首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

求1 sql 语句 在线的 非常着

2013-11-15 
求一 sql 语句 在线的 非常着急原始数据表:Dateidcount2013-05-23112013-05-23232013-05-2611002013-06-01

求一 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(+)

排序自己试试

热点排行