mySQL query - show most popular item

前端 未结 3 694
渐次进展
渐次进展 2021-02-11 04:53

I need to find the most popular occurrence of an item grouped by date and display the total of all items along with the name of this item. Is something like this possible in a s

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-11 05:27

    thanks to hohodave for his initial response:

    SELECT date, item, cnt, (
    SELECT COUNT( * )
    FROM test_popularity
    WHERE date = t.date
    ) AS totalCnt
    FROM (
    SELECT date, item, count( item_id ) AS cnt
    FROM test_popularity
    GROUP BY date, item_id
    ORDER BY cnt DESC
    )t
    GROUP BY date;
    

提交回复
热议问题