Guest User

Untitled

a guest
May 25th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. SELECT *
  2. FROM
  3. channels
  4. JOIN gigs ON channels.id = gigs.channel_id
  5. JOIN songs ON gigs.song_id = songs.id
  6. JOIN (
  7. SELECT t1.channel_id, t1.song_id, COUNT(t2.song_id) AS theCount
  8. FROM gigs t1
  9. LEFT JOIN gigs t2 ON t1.channel_id = t2.channel_id AND t1.song_id > t2.song_id
  10. GROUP BY t1.channel_id, t1.song_id
  11. HAVING theCount >= 10
  12. ) AS dt USING (channel_id, song_id) GROUP BY gigs.channel_id
Add Comment
Please, Sign In to add comment