[英]How i can get values order by the count of distinct values
I want to get those Product in ascending order who number is greater in mysql 我想按升序获取那些在mysql中编号更大的产品
order_id | product_id
1 | 13
1 | 12
1 | 24
2 | 14
2 | 245
2 | 23
3 | 14
3 | 23
4 | 14
i have done that code but its not working 我已经完成了该代码,但无法正常工作
SELECT product_id FROM `sales_order_item` ORDER BY COUNT('product_id') ASC
i want priduct_id in ascending order on the basis of there count\\ 我希望在其中count的基础上按升序排列priduct_id \\
product_id
14
23
13
24
245
as 14 occurs 4 times it must have to be on top and so on 因为14发生了4次,所以它必须在最上面,依此类推
use order by COUNT('product_id') desc
order by COUNT('product_id') desc
使用order by COUNT('product_id') desc
SELECT product_id,COUNT('product_id') as cnt FROM `sales_order_item`
group by product_id
ORDER BY cnt desc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.