From 20219dd4f7192c61492b7667dd3f15b05dbba044 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sat, 23 Sep 2023 20:19:44 +0200 Subject: feat: Add post to version control --- content/posts/postgres-aggregates/aggregation.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 content/posts/postgres-aggregates/aggregation.sql (limited to 'content/posts/postgres-aggregates/aggregation.sql') diff --git a/content/posts/postgres-aggregates/aggregation.sql b/content/posts/postgres-aggregates/aggregation.sql new file mode 100644 index 0000000..ebb9ed5 --- /dev/null +++ b/content/posts/postgres-aggregates/aggregation.sql @@ -0,0 +1,20 @@ +EXPLAIN ( + ANALYZE, + COSTS, + VERBOSE, + BUFFERS +) +SELECT + products.id AS product_id, + products.name AS product_name, + COUNT(DISTINCT reviews.id) AS num_reviews, + COUNT(DISTINCT orders.id) AS num_orders +FROM + products + LEFT JOIN reviews ON reviews.product_id = products.id + LEFT JOIN orders ON orders.product_id = products.id + -- WHERE + -- products.id % 10 = 0 +GROUP BY + products.id; + -- cgit v1.3