SQL For Data Analytics


Гео и язык канала: Весь мир, Английский
Категория: Карьера


This channel covers everything you need to learn SQL for data science, data analyst, data engineer and business analyst roles.

Связанные каналы

Гео и язык канала
Весь мир, Английский
Категория
Карьера
Статистика
Фильтр публикаций


⚡️ DISCOVER ALEXATOR — NEW RELEASE 011–015

5 new electronic tracks created to inspire, motivate and energize.

🌐 ALEXATOR.COM
🎧 Listen & download for free
🎵 Music
🎬 Music Videos

📲 t.me/alexator_music
Follow for new music, videos & updates.

🎧 STREAMING & SOCIAL
🟢 Spotify
🎵 Apple Music
▶️ YouTube — ALEXATOR


Double Tap ❤️ For More SQL Notes


30-day Roadmap plan for SQL covers beginner, intermediate, and advanced topics 👇

Week 1: Beginner Level

Day 1-3: Introduction and Setup
1. Day 1: Introduction to SQL, its importance, and various database systems.
2. Day 2: Installing a SQL database (e.g., MySQL, PostgreSQL).
3. Day 3: Setting up a sample database and practicing basic commands.

Day 4-7: Basic SQL Queries
4. Day 4: SELECT statement, retrieving data from a single table.
5. Day 5: WHERE clause and filtering data.
6. Day 6: Sorting data with ORDER BY.
7. Day 7: Aggregating data with GROUP BY and using aggregate functions (COUNT, SUM, AVG).

Week 2-3: Intermediate Level

Day 8-14: Working with Multiple Tables
8. Day 8: Introduction to JOIN operations.
9. Day 9: INNER JOIN and LEFT JOIN.
10. Day 10: RIGHT JOIN and FULL JOIN.
11. Day 11: Subqueries and correlated subqueries.
12. Day 12: Creating and modifying tables with CREATE, ALTER, and DROP.
13. Day 13: INSERT, UPDATE, and DELETE statements.
14. Day 14: Understanding indexes and optimizing queries.

Day 15-21: Data Manipulation
15. Day 15: CASE statements for conditional logic.
16. Day 16: Using UNION and UNION ALL.
17. Day 17: Data type conversions (CAST and CONVERT).
18. Day 18: Working with date and time functions.
19. Day 19: String manipulation functions.
20. Day 20: Error handling with TRY...CATCH.
21. Day 21: Practice complex queries and data manipulation tasks.

Week 4: Advanced Level

Day 22-28: Advanced Topics
22. Day 22: Working with Views.
23. Day 23: Stored Procedures and Functions.
24. Day 24: Triggers and transactions.
25. Day 25: Windows Function

Day 26-30: Real-World Projects
26. Day 26: SQL Project-1
27. Day 27: SQL Project-2
28. Day 28: SQL Project-3
29. Day 29: Practice questions set
30. Day 30: Final review and practice, explore advanced topics in depth, or work on a personal project.

Like for more ❤️

Free Resources to learn SQL: https://whatsapp.com/channel/0029VanC5rODzgT6TiTGoa1v/1394


📊 4 SQL Interview Scenarios Asked in Real Interviews

1️⃣ Find the 2nd Highest Salary

💡 Question:
Write a query to find the second highest salary without using LIMIT or TOP.

💡 Answer:
Use DENSE_RANK() or a subquery.

2️⃣ Find Duplicate Records

💡 Question:
How would you find duplicate email IDs in a Customers table?

💡 Answer:
Use GROUP BY with HAVING COUNT(*) > 1.

3️⃣ Find the Top 3 Highest Salaries in Each Department

💡 Question:
Write a query to retrieve the top 3 highest-paid employees from every department.

💡 Answer:
Use DENSE_RANK() or ROW_NUMBER() with PARTITION BY.

4️⃣ Delete Duplicate Records While Keeping One Copy

💡 Question:
How would you remove duplicate rows while retaining only one record?

💡 Answer:
Use a CTE with ROW_NUMBER() and delete rows where the row number is greater than 1.

❤️ React for more SQL interview scenarios!


🚨 SQL Myth You Should Stop Believing

❌ Myth: You need to memorize 500+ SQL functions to crack Data Analyst interviews.

✅ Reality: Most interviewers care more about your problem-solving skills than how many functions you remember.

If you’re comfortable with:

✔️ JOINs
✔️ GROUP BY & Aggregations
✔️ Window Functions
✔️ CTEs
✔️ CASE WHEN
✔️ Subqueries

...you’ll have a strong foundation for many Data Analyst interviews.

💡 Instead of memorizing every function, spend your time solving real SQL interview questions. That’s where the real learning happens.

🔥 Concepts > Memorization. Practice > Perfection.


