[英]Sort database table by highest number of occurences of an id mysql/php
I have a table 'favoriteSellers' with columns 我有一个表'favoriteSellers'和列
uniqueId userId sellerId
1 33 31
2 33 32
3 31 32
4 32 33
5 32 32
6 31 33
I need to be able to call the most favorited sellerIds in order. 我需要能够按顺序拨打最受欢迎的SellerIds。 So in the above it would return Id 32, then 33, then 31
所以在上面它将返回Id 32,然后是33,然后是31
I have no idea the correct sql statement to do this! 我不知道正确的sql语句来做到这一点!
SELECT sellerId, COUNT(*) AS bestSeller FROM favoriteSellers ORDER BY bestSeller DESC
Try this. 尝试这个。 just off the top off my head I think this may do what you wish
我觉得这可能会做你想做的事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.