Introduction
SQL (Structured Query Language) is one of the most important tools used by data analysts to retrieve, organize, transform, and analyze data stored in relational databases. PostgreSQL is a powerful open source relational database management system that supports advanced SQL features for solving real-world business problems.
This guide covers four skills that take you from basic queries to real analysis in PostgreSQL: window functions, joins, common table expressions (CTEs) and subqueries.
1. SQL Window Functions
A window function performs a calculation across a group of related rows while retaining the individual rows in the output.
Imagine that a hospital manager wants to rank hospital visits according to their total bills. A normal aggregation could calculate the total or average bill, but it might combine multiple visits into one result.…