比如oralce查出一張表
要轉換成如圖需求的表 如何做
差不多下面這樣
select (月份 || '月') 月份
,sum(decode(日期, 1, 行走公裡數,0)) as 1日
,sum(decode(日期, 2, 行走公裡數,0)) as 2日
,sum(decode(日期, 3, 行走公裡數,0)) as 3日
,sum(decode(日期, 4, 行走公裡數,0)) as 4日
,sum(decode(日期, 5, 行走公裡數,0)) as 5日
,sum(decode(日期, 6, 行走公裡數,0)) as 6日
,sum(decode(日期, 7, 行走公裡數,0)) as 7日
,sum(decode(日期, 8, 行走公裡數,0)) as 8日
,sum(decode(日期, 9, 行走公裡數,0)) as 9日
,sum(decode(日期, 10, 行走公裡數,0)) as 10日
,sum(decode(日期, 11, 行走公裡數,0)) as 11日
,sum(decode(日期, 12, 行走公裡數,0)) as 12日
,sum(decode(日期, 13, 行走公裡數,0)) as 13日
,sum(decode(日期, 14, 行走公裡數,0)) as 14日
,sum(decode(日期, 15, 行走公裡數,0)) as 15日
,sum(decode(日期, 16, 行走公裡數,0)) as 16日
,sum(decode(日期, 17, 行走公裡數,0)) as 17日
,sum(decode(日期, 18, 行走公裡數,0)) as 18日
,sum(decode(日期, 19, 行走公裡數,0)) as 19日
,sum(decode(日期, 20, 行走公裡數,0)) as 20日
,sum(decode(日期, 21, 行走公裡數,0)) as 21日
,sum(decode(日期, 22, 行走公裡數,0)) as 22日
,sum(decode(日期, 23, 行走公裡數,0)) as 23日
,sum(decode(日期, 24, 行走公裡數,0)) as 24日
,sum(decode(日期, 25, 行走公裡數,0)) as 25日
,sum(decode(日期, 26, 行走公裡數,0)) as 26日
,sum(decode(日期, 27, 行走公裡數,0)) as 27日
,sum(decode(日期, 28, 行走公裡數,0)) as 28日
,sum(decode(日期, 29, 行走公裡數,0)) as 29日
,sum(decode(日期, 30, 行走公裡數,0)) as 30日
,sum(decode(日期, 31, 行走公裡數,0)) as 31日
from 表 group by 月份
參考http://blog.csdn.net/danielinbiti/article/details/44977749