Skip to content

Commit 338828a

Browse files
[ADD] CTE
1 parent 72b2d40 commit 338828a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

classes/29-cte.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
WITH posts_week_2024 AS (
2+
SELECT
3+
DATE_TRUNC('week', p.created_at) AS weeks,
4+
COUNT(DISTINCT(p.post_id)) AS number_of_posts,
5+
SUM(c.counter) AS total_claps,
6+
COUNT(*) AS number_of_claps
7+
FROM posts AS p
8+
INNER JOIN claps AS c ON c.post_id = p.post_id
9+
GROUP BY weeks
10+
ORDER BY weeks DESC
11+
)
12+
13+
SELECT *
14+
FROM posts_week_2024
15+
WHERE weeks BETWEEN '2024-01-01' AND '2024-12-31'
16+
AND total_claps >= 600;

0 commit comments

Comments
 (0)