我有一个名为order_list的表,其中包含以下字段
每次用户下订单时,此表用于保存订单详细信息。那么如何根据有序计数的总和编写我的SQL查询来查找前10项呢?
答案 0 :(得分:3)
SELECT item_id, SUM(count) FROM order_list GROUP BY item_id ORDER BY SUM(count) DESC LIMIT 0,10
答案 1 :(得分:0)
SELECT *
FROM table_name
GROUP BY item_id
ORDER BY count DESC
LIMIT 10
答案 2 :(得分:0)
select item_id, sum(count) as total
from order_list
group by item_id
order by total desc
limit 10