如何修改下面的union select语句到任何连接select语句方法,它来自表1和表2的总和价格,我也尝试了,
select CODE, SUM(PRICE) as PRICE
from (SELECT CODE, SUM(PRICE) as PRICE
FROM TABLE1
where ID='IBK' and cast(TMSTAMP_UPDATE as DATE)='2014-03-31'
GROUP BY CODE
union
SELECT CODE, SUM(PRICE) as PRICE
FROM TABLE2
where ID='IBK' and cast(TMSTAMP_UPDATE as DATE)='2014-03-31'
GROUP BY CODE) GROUP BY CODE;
提前致谢
答案 0 :(得分:0)
尝试这样
select CODE, SUM(PRICE) as PRICE
from (SELECT CODE, SUM(PRICE) as PRICE
FROM TABLE1 t1 INNER JOIN TABLE2 t2 ON
t1.ID=t2.ID and
t1. cast(TMSTAMP_UPDATE as DATE)='2014-03-31'
= t2.cast(TMSTAMP_UPDATE as DATE)='2014-03-31' and
t1.ID='IBK' and t1.cast(TMSTAMP_UPDATE as DATE)='2014-03-31'
GROUP BY CODE) GROUP BY CODE;