SQL Cheatsheet for Data Analysis
Essential SQL for Analysts
Basic Queries
SELECT column1, column2 FROM table_name;
SELECT * FROM table_name WHERE condition;
SELECT * FROM table_name ORDER BY column_name ASC/DESC;
Aggregations
COUNT(): Counts the number of rows.
SUM(): Calculates the sum of values.
AVG(): Calculates the average of values.
MIN() / MAX(): Find the minimum/maximum value.
GROUP BY: Groups rows that have the same values into summary rows.
Joins
INNER JOIN: Returns records that have matching values in both tables.
LEFT JOIN: Returns all records from the left table, and the matched records from the right table.
RIGHT JOIN: Returns all records from the right table, and the matched records from the left table.