| 導購 | 订阅 | 在线投稿
分享
 
 
 

教你輕松掌握一個縱表轉橫表的"SQL"

來源:互聯網  2008-06-01 02:15:25  評論

縱表轉橫表的"SQL"示例:

縱表結構:

fname ftype fvalue

小喬 zaocan 10

小喬 zhongcan 20

小喬 wancan 5

轉換後的表結構:

fname zaocan_value zhongcan_value wancan_value

小喬 10 20 5

縱表轉橫表SQL示例:

select Fname, sum(case Ftype when 'zaocan'

then Fvalue else 0 end) as zaocan_value,

sum(case Ftype when 'zhongcan'

then Fvalue else 0 end) as zhongcan_value,

sum(case Ftype when 'wancan' then Fvalue else 0 end)

as wancan_value from case_table group by Fname

縱表轉橫表的"SQL"示例: 縱表結構: fname ftype fvalue 小喬 zaocan 10 小喬 zhongcan 20 小喬 wancan 5 轉換後的表結構: fname zaocan_value zhongcan_value wancan_value 小喬 10 20 5 縱表轉橫表SQL示例: select Fname, sum(case Ftype when 'zaocan' then Fvalue else 0 end) as zaocan_value, sum(case Ftype when 'zhongcan' then Fvalue else 0 end) as zhongcan_value, sum(case Ftype when 'wancan' then Fvalue else 0 end) as wancan_value from case_table group by Fname
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有