查询一年的12个

来源:互联网 发布:微商或淘宝店计划 编辑:程序博客网 时间:2024/04/29 17:53

select m.month , isnull(n.P_Money,0) P_Money from
(
select 1 month union
select 2 month union
select 3 month union
select 4 month union
select 5 month union
select 6 month union
select 7 month union
select 8 month union
select 9 month union
select 10 month union
select 11 month union
select 12 month 
) m
left join
(select datepart(mm,P_InTime) P_InTime , sum(P_Money) P_Money from Pay_View where  datediff(yy,P_InTime,getdate()) = 0 group by datepart(mm,P_InTime)) n
on m.month = n.P_InTime

 

查询结果:

1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 30
11 30
12 40

原创粉丝点击