我有一个 mysql 表,其中包含客户 ID 和客户针对各种类别发布的信息。我想按降序找出每个类别的客户发布数量。
Customer id Category no
1 1
2 1
3 1
1 1
1 2
1 1
2 1
基本上在上表中,客户 ID 1 的职位最高,然后是 1,然后是 2,然后是 3。 那么我应该使用什么 mysql 查询来获得解决方案。
非常感谢任何帮助。提前致谢。
最佳答案
这将为您提供类别表中的帖子条目数,这些条目按类别和客户分组,并按降序排列:
select customer_id, category_no, count(1) as total_post
from category
group by customer_id, category_no
order by count(1) desc;
关于php - Customer_id 的订单计数(按类别 no),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20670291/