how can i join data aggregated by day on a primary table?

If you version of SQL support analytic functions, then use COUNT here:

SELECT date, id, COUNT(id) OVER (PARTITION BY date) total_id_per_day
FROM yourTable
ORDER BY date;

If you are stuck without analytic functions, then use a join to a subquery which finds the counts:

SELECT t1.date, t1.id, t2.cnt AS total_id_per_day
FROM yourTable t1
INNER JOIN
(
    SELECT date, COUNT(id) AS cnt
    FROM yourTable
    GROUP BY date
) t2
    ON t2.date = t1.date
ORDER BY
    t1.date;

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top