You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Given a posts table that contains a created_at timestamp column write a query that returns date (without time component),
-- a number of posts for a given date and a running (cumulative) total number of posts up until a given date. The resulting set should be ordered chronologically by date.
-- Desired Output
-- The resulting set should look similar to the following:
date | count | total
-----------+-------+-------
2017-01-26 | 20 | 20
2017-01-27 | 17 | 37
2017-01-28 | 7 | 44
2017-01-29 | 8 | 52
...
-- date - (DATE) date
-- count - (INT) number of posts for a date
-- total - (INT) a running (cumulative) number of posts up until a date
-- ANSWER
SELECTDATE(created_at) ASdate, COUNT(*) AS count, CAST(SUM(COUNT(*)) OVER (ORDER BYDATE(created_at)) ASINTEGER) AS total