Skip to content

Instantly share code, notes, and snippets.

@vsizov
Created November 29, 2013 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsizov/7706718 to your computer and use it in GitHub Desktop.
Save vsizov/7706718 to your computer and use it in GitHub Desktop.
select f.*, count(*) cnt
from feedbacks f
LEFT JOIN feedbacks fn ON fn.id = (SELECT MAX(id) FROM feedbacks WHERE customer_id = f.customer_id)
WHERE (f.comment IS NOT NULL OR f.testimonial IS NOT NULL) AND f.company_id = 42
GROUP BY f.recommend;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment