日期:2014-05-17 浏览次数:20952 次
--1 select productName1,color1, sum(decode(color1,'红',1,0))-sum(decode(color1,'蓝',1,0)) num_ from product1 group by productName1,color1 having sum(decode(color1,'红',1,0)) > sum(decode(color1,'蓝',1,0)); --2 select productName1, sum(decode(color1,'红',1,0)) 红色rednum , sum(decode(color1,'蓝',1,0)) 蓝色bluenum from product1 group by productName1;
------解决方案--------------------
select productName1,color1, sum(decode(color1,'红',nvl(num1,0),0))-sum(decode(color1,'蓝',nvl(num1,0),0)) num_ from product1 group by productName1,color1 having sum(decode(color1,'红',nvl(num1,0),0)) > sum(decode(color1,'蓝',nvl(num1,0),0))