Skip to content

Commit 7764728

Browse files
[ADD] Multiple CTEs
1 parent 338828a commit 7764728

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

classes/30-multiple-ctes.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
WITH
2+
claps_per_post AS (
3+
SELECT
4+
post_id,
5+
SUM(counter)
6+
FROM claps
7+
GROUP BY post_id
8+
),
9+
posts_from_2023 AS (
10+
SELECT *
11+
FROM posts
12+
WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31'
13+
)
14+
15+
SELECT *
16+
FROM claps_per_post
17+
WHERE claps_per_post.post_id IN (
18+
SELECT post_id
19+
FROM posts_from_2023
20+
);

0 commit comments

Comments
 (0)