Ok, so I have the following query:
SELECT MIN(`date`), `player_name`
FROM `player_playtime`
GROUP BY `player_name`
I then need to use this result inside the following query:
SELECT DATE(`date`) , COUNT(DISTINCT `player_name`)
FROM `player_playtime /*Use previous query result here*/`
GROUP BY DATE( `date`) DESC LIMIT 60
How would I go about doing this?
You just need to write the first query as a subquery (derived table), inside parentheses, pick an alias for it (
t
below) and alias the columns as well.The
DISTINCT
can also be safely removed as the internalGROUP BY
makes it redundant:Since the
COUNT
is now obvious that is only counting rows of the derived table, you can replace it withCOUNT(*)
and further simplify the query: