SELECT id HAVING maximum count of id

后端 未结 4 589
暖寄归人
暖寄归人 2020-12-15 22:39

Have a products table with item_id and color_id. I\'m trying to get the color_id with the most non-null instances.

This fails:

SELECT color_id 
           


        
4条回答
  •  [愿得一人]
    2020-12-15 23:22

    SELECT 
      color_id, 
      COUNT(color_id) AS occurances
    FROM so_test
    GROUP BY color_id
    ORDER BY occurances DESC
    LIMIT 0, 1
    

    Here is a sample fiddle with a basic table that shows it working: sql fiddle

提交回复
热议问题