SQL2005行列轉換的另一方法 PIVOT

2021-05-21 17:36:24 字數 1936 閱讀 9221

create table salesbymonth

(year char(4),

month char(3),

amount money,

primary key (year, month)

)insert into salesbymonth (year, month, amount)

values('2004','jan', 789.0000)

insert into salesbymonth (year, month, amount)

values('2004','feb', 389.0000)

insert into salesbymonth (year, month, amount)

values('2004','mar', 8867.0000)

insert into  salesbymonth (year, month, amount)

values('2004','apr', 778.0000)

insert into  salesbymonth (year, month, amount)

values('2004','may', 78.0000)

insert into  salesbymonth (year, month, amount)

values('2004','jun', 9.0000)

insert into  salesbymonth (year, month, amount)

values('2004','jul', 987.0000)

insert into  salesbymonth (year, month, amount)

values('2004','aug', 866.0000)

insert into  salesbymonth (year, month, amount)

values('2004','sep', 7787.0000)

insert into  salesbymonth (year, month, amount)

values('2004','oct', 85576.0000)

insert into  salesbymonth (year, month, amount)

values('2004','nov', 855.0000)

insert into  salesbymonth (year, month, amount)

values('2004','dec', 5878.0000)

insert into  salesbymonth (year, month, amount)

values('2005','jan', 7.0000)

insert into  salesbymonth (year, month, amount)

values('2005','feb', 6868.0000)

insert into  salesbymonth (year, month, amount)

values('2005','mar', 688.0000)

insert into  salesbymonth (year, month, amount)

values('2005','apr', 9897.0000)

select *

-- [jan],[feb],[mar],[apr],[may],[jun],[jul],[aug],[sep],[oct],[nov],[dec]

from ( select amount, month

from salesbymonth ) as salesbymonth

pivot ( sum(amount) for month in

([jan],[feb],[mar],[apr],[may],[jun],[jul],[aug],[sep],[oct],[nov],[dec])

) as ourpivot

sql2005 行列轉換的例子

select categoryproductid,0 as p0,1 as p1,2 as p2,3 as p3,4 as p4,5 as p5,6 as p6,7 as p7,8 as p8,9 as p9 from select categoryproductid,sequence,proper...

Linux檢視網絡卡UUID另一方法

有時我們不小心將 etc sysconfig network scripts ifcfg eth0 可以通過此檔案進行檢視uuid 刪除或者損壞,要重新編輯ifcfg eth0檔案時不知道網絡卡的uuid是什麼 當然也可以不寫 那我們還有什麼方法可以檢視網絡卡的uuid呢?在這裡我們使用的方法是使用...

js開發遇到在方法中呼叫另一方法問題

eas crm dayi webcontent ecp page template entitylist.js 基礎指令碼 eas crm dayi webcontent brandmarket page matchreply matchreply.js自己寫的指令碼 entitylist.js中有...