以下SQL代码返回两列:' product_id'和'反击' 我希望它只返回' product_id',是否可能?
select product_id, count(*) as counter
from accounts_products
group by product_id
order by counter DESC
limit 1
答案 0 :(得分:3)
只需删除counter
列,然后直接ORDER BY
计数:
SELECT product_id
FROM accounts_products
GROUP BY product_id
ORDER BY COUNT(*) DESC
LIMIT 1