Code24Lab
Databases & SQL Intermediate

PostgreSQL in Practice: Joins, JSONB, Window Functions & Views

Join and reshape data the PostgreSQL way with LATERAL, DISTINCT ON and recursive CTEs, query arrays and JSONB, rank and compare rows with window functions, and build views, materialized views and upserts, with every answer checked as you go.

20 lessons 20 labs Certificate

  • One-time payment
  • Instant access right after payment
  • Secure checkout with Stripe

About this course

This intermediate course teaches the PostgreSQL features that make everyday reporting shorter and safer. In 20 hands-on labs you join tables with USING and LATERAL, pick the latest row per group with DISTINCT ON, walk category trees with recursive CTEs and fill calendar gaps with generate_series. You query text arrays with @>, && and ANY, unnest them without double counting, and read JSONB documents with ->, ->>, ? and containment, including the indexes that serve them. Window functions cover ranking, running totals, frames and LAG/LEAD, and the course ends with views, materialized views and INSERT ... ON CONFLICT upserts. Every lab shows real SQL next to fictional data; you work out the exact result and get every answer checked.

Lessons

  1. Joins in PostgreSQL: USING, Aliases and a First ReportLabFree
  2. LEFT JOIN, COALESCE and the FILTER ClauseLab Locked
  3. DISTINCT ON: The Latest Row per GroupLab Locked
  4. LATERAL Joins: Top N Rows per GroupLab Locked
  5. CTEs: Building a Report in Readable StepsLab Locked
  6. WITH RECURSIVE: Walking a Category TreeLab Locked
  7. generate_series: Reports Without Missing DaysLab Locked
  8. Arrays: @>, && and ANYLab Locked
  9. unnest, array_agg and the Double-Counting TrapLab Locked
  10. JSONB: ->, ->>, ? and @>Lab Locked
  11. JSONB Arrays to Rows: jsonb_to_recordsetLab Locked
  12. GIN Indexes and Selectivity for JSONB and ArraysLab Locked
  13. Window Functions: ROW_NUMBER, RANK, DENSE_RANKLab Locked
  14. Running Totals and Window Frames: RANGE vs ROWSLab Locked
  15. LAG and LEAD: Month-over-Month ChangeLab Locked
  16. Shares and Top N per Group with Window AggregatesLab Locked
  17. Views: Saved Queries That Are Always CurrentLab Locked
  18. Materialized Views: Fast but StaleLab Locked
  19. UPSERT with INSERT ... ON CONFLICTLab Locked
  20. Final Project: A Customer Report in One QueryLab Locked