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

SQL For Data Analytics v2

This handbook by Aditya Tyagi teaches SQL from beginner to advanced levels, focusing on practical examples in PostgreSQL and MySQL. Key topics include data retrieval, joins, aggregations, and window functions, each illustrated with runnable SQL code. The document aims to equip readers with the skills necessary for data analytics using SQL.
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)
9 views2 pages

SQL For Data Analytics v2

This handbook by Aditya Tyagi teaches SQL from beginner to advanced levels, focusing on practical examples in PostgreSQL and MySQL. Key topics include data retrieval, joins, aggregations, and window functions, each illustrated with runnable SQL code. The document aims to equip readers with the skills necessary for data analytics using SQL.
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
You are on page 1/ 2

SQL for Data Analytics

Author: Aditya Tyagi

This handbook is designed to help you learn SQL from beginner to advanced concepts, with
runnable examples that work in PostgreSQL and MySQL.

Aditya Tyagi
1. Introduction to SQL
Structured Query Language (SQL) is the standard language for working with relational databases.
In this chapter, you will learn how to retrieve and filter data.

Example:
-- Select all columns from a table SELECT * FROM employees; -- Select specific
columns SELECT first_name, last_name, salary FROM employees; -- Filtering with
WHERE SELECT * FROM employees WHERE department = 'Finance';

2. Joins
Joins combine rows from two or more tables based on related columns.

Example:
-- INNER JOIN: returns matching rows SELECT c.customer_id, c.name, o.order_id,
o.order_date FROM customers c INNER JOIN orders o ON c.customer_id =
o.customer_id; -- LEFT JOIN: keep all rows from left table SELECT c.customer_id,
c.name, o.order_id FROM customers c LEFT JOIN orders o ON c.customer_id =
o.customer_id;

3. Aggregations
Aggregate functions allow you to summarize data using GROUP BY.

Example:
-- Count employees in each department SELECT department, COUNT(*) as
employee_count FROM employees GROUP BY department; -- Average salary per
department SELECT department, AVG(salary) as avg_salary FROM employees GROUP BY
department;

4. Window Functions
Window functions perform calculations across sets of rows related to the current row.

Example:
-- Rank employees by salary within each department SELECT department, first_name,
last_name, salary, RANK() OVER(PARTITION BY department ORDER BY salary DESC) as
rank FROM employees; -- Running total of sales SELECT order_id, order_date,
amount, SUM(amount) OVER(ORDER BY order_date) as running_total FROM orders;

Aditya Tyagi

You might also like