How to preserve grouping in subquery
Hello i have a sql query like this:
SELECT
COUNT(*) AS total,
COUNT(referrer) AS referrer,
DATE_FORMAT(created_at, "%Y") AS YEAR,
DATE_FORMAT(created_at, "%m") AS MONTH,
DATE_FORMAT(created_at, "%d") AS DAY
FROM
users
GROUP BY
EXTRACT(DAY FROM created_at),
EXTRACT(MONTH FROM created_at),
EXTRACT(YEAR FROM created_at)
ORDER BY
created_at ASC
This gives me table with totals sorted by day (month and year). what i
need is to add a subquery to display one more count() which has a
condition. Something like:
(SELECT count(*) FROM users WHERE result = '1') as winners
the problem obviously is with the grouping of main query since i get same
result without grouping the subquery for every row.
What would be the right way to execute such query?
No comments:
Post a Comment