unknown101 Posted May 22, 2008 Share Posted May 22, 2008 Hi Guys, im trying to workout how to write a query which involves the following table example: ArtistID || TrackID || Rating || UserID 2 1 3 1 2 2 3 1 2 3 2 1 This table will have many ratings, but how would I select all artistIDs which have been rated more than 3 times, by the same user and consistenly giving them a rating of 3 or below (as the table above demonstrates). So for example the only information i have is the user ID, i then need to find out that info - could anyone give me a hand please? Any help appreciated.. Cheers Link to comment https://forums.phpfreaks.com/topic/106775-help-with-query/ Share on other sites More sharing options...
rhodesa Posted May 22, 2008 Share Posted May 22, 2008 hum...not tested, but try this: SELECT ArtistID WHERE Rating <= 3 AND UserID = '1' AND count(Rating) > 3 GROUP BY ArtistID Link to comment https://forums.phpfreaks.com/topic/106775-help-with-query/#findComment-547342 Share on other sites More sharing options...
GingerRobot Posted May 22, 2008 Share Posted May 22, 2008 You'll need the HAVING clause: SELECT ArtistID,count(*) as count FROM yourtable WHERE Rating <= 3 AND UserID=1 GROUP BY ArtistID HAVING count >=3 Link to comment https://forums.phpfreaks.com/topic/106775-help-with-query/#findComment-547350 Share on other sites More sharing options...
unknown101 Posted May 22, 2008 Author Share Posted May 22, 2008 Thanks for the help guys, will test it shortly:) Link to comment https://forums.phpfreaks.com/topic/106775-help-with-query/#findComment-547359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.