# sql汇总问题

0

xiaoafei1991 | 菜鸟二级 | 园豆：466

0

xiaoafei1991 | 园豆：466 (菜鸟二级) | 2014-06-21 19:09

@xiaoafei1991:

```select salesperson as 销售人员,
sum(case when month(subtime)=1 then sales else 0 end) as [1月总销售额],
sum(case when month(subtime)=2 then sales else 0 end) as [2月总销售额],
sum(case when month(subtime)=3 then sales else 0 end) as [3月总销售额],
sum(case when month(subtime)=4 then sales else 0 end) as [4月总销售额],
sum(case when month(subtime)=5 then sales else 0 end) as [5月总销售额],
sum(case when month(subtime)=6 then sales else 0 end) as [6月总销售额],
sum(case when month(subtime)=7 then sales else 0 end) as [7月总销售额],
sum(case when month(subtime)=8 then sales else 0 end) as [8月总销售额],
sum(case when month(subtime)=9 then sales else 0 end) as [9月总销售额],
sum(case when month(subtime)=10 then sales else 0 end) as [10月总销售额],
sum(case when month(subtime)=11 then sales else 0 end) as [11月总销售额],
sum(case when month(subtime)=12 then sales else 0 end) as [12月总销售额],
sum(sales) as [全年总销售额]
from [table]
where year(subtime)=2014
group by salesperson```

@飞来飞去: 谢谢！

xiaoafei1991 | 园豆：466 (菜鸟二级) | 2014-06-21 20:19

0

`select salesperson, sum(sales) as salesInMay from sell where strftime('%m', subtime) = '05' group by salesperson;`

----------------------------------------------------------

grassofsky | 园豆：342 (菜鸟二级) | 2014-06-21 20:39

您需要登录以后才能回答，未注册用户请先注册