Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
28 lines (20 loc) · 901 Bytes

File metadata and controls

28 lines (20 loc) · 901 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- Description
-- 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
SELECT DATE(created_at) AS date, COUNT(*) AS count, CAST(SUM(COUNT(*)) OVER (ORDER BY DATE(created_at)) AS INTEGER) AS total
FROM posts
GROUP BY DATE(created_at)
ORDER BY DATE(created_at);
Morty Proxy This is a proxified and sanitized view of the page, visit original site.