defroster Posted April 18, 2013 Share Posted April 18, 2013 Hello I have a table over videos submitted by people: id / by_person / type / title / ----------------------------------------- 1 | 3 | 1 | title1 | 2 | 4 | 1 | title2 | 3 | 3 | 1 | title3 | 4 | 4 | 2 | title4 | 5 | 3 | 1 | title5 | 6 | 6 | 2 | title6 | 7 | 6 | 2 | title7 | 8 | 4 | 2 | title8 | 9 | 3 | 1 | title9 | 10 | 4 | 1 | title10 | 11 | 4 | 1 | title11 | 12| 3 | 1 | title12 | How do I SELECT the top 2 people who have submitted the most videos with type=1 ? So I get a presentation like this: 1. Person(3) - 5 videos 2. Person(4) - 3 videos Thanks Link to comment https://forums.phpfreaks.com/topic/277107-select-top-two-people-with-most-submitted-videos-where-type1/ Share on other sites More sharing options...
Barand Posted April 18, 2013 Share Posted April 18, 2013 SELECT by_person, COUNT(*) as total FROM videos ORDER BY total DESC LIMIT 2 Link to comment https://forums.phpfreaks.com/topic/277107-select-top-two-people-with-most-submitted-videos-where-type1/#findComment-1425587 Share on other sites More sharing options...
defroster Posted April 18, 2013 Author Share Posted April 18, 2013 Thanks Barand, but I would only like to select the count where type=1, how do I bake that in? Link to comment https://forums.phpfreaks.com/topic/277107-select-top-two-people-with-most-submitted-videos-where-type1/#findComment-1425588 Share on other sites More sharing options...
defroster Posted April 18, 2013 Author Share Posted April 18, 2013 Thanks, solved now SELECT by_person, count(*) AS total FROM videos WHERE type = 1 GROUP BY by_person ORDER BY total DESC LIMIT 2 DEMO: http://sqlfiddle.com/#!2/b2916/22 Link to comment https://forums.phpfreaks.com/topic/277107-select-top-two-people-with-most-submitted-videos-where-type1/#findComment-1425608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.