0% found this document useful (0 votes)
4 views2 pages

SQL Cheat Sheet for Data Analysts

This document is a quick reference guide for SQL used by data analysts, covering essential commands and concepts such as SELECT statements, filtering, sorting, aggregations, joins, subqueries, window functions, and data cleaning. It provides examples for each topic, including how to use logical operators, CASE statements, and common practices for data analysis. Additionally, it suggests resources for practice and emphasizes the importance of mastering joins and aggregations.

Uploaded by

Sachin Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

SQL Cheat Sheet for Data Analysts

This document is a quick reference guide for SQL used by data analysts, covering essential commands and concepts such as SELECT statements, filtering, sorting, aggregations, joins, subqueries, window functions, and data cleaning. It provides examples for each topic, including how to use logical operators, CASE statements, and common practices for data analysis. Additionally, it suggests resources for practice and emphasizes the importance of mastering joins and aggregations.

Uploaded by

Sachin Singh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL for Data Analyst - Quick Reference Guide

1. SELECT Basics

SELECT column_name FROM table_name;


SELECT * FROM employees;
Use WHERE to filter rows:
SELECT * FROM employees WHERE age > 30;

2. Filtering & Logical Operators

WHERE age BETWEEN 25 AND 35;


WHERE department IN ('Sales', 'Marketing');
WHERE name LIKE 'A%';
WHERE NOT city = 'Delhi';

3. Sorting & Limiting Results

ORDER BY salary DESC;


SELECT * FROM employees ORDER BY age LIMIT 5;

4. Aggregations

SELECT COUNT(*), AVG(salary), MAX(age) FROM employees;


GROUP BY department;
HAVING COUNT(*) > 5

5. Joins (Most Important)

INNER JOIN: employees INNER JOIN departments ON employees.dept_id = [Link]


LEFT JOIN: Keeps all records from left
RIGHT JOIN, FULL JOIN similar

6. Subqueries & CTEs

Subquery: SELECT name FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
CTE:
WITH dept_avg AS (
SELECT dept_id, AVG(salary) AS avg_sal FROM employees GROUP BY dept_id
)
SELECT * FROM dept_avg;

7. Window Functions
SQL for Data Analyst - Quick Reference Guide

ROW_NUMBER() OVER(PARTITION BY dept_id ORDER BY salary DESC)


RANK(), DENSE_RANK(), SUM() OVER(), AVG() OVER()

8. CASE Statement

SELECT name, salary,


CASE WHEN salary > 50000 THEN 'High' ELSE 'Low' END AS Salary_Level FROM employees;

9. Data Cleaning

IS NULL, COALESCE(column, 'Unknown')


CAST(salary AS INT), TRIM(name), REPLACE(name, 'Mr. ', '')

10. Practice Advice

Use: [Link], [Link], [Link]


Focus on joins, aggregations, window functions

You might also like