sql列转行
1.需要实现一个单行的统计报表
思路先用一个union查出单列,然后再把单列转成单行
2.实现
SELECT
MAX(CASE WHEN type = 1 THEN num ELSE 0 END) AS 'GeneralCnt',
MAX(CASE WHEN type = 2 THEN num ELSE 0 END) AS 'HistoryCnt'
from (
select '1' as 'type',count(*) as 'num'
from General
union all
select '2' ,count(*)
from History
) tmp
posted on 2014-05-07 09:03 kenny jiang 阅读(223) 评论(0) 编辑 收藏 举报