SQL Interview Questions asked by Urban Company:-

Question 1: Monthly Revenue Trends by Category

Scenario: Analyze monthly revenue trends for each product category.
Table:
1. transactions (Transaction_id, Product_id, Amount_spent, Transaction_date),

2. products (Product_id, Category)

Challenge: Write a SQL query to calculate the total revenue for each category on a monthly basis and identify the top 3 categories with the highest revenue growth month-over-month.

Question 2: Customer Retention Analysis
Scenario: Determine the retention rate of customers.

Table:
1. customer_visits (Customer_id, Visit_date)

Challenge: Write a SQL query to calculate the retention rate of customers month-over-month for the past year, identifying the percentage of customers who return the following month.

Question 3: Product Affinity Analysis
Scenario: Identify products that are frequently bought together.

Table:
1. order_details (Order_id, Product_id, Quantity)

Challenge: Write a SQL query to find pairs of products that are frequently bought together. Include the count of how many times each pair appears in the same order and rank them by frequency.

Question 4: Customer Purchase Segmentation

Scenario: Segment customers based on their purchase behavior.
Table:
1. purchases (Customer_id, Product_id, Amount_spent, Purchase_date)

Challenge: Write a SQL query to segment customers into different groups based on their total spending and purchase frequency in the last year. Classify them into categories like 'High Spenders', 'Medium Spenders', and 'Low Spenders'.

Question 5: Anomaly Detection in Transactions

Scenario: Detect anomalies in transaction amounts.
Table:
1. transactions (Transaction_id, Customer_id, Amount_spent, Transaction_date)

Challenge: Write a SQL query to identify transactions that deviate significantly from the customer's average spending. Flag transactions that are more than three standard deviations away from the mean spending amount for each customer.






SQL Guide with Free Resources.pdf
5.1Мб
React with ♥️ for more free resources


Essential SQL Functions 👇👇

### DATE AND TIME FUNCTIONS:
- NOW(): Returns the current date and time.
- CURDATE(): Returns the current date.
- CURTIME(): Returns the current time.
- DATE(): Extracts the date part of a date or datetime expression.
- DATEDIFF(): Returns the number of days between two date values.
- YEAR(): Extracts the year.
- MONTH(): Extracts the month.
- DAY(): Extracts the day of the month.
- HOUR(): Extracts the hour.
- MINUTE(): Extracts the minute.
- SECOND(): Extracts the second.

### AGGREGATE FUNCTIONS:
- SUM(): Returns the sum of a set of values.
- AVG(): Returns the average value of a numeric column.
- MIN(): Returns the minimum value in a set of values.
- MAX(): Returns the maximum value in a set of values.
- COUNT(): Returns the number of rows that matches a specified condition.
- COUNT(*): Returns the number of rows in a table.
- COUNT(DISTINCT column_name): Returns the number of distinct values in a column.

### STRING FUNCTIONS:
- CONCAT(): Concatenates two or more strings.
- LENGTH(): Returns the length of a string.
- UPPER(): Converts a string to upper-case.
- LOWER(): Converts a string to lower-case.
- LEFT(): Extracts a number of characters from a string (starting from left).
- RIGHT(): Extracts a number of characters from a string (starting from right).
- SUBSTRING(): Extracts a substring from a string.

### NUMERIC FUNCTIONS:
- ROUND(): Rounds a number to a specified number of decimal places.
- FLOOR(): Returns the largest integer value less than or equal to a number.
- CEIL(): Returns the smallest integer value greater than or equal to a number.
- ABS(): Returns the absolute value of a number.

### INFORMATION FUNCTIONS:
- ISNULL(): Returns a specified value if the expression is NULL.
- COALESCE(): Returns the first non-null value in a list.
- NULLIF(): Returns NULL if the two expressions are equal.

### LOGICAL FUNCTIONS:
- IF(): Returns one value if a condition is TRUE, and another value if it is FALSE.
- CASE: Evaluates a list of conditions and returns one of multiple possible result expressions.
- AND: Combines two or more conditions and returns TRUE if all conditions are TRUE.
- OR: Combines two or more conditions and returns TRUE if any condition is TRUE.
- NOT: Reverses the value of a boolean expression.

### JSON FUNCTIONS:
- JSON_EXTRACT(): Extracts data from a JSON document.
- JSON_OBJECT(): Creates a JSON object from a list of key-value pairs.

### WINDOW FUNCTIONS:
- ROW_NUMBER(): Assigns a unique sequential integer to rows within a partition.
- RANK(): Assigns a rank to each row within a partition.
- DENSE_RANK(): Similar to RANK(), but without gaps in the ranking sequence.
- NTILE(): Divides rows into a specified number of approximately equal groups.

### OTHER FUNCTIONS:
- CAST(): Converts a value of one data type to another.
- CONVERT(): Converts a value of one data type to another.
- COALESCE(): Returns the first non-null expression among its arguments.

Here you can find SQL Interview Resources👇
https://whatsapp.com/channel/0029VaGgzAk72WTmQFERKh02

Like this post if you need more 👍❤️

Share with credits: https://t.me/sqlspecialist

Hope it helps :)


SQL Functions Interview Questions with Answers 🎯📚

1️⃣ Q: What is the difference between COUNT(*) and COUNT(column_name)?
A:
- COUNT(*) counts all rows, including those with NULLs.
- COUNT(column_name) counts only rows where the column is NOT NULL.

2️⃣ Q: When would you use GROUP BY with aggregate functions?
A:
Use GROUP BY when you want to apply aggregate functions per group (e.g., department-wise total salary):
SELECT department, SUM(salary) FROM employees GROUP BY department;

3️⃣ Q: What does the COALESCE() function do?
A:
COALESCE() returns the first non-null value from the list of arguments.
Example:
SELECT COALESCE(phone, 'N/A') FROM users;

4️⃣ Q: How does the CASE statement work in SQL?
A:
CASE is used for conditional logic inside queries.
Example:
SELECT name,
CASE
WHEN score >= 90 THEN 'A'
WHEN score >= 75 THEN 'B'
ELSE 'C'
END AS grade
FROM students;

5️⃣ Q: What’s the use of SUBSTRING() function?
A:
It extracts a part of a string.
Example:
SELECT SUBSTRING('DataScience', 1, 4); -- Output: Data

6️⃣ Q: What’s the output of LENGTH('SQL')?
A:
It returns the length of the string: 3

7️⃣ Q: How do you find the number of days between two dates?
A:
Use DATEDIFF(end_date, start_date)
Example:
SELECT DATEDIFF('2026-01-10', '2026-01-05'); -- Output: 5

8️⃣ Q: What does ROUND() do in SQL?
A:
It rounds a number to the specified decimal places.
Example:
SELECT ROUND(3.456, 2); -- Output: 3.46

💡 Pro Tip: Always mention real use cases when answering — it shows practical understanding.

💬 Tap ❤️ for more!




sql notes.pdf
36.5Мб
SQL Handwritten Notes 📔🗒


🗄️ SQL Developer Roadmap

📂 SQL Basics (SELECT, WHERE, ORDER BY)
∟📂 Joins (INNER, LEFT, RIGHT, FULL)
∟📂 Aggregate Functions (COUNT, SUM, AVG)
∟📂 Grouping Data (GROUP BY, HAVING)
∟📂 Subqueries & Nested Queries
∟📂 Data Modification (INSERT, UPDATE, DELETE)
∟📂 Database Design (Normalization, Keys)
∟📂 Indexing & Query Optimization
∟📂 Stored Procedures & Functions
∟📂 Transactions & Locks
∟📂 Views & Triggers
∟📂 Backup & Restore
∟📂 Working with NoSQL basics (optional)
∟📂 Real Projects & Practice
∟✅ Apply for SQL Dev Roles

❤️ React for More!


🎯 SQL Fundamentals Part-1: SELECT Basics

SELECT is the most used SQL command, used to retrieve data from a database.

Think of SQL like asking questions to a database. SELECT = asking what data you want.

✅ What is SELECT in SQL?
SELECT statement retrieves data from one or more tables in a database.

👉 Basic Syntax
SELECT column_name
FROM table_name;


How SQL executes:
1. Finds table (FROM)
2. Applies filter (WHERE)
3. Returns selected columns (SELECT)
4. Sorts results (ORDER BY)
5. Limits rows (LIMIT)

🔹 1. SELECT All Columns (SELECT *)
Used to retrieve every column from a table.

SELECT *
FROM employees;


👉 Returns complete table data.

📌 When to use:
✔ Exploring new dataset
✔ Checking table structure
✔ Quick testing

⚠️ Avoid in production: Slow on large tables, fetches unnecessary data.

🔹 2. SELECT Specific Columns
Best practice — retrieve only required data.
SELECT name, salary
FROM employees;


👉 Returns only selected columns.
💡 Why important:
✅ Faster queries
✅ Better performance
✅ Cleaner results

🔹 3. FROM Clause (Data Source)
Specifies where data comes from.
SELECT name
FROM customers;


👉 SQL reads data from customers table.

🔹 4. WHERE Clause (Filtering Data)
Used to filter rows based on conditions.
SELECT column
FROM table
WHERE condition;


Examples:
- Filter by value: SELECT * FROM employees WHERE salary > 50000;
- Filter by text: SELECT * FROM employees WHERE city = 'Mumbai';

🔹 5. ORDER BY (Sorting Results)
Sorts query results.
SELECT column
FROM table
ORDER BY column ASC | DESC;


Examples:
- Ascending: SELECT name, salary FROM employees ORDER BY salary ASC;
- Descending: SELECT name, salary FROM employees ORDER BY salary DESC;

🔹 6. LIMIT (Control Output Rows)
Restricts number of returned rows.
SELECT *
FROM employees
LIMIT 5;


👉 Returns first 5 records.

⭐ SQL Query Execution Order
1. FROM
2. WHERE
3. SELECT
4. ORDER BY
5. LIMIT

🧠 Real-World Example
Business question: "Show top 10 highest paid employees."
SELECT name, salary
FROM employees
ORDER BY salary DESC
LIMIT 10;


🚀 Mini Practice Tasks
Task 1: Get all records from customers.
Task 2: Show only customer name and city.
Task 3: Find employees with salary > 40000.
Task 4: Show top 3 highest priced products.

Double Tap ♥️ For Part-2


🗄️ SQL Developer Roadmap

📂 SQL Basics (SELECT, WHERE, ORDER BY)
∟📂 Joins (INNER, LEFT, RIGHT, FULL)
∟📂 Aggregate Functions (COUNT, SUM, AVG)
∟📂 Grouping Data (GROUP BY, HAVING)
∟📂 Subqueries & Nested Queries
∟📂 Data Modification (INSERT, UPDATE, DELETE)
∟📂 Database Design (Normalization, Keys)
∟📂 Indexing & Query Optimization
∟📂 Stored Procedures & Functions
∟📂 Transactions & Locks
∟📂 Views & Triggers
∟📂 Backup & Restore
∟📂 Working with NoSQL basics (optional)
∟📂 Real Projects & Practice
∟✅ Apply for SQL Dev Roles

❤️ React for More!


SQL Window Functions 🪟📊

Window functions perform calculations across rows related to the current row without collapsing them like GROUP BY does.

1️⃣ ROW_NUMBER()
Gives a unique number to each row in a partition.
SELECT name, dept_id,
ROW_NUMBER() OVER (
PARTITION BY dept_id
ORDER BY salary DESC
) AS rank
FROM employees;
📌 Use case: Rank employees by salary within each department.

2️⃣ RANK() vs DENSE_RANK()
⦁ RANK() → Skips numbers on ties (1, 2, 2, 4)
⦁ DENSE_RANK() → No gaps (1, 2, 2, 3)
SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) AS rnk,
DENSE_RANK() OVER (ORDER BY salary DESC) AS dense_rnk
FROM employees;

3️⃣ LAG() and LEAD()
Access previous/next row values.
SELECT name, salary,
LAG(salary) OVER (ORDER BY id) AS prev_salary,
LEAD(salary) OVER (ORDER BY id) AS next_salary
FROM employees;
📌 Use case: Compare current row to previous/next (e.g., salary or stock change).

4️⃣ NTILE(n)
Divides rows into n buckets.
SELECT name,
NTILE(4) OVER (ORDER BY salary DESC) AS quartile
FROM employees;
📌 Use case: Quartiles/percentile-style grouping.

5️⃣ SUM(), AVG(), COUNT() with OVER()
Running totals, partition-wise aggregates, moving stats.
SELECT name, dept_id, salary,
SUM(salary) OVER (PARTITION BY dept_id) AS dept_total
FROM employees;


🧠 Interview Q&A

Q1: Difference between GROUP BY and OVER()?
⦁ GROUP BY → Collapses rows into groups; one row per group.
⦁ OVER() → Keeps all rows; adds an extra column with the aggregate.

Q2: When would you use LAG()?
To compare current row values with previous ones (e.g., day‑to‑day revenue change, previous month’s balance).

Q3: What happens if no PARTITION BY is used?
The function runs over the entire result set as a single partition.

Q4: Can you sort inside OVER()?
Yes, ORDER BY inside OVER() defines the calculation order (needed for ranking, LAG/LEAD, running totals).

💬 Double Tap ❤️ for more!


Recursive CTE in SQL


𝗦𝗤𝗟 𝗙𝗿𝗼𝗺 𝗕𝗮𝘀𝗶𝗰𝘀 𝘁𝗼 𝗔𝗱𝘃𝗮𝗻𝗰𝗲𝗱: This PDF-file contains SQL from beginner to advanced level.

You will need this 101-page PDF file to prepare and review SQL before any data-related interview.

https://drive.google.com/file/d/1N2uPi4hkdCLYPgBa5UfjFT4koqMbGUHz/view


🔰 Explaining PostgreSQL

Показано 20 последних публикаций.