sql-exercises / ex19.sql
ex19.sql
Raw
SELECT a.dateRep, SUM(b.cases), SUM(b.deaths) FROM
    (SELECT dateRep, STRFTIME(
                        SUBSTR(daterep, 7, 4)|| '-' ||
                        SUBSTR(daterep, 4, 2) || '-' ||
                        SUBSTR(daterep, 1, 2)
                    ) AS date
    FROM DateInfo ORDER BY date ASC) as a,
    (SELECT cases, deaths, STRFTIME(
                        SUBSTR(daterep, 7, 4)|| '-' ||
                        SUBSTR(daterep, 4, 2) || '-' ||
                        SUBSTR(daterep, 1, 2)
                    ) AS date
    FROM DailyStats WHERE geoId = 'UK' ORDER BY date ASC) as b
WHERE a.date >= b.date
GROUP BY a.date;