Skip to content

Instantly share code, notes, and snippets.

@xeviknal
Created September 21, 2016 10:20
Show Gist options
  • Save xeviknal/ce9eb229b19cecf14ddc21f1147663e0 to your computer and use it in GitHub Desktop.
Save xeviknal/ce9eb229b19cecf14ddc21f1147663e0 to your computer and use it in GitHub Desktop.
SQL: derivated table
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