比如我有A表
id date num
1 2010-06-01 1
2 2010-06-01 2
3 2010-07-01 3
4 2010-07-21 4
5 2010-08-01 5
6 2011-09-01 6
用sql 分别查出日 月 季 年数据返回
如按日select date ,sum(num) from a group by date....
id date num
1 2010-06-01 1
2 2010-06-01 2
3 2010-07-01 3
4 2010-07-21 4
5 2010-08-01 5
6 2011-09-01 6
用sql 分别查出日 月 季 年数据返回
如按日select date ,sum(num) from a group by date....
from a group by cast(year(aopp_createddate) as varchar(4))+'-'+ cast(month(aopp_createddate) as varchar(2))
--按日
select convert(varchar(10),date,120) 日期 ,sum(num) from a group by convert(varchar(10),date,120)
--月
select convert(varchar(7),date,120) 月份 ,sum(num) from a group by convert(varchar(7),date,120)
--季度
select year(date) 年, datepart(Q,date) 季度 ,sum(num) from a group by year(date), datepart(Q,date)
--年
select year(date) 年, sum(num) from a group by year(date)
order by year(date)
select datepart(wk,[date]) wk,sum(num) as num
from tb
group by datepart(wk,[date])
select datepart(wk,date),date from a group by datepart(wk,date)
select datepart(wk,date),sum(num) from a group by datepart(wk,date)
--月
select convert(varchar(7),date,120) 月份 ,sum(num) from a group by convert(varchar(7),date,120)比如我选择月是5月,哪这里条件应如何设置呢,这样吗???
select convert(varchar(7),date,120) 月份 ,sum(num) from a
where convert(varchar(7),date,120)='2010-05'
group by convert(varchar(7),date,120)