我有2个查询:一个是用ANSI SQL编写的,另一个是用oracle方言编写的。 我认为他们都必须给出相同的结果集,但事实并非如此。第一个查询提供385行,第二个查询提供25行
首先:
SELECT idclient, cl.surname, sum(sub1.s)
FROM client cl JOIN incomestatement incst USING(idclient)
JOIN (SELECT c.idincome ID, sum(inst.total) AS s
FROM instalment inst JOIN credit c USING(idcredit)
WHERE inst.paydate > c.paydate AND c.isloaned = 1
GROUP BY c.idincome) sub1 ON incst.idincome = sub1.ID
GROUP BY idclient, cl.surname;
第二
SELECT c.idclient, c.surname, sum(sub.s)
FROM client c, incomestatement inc,
(SELECT sum(inst.total) as s, cr.idincome as id
FROM instalment inst, credit cr
WHERE inst.paydate > cr.paydate AND cr.isloaned = 1 AND cr.idcredit = inst.idcredit
GROUP BY cr.idincome
) sub
WHERE c.idclient = inc.idclient AND inc.income = sub.ID
group by c.idclient, c.surname;
那么他们为什么不给出相同的结果?
答案 0 :(得分:1)
我会逐步解决问题。
答案 1 :(得分:0)
你做了提交吗? 您可能没有提交某些交易,因此结果可能会有所不同。