`
joeyhacker
  • 浏览: 96193 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

P.01

SUN 
阅读更多

有如下数据:
日期          姓名 金额
2008-1-12 sun  100
2008-1-12 张    100
2008-1-13 sun  100
2008-1-19 张    300
2008-2-12 sun  120
2008-2-19 张    300
2008-3-12 sun  130


得到的查询结果:
姓名    2008-01    2008-02   2008-03
sun      200           120         130
张        400           300         

 0

 

我的答案(非最佳答案.)

select t1.username "姓名","2009-09","2009-10","2009-11"
from (select username,sum(money) as "2009-09" from SCOTT.MY where datetime between to_date('2009-09-01','yyyy-mm-dd') and to_date('2009-09-30','yyyy-mm-dd') group by username) t1,
(select username,sum(money) as "2009-10" from SCOTT.MY where datetime between to_date('2009-10-01','yyyy-mm-dd') and to_date('2009-10-30','yyyy-mm-dd') group by username) t2,
(select username,sum(money) as "2009-11" from SCOTT.MY where datetime between to_date('2009-11-01','yyyy-mm-dd') and to_date('2009-11-30','yyyy-mm-dd') group by username) t3
where t1.username = t2.username and t2.username = t3.username;

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics