@Codingdidi
9.46K subscribers
26 photos
7 videos
47 files
257 links
Free learning Resources For Data Analysts, Data science, ML, AI, GEN AI and Job updates, career growth, Tech updates
Download Telegram
Complete topics & subtopics of hashtag #SQL for Data Analyst role:-

๐Ÿญ. ๐—•๐—ฎ๐˜€๐—ถ๐—ฐ ๐—ฆ๐—ค๐—Ÿ ๐—ฆ๐˜†๐—ป๐˜๐—ฎ๐˜…:
SQL keywords
Data types
Operators
SQL statements (SELECT, INSERT, UPDATE, DELETE)

๐Ÿฎ. ๐——๐—ฎ๐˜๐—ฎ ๐——๐—ฒ๐—ณ๐—ถ๐—ป๐—ถ๐˜๐—ถ๐—ผ๐—ป ๐—Ÿ๐—ฎ๐—ป๐—ด๐˜‚๐—ฎ๐—ด๐—ฒ (๐——๐——๐—Ÿ):
CREATE TABLE
ALTER TABLE
DROP TABLE
Truncate table

๐Ÿฏ. ๐——๐—ฎ๐˜๐—ฎ ๐— ๐—ฎ๐—ป๐—ถ๐—ฝ๐˜‚๐—น๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—Ÿ๐—ฎ๐—ป๐—ด๐˜‚๐—ฎ๐—ด๐—ฒ (๐——๐— ๐—Ÿ):
SELECT statement (SELECT, FROM, WHERE, ORDER BY, GROUP BY, HAVING, JOINs)
INSERT statement
UPDATE statement
DELETE statement

๐Ÿฐ. ๐—”๐—ด๐—ด๐—ฟ๐—ฒ๐—ด๐—ฎ๐˜๐—ฒ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€:
SUM, AVG, COUNT, MIN, MAX
GROUP BY clause
HAVING clause

๐Ÿฑ. ๐——๐—ฎ๐˜๐—ฎ ๐—–๐—ผ๐—ป๐˜€๐˜๐—ฟ๐—ฎ๐—ถ๐—ป๐˜๐˜€:
Primary Key
Foreign Key
Unique
NOT NULL
CHECK

๐Ÿฒ. ๐—๐—ผ๐—ถ๐—ป๐˜€:
INNER JOIN
LEFT JOIN
RIGHT JOIN
FULL OUTER JOIN
Self Join
Cross Join

๐Ÿณ. ๐—ฆ๐˜‚๐—ฏ๐—พ๐˜‚๐—ฒ๐—ฟ๐—ถ๐—ฒ๐˜€:
Types of subqueries (scalar, column, row, table)
Nested subqueries
Correlated subqueries

๐Ÿด. ๐—”๐—ฑ๐˜ƒ๐—ฎ๐—ป๐—ฐ๐—ฒ๐—ฑ ๐—ฆ๐—ค๐—Ÿ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€:
String functions (CONCAT, LENGTH, SUBSTRING, REPLACE, UPPER, LOWER)
Date and time functions (DATE, TIME, TIMESTAMP, DATEPART, DATEADD)
Numeric functions (ROUND, CEILING, FLOOR, ABS, MOD)
Conditional functions (CASE, COALESCE, NULLIF)

๐Ÿต. ๐—ฉ๐—ถ๐—ฒ๐˜„๐˜€:
Creating views
Modifying views
Dropping views

๐Ÿญ๐Ÿฌ. ๐—œ๐—ป๐—ฑ๐—ฒ๐˜…๐—ฒ๐˜€:
Creating indexes
Using indexes for query optimization

๐Ÿญ๐Ÿญ. ๐—ง๐—ฟ๐—ฎ๐—ป๐˜€๐—ฎ๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€:
ACID properties
Transaction management (BEGIN, COMMIT, ROLLBACK, SAVEPOINT)
Transaction isolation levels

๐Ÿญ๐Ÿฎ. ๐——๐—ฎ๐˜๐—ฎ ๐—œ๐—ป๐˜๐—ฒ๐—ด๐—ฟ๐—ถ๐˜๐˜† ๐—ฎ๐—ป๐—ฑ ๐—ฆ๐—ฒ๐—ฐ๐˜‚๐—ฟ๐—ถ๐˜๐˜†:
Data integrity constraints (referential integrity, entity integrity)
GRANT and REVOKE statements (granting and revoking permissions)
Database security best practices

๐Ÿญ๐Ÿฏ. ๐—ฆ๐˜๐—ผ๐—ฟ๐—ฒ๐—ฑ ๐—ฃ๐—ฟ๐—ผ๐—ฐ๐—ฒ๐—ฑ๐˜‚๐—ฟ๐—ฒ๐˜€ ๐—ฎ๐—ป๐—ฑ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€:
Creating stored procedures
Executing stored procedures
Creating functions
Using functions in queries

๐Ÿญ๐Ÿฐ. ๐—ฃ๐—ฒ๐—ฟ๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐—ป๐—ฐ๐—ฒ ๐—ข๐—ฝ๐˜๐—ถ๐—บ๐—ถ๐˜‡๐—ฎ๐˜๐—ถ๐—ผ๐—ป:
Query optimization techniques (using indexes, optimizing joins, reducing subqueries)
Performance tuning best practices

๐Ÿญ๐Ÿฑ. ๐—”๐—ฑ๐˜ƒ๐—ฎ๐—ป๐—ฐ๐—ฒ๐—ฑ ๐—ฆ๐—ค๐—Ÿ ๐—–๐—ผ๐—ป๐—ฐ๐—ฒ๐—ฝ๐˜๐˜€:
Recursive queries
Pivot and unpivot operations
Window functions (Row_number, rank, dense_rank, lead & lag)
CTEs (Common Table Expressions)
Dynamic SQL

๐—๐—ผ๐—ถ๐—ป ๐—บ๐˜† ๐—ง๐—ฒ๐—น๐—ฒ๐—ด๐—ฟ๐—ฎ๐—บ ๐—–๐—ต๐—ฎ๐—ป๐—ป๐—ฒ๐—น - https://t.me/codingdidi

If you've read so far, do LIKE the post๐Ÿ‘
๐Ÿ‘27โค3
Top 10 Advanced SQL Queries for Data Mastery

1. Recursive CTE (Common Table Expressions)
Use a recursive CTE to traverse hierarchical data, such as employees and their managers.

WITH RECURSIVE EmployeeHierarchy AS (
SELECT employee_id, employee_name, manager_id
FROM employees
WHERE manager_id IS NULL
UNION ALL
SELECT e.employee_id, e.employee_name, e.manager_id
FROM employees e
JOIN EmployeeHierarchy eh ON e.manager_id = eh.employee_id
)
SELECT *
FROM EmployeeHierarchy;


2. Pivoting Data
Turn row data into columns (e.g., show product categories as separate columns).

SELECT *
FROM (
SELECT TO_CHAR(order_date, 'YYYY-MM') AS month, product_category, sales_amount
FROM sales
) AS pivot_data
PIVOT (
SUM(sales_amount)
FOR product_category IN ('Electronics', 'Clothing', 'Books')
) AS pivoted_sales;


3. Window Functions
Calculate a running total of sales based on order date.

SELECT 
order_date,
sales_amount,
SUM(sales_amount) OVER (ORDER BY order_date) AS running_total
FROM sales;


4. Ranking with Window Functions
Rank employeesโ€™ salaries within each department.

SELECT 
department,
employee_name,
salary,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS salary_rank
FROM employees;


5. Finding Gaps in Sequences
Identify missing values in a sequential dataset (e.g., order numbers).

WITH Sequences AS (
SELECT MIN(order_number) AS start_seq, MAX(order_number) AS end_seq
FROM orders
)
SELECT start_seq + 1 AS missing_sequence
FROM Sequences
WHERE NOT EXISTS (
SELECT 1
FROM orders o
WHERE o.order_number = Sequences.start_seq + 1
);


6. Unpivoting Data
Convert columns into rows to simplify analysis of multiple attributes.

SELECT 
product_id,
attribute_name,
attribute_value
FROM products
UNPIVOT (
attribute_value FOR attribute_name IN (color, size, weight)
) AS unpivoted_data;


7. Finding Consecutive Events
Check for consecutive days/orders for the same product using LAG().

WITH ConsecutiveOrders AS (
SELECT
product_id,
order_date,
LAG(order_date) OVER (PARTITION BY product_id ORDER BY order_date) AS prev_order_date
FROM orders
)
SELECT product_id, order_date, prev_order_date
FROM ConsecutiveOrders
WHERE order_date - prev_order_date = 1;


8. Aggregation with the FILTER Clause
Calculate selective averages (e.g., only for the Sales department).

SELECT 
department,
AVG(salary) FILTER (WHERE department = 'Sales') AS avg_salary_sales
FROM employees
GROUP BY department;


9. JSON Data Extraction
Extract values from JSON columns directly in SQL.

SELECT 
order_id,
customer_id,
order_details ->> 'product' AS product_name,
CAST(order_details ->> 'quantity' AS INTEGER) AS quantity
FROM orders;


10. Using Temporary Tables
Create a temporary table for intermediate results, then join it with other tables.

-- Create a temporary table
CREATE TEMPORARY TABLE temp_product_sales AS
SELECT product_id, SUM(sales_amount) AS total_sales
FROM sales
GROUP BY product_id;

-- Use the temp table
SELECT p.product_name, t.total_sales
FROM products p
JOIN temp_product_sales t ON p.product_id = t.product_id;


Why These Matter
Advanced SQL queries let you handle complex data manipulation and analysis tasks with ease. From traversing hierarchical relationships to reshaping data (pivot/unpivot) and working with JSON, these techniques expand your ability to derive insights from relational databases.

Keep practicing these queries to solidify your SQL expertise and make more data-driven decisions!

Here you can find essential Pyspark Resources๐Ÿ‘‡
https://www.instagram.com/codingdidi

Like this post if you need more ๐Ÿ‘โค๏ธ

Hope it helps :)

#sql #dataanalyst
๐Ÿ‘5๐Ÿ”ฅ2โค1