SQL Oracle联接概率与表未联接

时间:2018-11-03 01:28:12

标签: sql oracle

我认为问题是我加入某处 我的OrderID不在一起

我不知道如何解决

T2.SetDiagonalValue val
T1.Range.AdvancedFilter xlFilterInPlace, T2.Range

Kinda喜欢被淘汰。 231未加入

select l.orderid, sum(l.qty) as units_sold, sum (l.qty) * p.price as Sales_Amount
from order_lines l join
     products p
     on p.prodid = l.prodid
group by l.orderid, p.price
Order by sum(l.qty) * p.price 

1 个答案:

答案 0 :(得分:1)

我怀疑您确实想要:

select l.orderid, sum(l.qty) as units_sold, sum(l.qty * p.price) as Sales_Amount
from order_lines l join
     products p
     on p.prodid = l.prodid
group by l.orderid
Order by Sales_Amount ;

group by子句指定您要如何定义结果集中的行。如果每个orderid只需要一行,那么orderid中应该只有group by