我正在尝试查找SalesReps最低成本订单,它们的平均成本和最高成本。我期待输出就像。
[SalesRep] [Max] [AVG] [Min]
#12121 12 6 2
我目前的守则是
SELECT DISTINCT REP, MAX(Amount), AVG(Amount), MIN(Amount)
FROM Orders
WHERE OrderDate BETWEEN '1990-01-01' AND '1999-12-30';
我理解Select语句错了我只是不知道从哪里开始。任何帮助将不胜感激。
答案 0 :(得分:0)
添加缺少的group by
:
select REP,
MAX(Amount),
AVG(Amount),
MIN(Amount)
from Orders
where OrderDate between '1990-01-01' and '1999-12-30'
group by REP --<-- here