日期:2014-05-17  浏览次数:20843 次

请教一个PL/SQL语句
表名datacount
字段
deliver_count       submit_count           icp_id
10                                 10                             1000
5                                     6                             1000
6                                     7                             1000
21                                 10                             1001
12                                 10                             1001
icp_id企业ID,
sql= "select   icp_id,   sum(deliver_count)   d,sum(submit_count)   s   from   datacount   t1   group   by   icp_id ";
在以上语句的基础上,现在我想求一条语句,就是求d与s之和大于60的icp_id,并也可以查询出这个icp_id的d和s,用一条语句


------解决方案--------------------
select * from
(select icp_id, sum(nvl(deliver_count,0)) d,sum(nvl(submit_count,0)) s
from datacount t1 group by icp_id
)
where d+s> 60
------解决方案--------------------
select icp_id, sum(deliver_count) d,sum(submit_count) s from datacount t1
having sum(deliver_count) + sum(submit_count) > =61
group by icp_id