我有一个返回结果列表的SQL查询。 sql是:
SELECT fcategory,sum(fquantity*fprice) AS qty FROM items GROUP BY fcategory
输出类似于
----------------
category|qty
----------------
a | 10
b | 100
c | 554
根据上面sql语句的结果,如何检索最大数量的行? (在这种情况下,我希望查询只返回" c")
答案 0 :(得分:0)
您可以按+限制1添加订单来获取此信息:
SELECT fcategory,sum(fquantity*fprice) AS qty FROM items GROUP BY fcategory
order by qty desc limit 1
答案 1 :(得分:0)
为了获取最高的数量,只需获得qty命令的第一个结果,如:
SELECT * FROM items ORDER BY qty desc limit 1
在您自己的情况下,
SELECT fcategory,sum(fquantity*fprice) AS qty FROM items GROUP BY fcategory ORDER BY qty LIMIT 1