表A字段 userNum place creattime
userNum place creattime
4 beijing 2010-04-01
8 shanghai 2010-04-01
4 beijing 2010-04-02
2 shanghai 2010-04-02
4 beijing 2010-04-03
1 shanghai 2010-04-03
我所需要的结果集如下:sum(userNum) creattime
12 2010-04-01
6 2010-04-02
5 2010-04-03
userNum place creattime
4 beijing 2010-04-01
8 shanghai 2010-04-01
4 beijing 2010-04-02
2 shanghai 2010-04-02
4 beijing 2010-04-03
1 shanghai 2010-04-03
我所需要的结果集如下:sum(userNum) creattime
12 2010-04-01
6 2010-04-02
5 2010-04-03
from A
group by creattime
order by creattime
from A
group by createtime
from A
group by creattime
order by creattime
with tt as(
select 4 userNum , 'beijing' place,'2010-04-01' creattime from dual union all
select 8 userNum , 'shanghai' place,'2010-04-01' creattime from dual union all
select 4 userNum , 'beijing' place,'2010-04-02' creattime from dual union all
select 2 userNum , 'shanghai' place,'2010-04-02' creattime from dual union all
select 4 userNum , 'beijing' place,'2010-04-03' creattime from dual union all
select 1 userNum , 'shanghai' place,'2010-04-03' creattime from dual)
select sum(userNum),creattime
from tt
group by creattime
order by creattime
select sum(userNum),creattime
from A
group by creattime
order by creattime
解释:让时间相同的为一个集合然后求其对应编号的和。
建议: 了解一下group by的用法。这是基本sql
select sum(usernum) as usernum,createtime
from A
group by createtime
order by sum(usernum) desc
--直来直去的类型
from A
group by creattime
order by creattime