日期:2014-05-16 浏览次数:20873 次
--try select a.顾客编号,sum(b.订单金额) 订单金额 from tb_aj001 a,tb_aj002 b where a.订单号=b.订单号 --and b.订单时间 between ... and ... --and b.订单状态=... having sum(b.订单金额)>500 and count(a.订单号)>1 group by a.顾客编号;
------解决方案--------------------
WITH t1 AS( SELECT 'D001' oderno,'C01' cuno FROM dual UNION ALL SELECT 'D002','C02' FROM dual UNION ALL SELECT 'D003','C01' FROM dual ),t2 AS( SELECT 'D001' oderno,90 odamt,'Finish' status,'20120601' txdat FROM dual UNION ALL SELECT 'D002',600,'Finish','20120602' FROM dual UNION ALL SELECT 'D003',450,'Finish','20120602' FROM dual ) SELECT t1.cuno,Sum(t2.odamt)odamt FROM t1,t2 WHERE t1.oderno=t2.oderno GROUP BY t1.cuno HAVING Count(t1.cuno)>1 AND Sum(t2.odamt)>500