展开全部
select cname,
sum(case when year(senddate)=2005 then totalpay else 0 end) as 2005,
sum(case when year(senddate)=2006 then totalpay else 0 end) as 2006
from pay group by cname
如果你senddate不是datetime类型的话year(senddate)=2005就要改成
left(senddate,4)='2005'
sum(case when year(senddate)=2005 then totalpay else 0 end) as 2005,
sum(case when year(senddate)=2006 then totalpay else 0 end) as 2006
from pay group by cname
如果你senddate不是datetime类型的话year(senddate)=2005就要改成
left(senddate,4)='2005'
展开全部
基于oracle:
select p.Cname,(select sum(nvl(TotalPay,0)) from pay where Cname=p.Cname and to_char(SendDate,'yyyy')='2005') as "2005",
(select sum(nvl(TotalPay,0)) from pay where Cname=p.Cname and to_char(SendDate,'yyyy')='2006') as "2006"
from Pay p
group by p.Cname
select p.Cname,(select sum(nvl(TotalPay,0)) from pay where Cname=p.Cname and to_char(SendDate,'yyyy')='2005') as "2005",
(select sum(nvl(TotalPay,0)) from pay where Cname=p.Cname and to_char(SendDate,'yyyy')='2006') as "2006"
from Pay p
group by p.Cname
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
去百度行转列,你这个是典型的行转列
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没有图啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询