Created
November 16, 2011 16:41
-
-
Save chartjes/1370594 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
More fun with aggregates. I have the following query: | |
SELECT brand.id, COUNT(DISTINCT(track_play.track_id)) as track_count | |
FROM track_play | |
INNER JOIN brand ON brand.id = track_play.brand_id | |
GROUP BY brand.id | |
which returns info like this: | |
"id","track_count" | |
1,1 | |
2,13 | |
3,631 | |
4,15 | |
9,3 | |
11,12 | |
13,12 | |
14,4 | |
20,9 | |
22,13 | |
24,12 | |
26,9 | |
29,2 | |
34,5 | |
35,4 | |
39,7 | |
40,13 | |
43,1 | |
44,3 | |
48,11 | |
54,14 | |
I need to figure out the average track_count per brand_id. Not sure if it requires a nested sub query, and I've tried using AVG(...) but I keep getting "Invalid use of group function" | |
Can you tell I'm too used to ORM's spitting data out for me? :P |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment