处理一些sql。我只有一个问题,如果需要更多细节,请告诉我。
执行sql查询时:
select o.prodid, p.prodname, sum(o.qtysold) as "TOTAL SALES"
from orderline o
inner join product p
on o.prodid = p.prodid
group by o.prodid, p.prodname
order by 3;
我得到以下数据:
PRODID PRODNAME TOTAL SALES
39 Coffee Table 1
33 Large Desk 1
34 Hallway Table 2
37 Zzz King Size Single Bed 2
38 Bedside Lamp 4
31 Lounge Chair 5
36 Lamp Stand (Tall) 7
35 Kitchen Stool 17
这些结果准确地反映了位于表 orderline 内的实际值。
但是,当我执行此查询时:
select o.prodid, p.prodname, sum(o.qtysold) as "TOTAL SALES"
from orderline o
inner join product p
on o.prodid = p.prodid
inner join allocation a
on a.prodid = p.prodid
inner join qualitycheck q
on q.prodid = a.prodid
having avg(q.score) >= 2
group by o.prodid, p.prodname
order by 3;
我得到以下数据:
PRODID PRODNAME TOTAL SALES
33 Large Desk 3
31 Lounge Chair 15
结果是准确的,正确的产品已被退回,但数据是错误的,因为我根本不明白的原因已售出的数量增加了三倍。任何有关为什么会发生这种情况的帮助和解释将不胜感激。
鲁布斯