Skip to content

Instantly share code, notes, and snippets.

@samflores
Created January 17, 2012 21:03
Show Gist options
  • Select an option

  • Save samflores/1628850 to your computer and use it in GitHub Desktop.

Select an option

Save samflores/1628850 to your computer and use it in GitHub Desktop.
SELECT
v1.*
FROM `venues` AS v1
WHERE (
v1.id in (
SELECT v2.id
FROM `venues` AS v2
JOIN rates ON rates.rateable_id = v2.id
WHERE (rates.rateable_type = 'Venue')
GROUP BY v2.id
HAVING ROUND(AVG(rates.stars)) = 3
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment