+-----------------------+------------------------+
| being_followed | follower |
+-----------------------+------------------------+
| Bob Dylan | B |
| Bob Dylan | A |
| Sam Cooke | X |
| The Beatles | Y |
| Bob Dylan | M |
| Sam Cooke | N |
+-----------------------+------------------------+
Now, I want to find which is the most occurring value in being_followed
and then order by it. It should look somewhat like -
Bob Dylan - 3
Sam Cooke - 2
The Beatles - 1
Please don't mark this as a duplicate.
Try below :
select being_followed , count(1) as count
from table
group by being_followed
order by count desc ;
Try This:-
select being_followed,count(*) total_followers
from table
group by being_followed
order by total_followers desc
SELECT being_followed , count(being_followed )as counter FROM `table_Name` GROUP BY being_followed ORDER BY counter DESC
您将得到想要的结果。在此处使用group by将获得唯一值,在使用count时将获得相同的being_followed计数器
Try this:
SELECT being_followed,COUNT(*) AS follower
FROM tablename GROUP BY being_followed ORDER BY follower DESC;
Output:
+-----------------------+------------------------+
| being_followed | follower |
+-----------------------+------------------------+
| Bob Dylan | 3 |
| Sam Cooke | 2 |
| The Beatles | 1 |
+-----------------------+------------------------+
Try this
SELECT being_followed,COUNT(1) count_followers
FROM table
GROUP BY being_followed
ORDER BY COUNT(1) DESC;
Get count of being_followed and also order by high to low bases(descending order)
Perhaps you can try this:
select being_followed, count(*) follower
from TableName
group by being_followed
order by follower desc
It's working fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.