读书人

求1 sql 语句 在线的 非常着

发布时间: 2013-11-15 22:28:15 作者: rapoo

求一 sql 语句 在线的 非常着急
原始数据表:

Date id count
2013-05-23 1 1
2013-05-23 2 3
2013-05-26 1 100
2013-06-01 2 200
2013-06-06 1 20
2013-06-06 2 30

期望结果:
2013-05-23 1 1
2013-06-01 1 0
2013-05-26 1 100
2013-06-06 1 20
2013-05-23 2 3
2013-05-26 2 0
2013-06-01 2 200
2013-06-06 2 30

如果当天有一个id的有数据,其他的id要补齐数据,count为0. 然后结果按id分组排序,每组id中按日期排序
[解决办法]
你试试下面语句


select data,id,nvl(count,0) from table group by data,id,count order by id

[解决办法]
select t3.date,t3.id nvl(t4.count,0) from (select t1.date,t2.id(select distinct date from table)t1, (select distinct id from table) t2)t3,table t4 where t3.id=t4.id(+) and t3.date=t4.date(+)

排序自己试试

读书人网 >oracle

热点推荐