Skip to content

Commit

Permalink
Added module 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Brumm committed Sep 25, 2024
1 parent c6dc2be commit 5a118e3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions courses/course_postgres_mastery/exercises/exercises_module_7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Exercises from the PostgreSQL Mastery course
Module 7
*/

/* 49-01 */

SELECT
c.customer_id,
c.first_name,
c.last_name,
c.email,
s.order_id,
s.order_date
FROM customer c
JOIN LATERAL (
SELECT co.*
FROM cust_order co
WHERE co.customer_id = c.customer_id
ORDER BY co.order_date ASC
FETCH FIRST 3 ROWS ONLY
) s ON TRUE
ORDER BY c.customer_id ASC;

/* 51-01 */

SELECT
c.customer_id,
c.first_name,
c.last_name,
c.email,
s.order_id,
s.order_date
FROM customer c
LEFT JOIN LATERAL (
SELECT co.*
FROM cust_order co
WHERE co.customer_id = c.customer_id
ORDER BY co.order_date ASC
FETCH FIRST 3 ROWS ONLY
) s ON TRUE
ORDER BY c.customer_id ASC;

0 comments on commit 5a118e3

Please sign in to comment.