Skip to content

Instantly share code, notes, and snippets.

@beachandbytes
Created March 24, 2013 18:52
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 beachandbytes/5233031 to your computer and use it in GitHub Desktop.
Save beachandbytes/5233031 to your computer and use it in GitHub Desktop.
SELECT
P.club
,memberCount.members
,SUM(O.Price * P.qnty) [sales]
FROM purchase P
INNER JOIN offer O ON O.club = P.club AND P.title = O.title
INNER JOIN (
SELECT M.club,COUNT(*) [members]
FROM members M
GROUP BY M.club
) memberCount ON memberCount.club = P.club
GROUP BY
P.club
memberCount.members
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment