简体   繁体   English

我如何通过计数不同值来获得值顺序

[英]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.

相关问题 如何使用 select 计数(不同的 x)来计算同一个表中的两个值并在我的 output 中获取两个不同的值? - How can I use select count (distinct x) in order to count two values in the same table and get the the two distinct values in my output? SQL:如何获得列中不同值的总数? - SQL: How would I get a total count for distinct values in a column? 如何获得2列的不同计数值? - How do I get distinct count values of 2 columns? 如何在一组日期值中计算不同的月份名称? - How can I count distinct months names in a set of date values? 在2个表中获取COUNT()和COUNT(DISTINCT())值 - Get COUNT() AND COUNT(DISTINCT()) values across 2 tables 如何返回不同的值及其数量? - How to return distinct values and their count? 如何从表中获取不同的值以及包含该值的行数 - How do I get distinct values from the table along with the count of how many rows there are containing that value 我如何实现MySQL的DISTINCT关键字以使用线程并行获取不同的值 - How can I implement DISTINCT keyword of mysql to get distinct values parallely using threads 请求如何获取其中一个等于的不同值的计数 - How to get a count of distinct values where one of them equals is requested MySQL获得不同的值并计算每个的数量? - MySQL get distinct values and count how many of each?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM