-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ben Brumm
committed
Sep 25, 2024
1 parent
c6dc2be
commit 5a118e3
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
courses/course_postgres_mastery/exercises/exercises_module_7.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |