SQL拼接
SQL1:
select SUM(CASE WHEN UNDESIRABLE != ' ' THEN 1 END) from Tm_Marketfeedback
WHERE datetochar(BACKDATE,'M') BETWEEN '2009-05' AND '2012-06')
SQL2:
select SUM(LOT_SIZE) AS B from tl_out_lot
where datetochar(OUTGOINGDATE,'M') ='2012-06'
将两条SQL的值相除 整合一条SQL,谢谢~~
------解决方案--------------------
select (select SUM(CASE
WHEN UNDESIRABLE != ' ' THEN
1
END)
from Tm_Marketfeedback
WHERE datetochar(BACKDATE, 'M') BETWEEN '2009-05' AND '2012-06')) /
(select SUM(LOT_SIZE) AS B
from tl_out_lot
where datetochar(OUTGOINGDATE, 'M') = '2012-06')
from dual;
------解决方案--------------------基本同意楼上,
但SUM(LOT_SIZE)做为除数的话,建议添加一个NULL或零值判断。
如:decode(NVL(SUM(LOT_SIZE),0),0,1,1)--如果是NULL值,强制转换为0,然后再把零值强制转换为1,其余的,不做变化。