答案 0 :(得分:1)
您可以使用子查询来检查给定记录的数量是否与表中观察到的最大数量相匹配:
SELECT *
FROM yourTable
WHERE qty = (SELECT MAX(qty) FROM yourTable)
如果有多个客户分享最大数量,则会返回多条记录。
如果您只想获得一条记录,即使存在关联,也可以使用此方法:
SELECT *
FROM yourTable
ORDER BY qty DESC
LIMIT 1
答案 1 :(得分:0)
我认为你需要每个数量的数量。
如果是这样,你可以尝试:
select custNum,
sum(qty) as qty
from Orders
group by custNum
order by sum(qty) desc;
小提琴:
答案 2 :(得分:0)
SELECT custnum,sum(qty) as total
FROM orders
group by custnum
having sum(qty) = (SELECT MAX(qty) FROM orders);
这将返回两个值。