回复次数:7
|
|
#1 得分:10
回复于: 2010-07-28 12:18:41
|
select
count
(id) 回帖总数,
count
(
distinct
userid) 回帖用户数
from
temp
where
to_char(retime,
'yyyy-mm'
)=
'2010-05'
sql月份汇总查询语句
select '铅笔' as [月份],
sum(case month(日期) when 1 then 铅笔 else 0 end) as [1月],
sum(case month(日期) when 2 then 铅笔 else 0 end) as [2月],
sum(case month(日期) when 3 then 铅笔 else 0 end) as [3月],
sum(case month(日期) when 4 then 铅笔 else 0 end) as [4月],
sum(case month(日期) when 5 then 铅笔 else 0 end) as [5月],
sum(铅笔) as 总价
from table
union all
select '钢笔' as [月份],
sum(case month(日期) when 1 then 钢笔 else 0 end) as [1月],
sum(case month(日期) when 2 then 钢笔 else 0 end) as [2月],
sum(case month(日期) when 3 then 钢笔 else 0 end) as [3月],
sum(case month(日期) when 4 then 钢笔 else 0 end) as [4月],
sum(case month(日期) when 5 then 钢笔 else 0 end) as [5月],
sum(钢笔) as 总价
from table
结果
铅笔 1月 2月 3月 4月 5月 总价
铅笔 200 500 600 700 500 2500
钢笔 200 300 250 400 300 1450
毛笔 300 400 500 300 600 2100
总价 700 1200 1350 1400 1400 6050