输入banner图图片脚本导航/分类

sql 列转行

(SELECT yuefen, 8 as yue, "8" as b FROM chexin union all SELECT yuefen, 9 as yue, "9" as b FROM chexin union all SELECT yuefen, 10 as yue, "10" as b FROM chexin union all SELECT yuefen, 11 as yue, "11" as b FROM chexin union all SELECT yuefen, 12 as yue, "12" as b FROM chexin ) chexin where yuefen>=201608

技术分享

查询8月、之后所有月的合计数据(包括8月)

select a d,sda c,yuefen,name,gender ,
(
SELECT SUM(b) from
(SELECT yuefen, 201608 as yue, "8" as b FROM chexin
union all
SELECT yuefen, 201609 as yue, "9" as b FROM chexin
union all
SELECT yuefen, 201610 as yue, "10" as b FROM chexin
union all
SELECT yuefen, 201611 as yue, "11" as b FROM chexin
union all
SELECT yuefen, 201612 as yue, "12" as b FROM chexin 
) chexin 
    where yue>=201608 and yuefen>=201608) 合计
    from chexin  where yuefen >=201608

技术分享

8月之后每个月的合计

SELECT yue,SUM(b) 合计 from
(SELECT yuefen, 201608 as yue, "8" as b FROM chexin
union all
SELECT yuefen, 201609 as yue, "9" as b FROM chexin
union all
SELECT yuefen, 201610 as yue, "10" as b FROM chexin
union all
SELECT yuefen, 201611 as yue, "11" as b FROM chexin
union all
SELECT yuefen, 201612 as yue, "12" as b FROM chexin 
) chexin where yue>=201608 group by yue 

技术分享

sql 列转行

标签: