Created
September 21, 2016 10:20
-
-
Save xeviknal/ce9eb229b19cecf14ddc21f1147663e0 to your computer and use it in GitHub Desktop.
SQL: derivated table
This file contains 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
SELECT | |
AVG(count) | |
FROM # here the derivate table comes | |
(SELECT | |
COUNT(*) AS count | |
FROM | |
`bets` | |
WHERE | |
state = 'pending' | |
GROUP BY user_id | |
) b; # Every derived table must have its own alias | |
# Usage of the derivate table let us compute the AVG of the grouped sql count. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment