有表 a(item,qty,startdate,enddate),如何查询得如下结果
----------------------------------------------------------------
item totala totalb totalc
----------------------------------------------------------
sysdate为当前日期
其中totala为 startdate <sysdate and enddate <sysdate qty的和
其中totalb为 startdate <sysdate and enddate>sysdate qty的和
其中totalc为 startdate>sysdate and enddate>sysdate qty的和
item 为三个(不同条件)的并集,如果相应的不存在可以在 相应的TOTAL 列填充0
----------------------------------------------------------------
item totala totalb totalc
----------------------------------------------------------
sysdate为当前日期
其中totala为 startdate <sysdate and enddate <sysdate qty的和
其中totalb为 startdate <sysdate and enddate>sysdate qty的和
其中totalc为 startdate>sysdate and enddate>sysdate qty的和
item 为三个(不同条件)的并集,如果相应的不存在可以在 相应的TOTAL 列填充0
解决方案 »
- 分组筛选SQL语句求教
- 一台电脑访问局域网中的另一台电脑的oracle怎么配置啊,两台都装了oracle
- oracle批量生成数据
- 100分求助:如何把服务器server1的oracle数据库db1,迁移到服务器server02的oracle上,并保持数据库同名,即db1。
- 菜鸟求助,月计划拆分到每一天
- 如果 name是oracle的关键字 但是我的表里有name这个字段 我怎么查询 name啊
- Powerdesigner是否能连接远程的服务器上的mysql?
- 如何将excel的数据导入oracle
- orcle初始化参数的位置是在哪儿指定的?
- linux下 安装时,安装页面出现乱码,无法正确显示字符。
- 还是select 语句的问题 ORA-00942: 表或视图不存在
- 删除ORACLE里的表
select totala + totalb + totalc item, totala, totalb, totalc
from (select sum(case when(startdate < sysdate) and (enddate < sysdate) then qty else 0) totala,
sum(case when(startdate < sysdate) and (enddate < sysdate) then qty else 0) totalb,
sum(case when(startdate < sysdate) and (enddate < sysdate) then qty else 0) totalc
from a)
select totala + totalb + totalc item, totala, totalb, totalc
from (select sum(case when(startdate < sysdate) and (enddate < sysdate) then qty else 0) totala,
sum(case when(startdate < sysdate) and (enddate > sysdate) then qty else 0) totalb,
sum(case when(startdate > sysdate) and (enddate > sysdate) then qty else 0) totalc
from a)
sum(case when(startdate < sysdate) and (enddate < sysdate) then qty else 0) totala,
sum(case when(startdate < sysdate) and (enddate > sysdate) then qty else 0) totalb,
sum(case when(startdate > sysdate) and (enddate > sysdate) then qty else 0) totalc
from a
group by item可以了,很感谢大家
select item,
sum(case when(startdate < sysdate) and (enddate < sysdate) then nvl(qty,0) else 0) totala,
sum(case when(startdate < sysdate) and (enddate > sysdate) then nvl(qty,0) else 0) totalb,
sum(case when(startdate > sysdate) and (enddate > sysdate) then nvl(qty,0) else 0) totalc
from a
group by item