现在有一个数据库,存储的是各个省2012年的销售单,销售单的创建日期每个月都有,
如何使用SQL语句将每个月的单据总量一次性统计出来:具体形式如下所示,不知道该如何操作。
1月 2月 3月 4月 5月 6月 。。。。。12月
北京市 50 40。。。。
上海市 30 48。。。。。
谢谢大家回复,感觉大家写的都好复杂,我直接将
SELECT month(date)
from table
groupby month(date)
然后就出结果了,大家看看有什么问题吗?
Select * from (Select row_number() over( partition by city-name 城市字段order by month 月份字段 asc ) as rum,* from table-name 表名 )as s where s.rum = month 需要的月份1-12
select
count(case when 日期>=1月1号 and 日期 count(case when 日期>=2月1号 and 日期 count(case when 日期>=3月1号 and 日期 count(case when 日期>=4月1号 and 日期 count(case when 日期>=5月1号 and 日期 count(case when 日期>=6月1号 and 日期 count(case when 日期>=7月1号 and 日期 count(case when 日期>=8月1号 and 日期 count(case when 日期>=9月1号 and 日期 count(case when 日期>=10月1号 and 日期 count(case when 日期>=11月1号 and 日期 count(case when 日期>=12月1号 and 日期<1月1号 then 1 else 0 end) count12
from 销售单表
group by 省份