简体   繁体   中英

SQL Select Count Distinct groupby

Hello I am looking to select the top 10 names that have watched the most unique shows. My_table is as follows:

Name     Show
Hilda    The Road
Tom      Joker
Harry    Rainbow Bright
Hilda    Show 100

We can try using LIMIT here:

SELECT Name
FROM yourTable
GROUP BY Name
ORDER BY COUNT(DISTINCT Show) DESC
LIMIT 10;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM