时间:2021-07-01 10:21:17 帮助过:4人阅读
查询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 列转行
标签: