Most reports may encounter "Data pivoting", that is, "column and column conversion ". All of these operations use the "functions" and "unregister" functions.
According to the description of "msdn", refer to the address (http://technet.microsoft.com/zh-cn/library/ms177410.aspx), but not very good understanding, the following according to your understanding of the introduction. If anything is inappropriate, ask the masters to correct them.
Msdn instance:
Select * from
(Select daystomanufacture, standardcost from production. Product) as tablesource
Bytes
(Sum (standardcost) for daystomanufacture in ([0], [1], [2], [3], [4])
As newtable
1. "Source Data Query": Select daystomanufacture, standardcost from production. Product
A simple understanding is the dataset to be operated by "operator ".
2. "outputs" function: (sum (standardcost) for daystomanufacture in ([0], [1], [2], [3], [4])
View "daystomanufacture" based on "standardcost" (source data column). The column after pivot is "[0], [1], [2], [3], [4] ".
3. query the new result set after perspective: Select * from... newtable
Note: "pivot data" is automatically grouped based on "non-pivot columns", such as the following table.
View the "dahour" column based on the "sumqty", then you will find that there are repeated "13, 14, 15, 16" in "dahour, however, their "buildingno" is different. In this case, they are automatically grouped by "buildingno" to change to different records (otherwise there is only one record ). The value of "dahour" is changed to the column title, and the value of "sumqty" is changed to the value corresponding to the "dahour" column.
The SQL statement is as follows:
Select * from (select buildingno, dahour, sumqty from energydatasum ed where buildingno in ('3366fa001', '3366fe001') as PT
Sums (sumqty) for dahour in ([00], [01], [02], [03], [04], [05], [06], [07], [08], [09], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23]) as RT
"Unregister" Function
As the name suggests, this is the inverse operation of the "distinct" function.
The instances in msdn are as follows:
1 create table pvt (vendorid int, emp1 int, emp2 int,
2 emp3 int, emp4 int, emp5 INT );
3 go
4 insert into PVT values );
5 insert into PVT values );
6 insert into PVT values (3, 4, 3, 5, 4 );
7 insert into PVT values );
8 insert into PVT values );
9
10 go
11 select * From PVT
12 go
13
14
15 select vendorid, employees, orderbs
16 from
17 (select vendorid, emp1, emp2, emp3, emp4, emp5
18 from PVT) P
19 uninitiated
20 (orderbs for employees in
21 (emp1, emp2, emp3, emp4, emp5)
22) as unpvt;
The only difference is the function name (nonsense), "Untitled" (data source column for title column in (title ))
Please correct me if anything is wrong.
For more information, see "sqlserver2008" evaluation version upgrade.
1. If "sqlserver2008" evaluation version is installed, enter the serial number during installation.
Development: PTTFM-X467G-P7RH2-3Q6CG-4DMYB
Enterprise: JD8Y6-HQG69-P9H84-XDTPG-34MBB
2. The "sqlserver2008" evaluation version has been installed and has passed the evaluation period. perform the following operations.
2.1 modify the registry:
Change the value of "commonfiles" in HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft SQL Server \ 100 \ configurationstate to 3.
2.2 click Start-all programs-Microsoft SQL Server 2008-configuration tools-{SQL Server Installation Center}
2.3 click maintenance on the left, click version upgrade on the right, and follow the prompts to continue the next step. Enter the product key
Development: PTTFM-X467G-P7RH2-3Q6CG-4DMYB
Enterprise: JD8Y6-HQG69-P9H84-XDTPG-34MBB
Bind