✅ SQL Window Functions 🧠🪟
Window functions perform calculations across rows that are related to the current row — without collapsing the result like GROUP BY.
1️⃣ ROW_NUMBER() – Assigns a unique row number per partition
➤ Gives ranking within each department
2️⃣ RANK() & DENSE_RANK() – Ranking with gaps (RANK) or without gaps (DENSE_RANK)
3️⃣ LAG() & LEAD() – Access previous or next row value
➤ Compare salary trends row-wise
4️⃣ SUM(), AVG(), COUNT() OVER() – Running totals, moving averages, etc.
5️⃣ NTILE(n) – Divides rows into n equal buckets
💡 Why Use Window Functions:
• Perform row-wise calculations
• Avoid GROUP BY limitations
• Enable advanced analytics (ranking, trends, etc.)
🧪 Practice Task:
Write a query to find the top 2 earners in each department using ROW_NUMBER().
💬 Tap ❤️ for more!
Window functions perform calculations across rows that are related to the current row — without collapsing the result like GROUP BY.
1️⃣ ROW_NUMBER() – Assigns a unique row number per partition
SELECT name, department,
ROW_NUMBER() OVER (PARTITION BY department ORDER BY salary DESC) AS rank
FROM employees;
➤ Gives ranking within each department
2️⃣ RANK() & DENSE_RANK() – Ranking with gaps (RANK) or without gaps (DENSE_RANK)
SELECT name, salary,
RANK() OVER (ORDER BY salary DESC) AS rank
FROM employees;
3️⃣ LAG() & LEAD() – Access previous or next row value
SELECT name, salary,
LAG(salary) OVER (ORDER BY salary) AS prev_salary,
LEAD(salary) OVER (ORDER BY salary) AS next_salary
FROM employees;
➤ Compare salary trends row-wise
4️⃣ SUM(), AVG(), COUNT() OVER() – Running totals, moving averages, etc.
SELECT department, salary,
SUM(salary) OVER (PARTITION BY department) AS dept_total
FROM employees;
5️⃣ NTILE(n) – Divides rows into n equal buckets
SELECT name, salary,
NTILE(4) OVER (ORDER BY salary DESC) AS quartile
FROM employees;
💡 Why Use Window Functions:
• Perform row-wise calculations
• Avoid GROUP BY limitations
• Enable advanced analytics (ranking, trends, etc.)
🧪 Practice Task:
Write a query to find the top 2 earners in each department using ROW_NUMBER().
💬 Tap ❤️ for more!
❤6
✅ SQL Real-World Use Cases 💼🧠
SQL is the backbone of data analysis and automation in many domains. Here’s how it powers real work:
1️⃣ Sales & CRM
Use Case: Sales Tracking & Pipeline Management
• Track sales per region, product, rep
• Identify top-performing leads
• Calculate conversion rates
SQL Task:
2️⃣ Finance
Use Case: Monthly Revenue and Expense Reporting
• Aggregate revenue by month
• Analyze profit margins
• Flag unusual transactions
SQL Task:
3️⃣ HR Analytics
Use Case: Employee Attrition Analysis
• Track tenure, exits, departments
• Calculate average retention
• Segment by age, role, or location
SQL Task:
4️⃣ E-commerce
Use Case: Customer Order Behavior
• Find most ordered products
• Time between repeat orders
• Cart abandonment patterns
SQL Task:
5️⃣ Healthcare
Use Case: Patient Visit Frequency
• Find frequent visitors
• Analyze doctor performance
• Calculate average stay duration
SQL Task:
6️⃣ Marketing
Use Case: Campaign Performance by Channel
• Track leads, clicks, conversions
• Compare cost-per-lead by platform
SQL Task:
🧪 Practice Task:
Pick a dataset (orders, users, sales)
→ Write 3 queries: summary, trend, filter
→ Visualize the output in Excel or Power BI
💬 Tap ❤️ for more!
SQL is the backbone of data analysis and automation in many domains. Here’s how it powers real work:
1️⃣ Sales & CRM
Use Case: Sales Tracking & Pipeline Management
• Track sales per region, product, rep
• Identify top-performing leads
• Calculate conversion rates
SQL Task:
SELECT region, SUM(sales_amount)
FROM deals
GROUP BY region;
2️⃣ Finance
Use Case: Monthly Revenue and Expense Reporting
• Aggregate revenue by month
• Analyze profit margins
• Flag unusual transactions
SQL Task:
SELECT MONTH(date), SUM(revenue - expense) AS profit
FROM finance_data
GROUP BY MONTH(date);
3️⃣ HR Analytics
Use Case: Employee Attrition Analysis
• Track tenure, exits, departments
• Calculate average retention
• Segment by age, role, or location
SQL Task:
SELECT department, COUNT(*)
FROM employees
WHERE exit_date IS NOT NULL
GROUP BY department;
4️⃣ E-commerce
Use Case: Customer Order Behavior
• Find most ordered products
• Time between repeat orders
• Cart abandonment patterns
SQL Task:
SELECT customer_id, COUNT(order_id)
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 5;
5️⃣ Healthcare
Use Case: Patient Visit Frequency
• Find frequent visitors
• Analyze doctor performance
• Calculate average stay duration
SQL Task:
SELECT patient_id, COUNT(*) AS visits
FROM appointments
GROUP BY patient_id;
6️⃣ Marketing
Use Case: Campaign Performance by Channel
• Track leads, clicks, conversions
• Compare cost-per-lead by platform
SQL Task:
SELECT channel, SUM(conversions)/SUM(clicks) AS conv_rate
FROM campaign_data
GROUP BY channel;
🧪 Practice Task:
Pick a dataset (orders, users, sales)
→ Write 3 queries: summary, trend, filter
→ Visualize the output in Excel or Power BI
💬 Tap ❤️ for more!
❤4
📊 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 𝗙𝗥𝗘𝗘 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝘂𝗿𝘀𝗲😍
🚀Upgrade your skills with industry-relevant Data Analytics training at ZERO cost
✅ Beginner-friendly
✅ Certificate on completion
✅ High-demand skill in 2026
𝐋𝐢𝐧𝐤 👇:-
https://pdlink.in/497MMLw
📌 100% FREE – Limited seats available!
🚀Upgrade your skills with industry-relevant Data Analytics training at ZERO cost
✅ Beginner-friendly
✅ Certificate on completion
✅ High-demand skill in 2026
𝐋𝐢𝐧𝐤 👇:-
https://pdlink.in/497MMLw
📌 100% FREE – Limited seats available!
✅ Useful Platform to Practice SQL Programming 🧠🖥️
Learning SQL is just the first step — practice is what builds real skill. Here are the best platforms for hands-on SQL:
1️⃣ LeetCode – For Interview-Oriented SQL Practice
• Focus: Real interview-style problems
• Levels: Easy to Hard
• Schema + Sample Data Provided
• Great for: Data Analyst, Data Engineer, FAANG roles
✔ Tip: Start with Easy → filter by “Database” tag
✔ Popular Section: Database → Top 50 SQL Questions
Example Problem: “Find duplicate emails in a user table” → Practice filtering, GROUP BY, HAVING
2️⃣ HackerRank – Structured & Beginner-Friendly
• Focus: Step-by-step SQL track
• Has certification tests (SQL Basic, Intermediate)
• Problem sets by topic: SELECT, JOINs, Aggregations, etc.
✔ Tip: Follow the full SQL track
✔ Bonus: Company-specific challenges
Try: “Revising Aggregations – The Count Function” → Build confidence with small wins
3️⃣ Mode Analytics – Real-World SQL in Business Context
• Focus: Business intelligence + SQL
• Uses real-world datasets (e.g., e-commerce, finance)
• Has an in-browser SQL editor with live data
✔ Best for: Practicing dashboard-level queries
✔ Tip: Try the SQL case studies & tutorials
4️⃣ StrataScratch – Interview Questions from Real Companies
• 500+ problems from companies like Uber, Netflix, Google
• Split by company, difficulty, and topic
✔ Best for: Intermediate to advanced level
✔ Tip: Try “Hard” questions after doing 30–50 easy/medium
5️⃣ DataLemur – Short, Practical SQL Problems
• Crisp and to the point
• Good UI, fast learning
• Real interview-style logic
✔ Use when: You want fast, smart SQL drills
📌 How to Practice Effectively:
• Spend 20–30 mins/day
• Focus on JOINs, GROUP BY, HAVING, Subqueries
• Analyze problem → write → debug → re-write
• After solving, explain your logic out loud
🧪 Practice Task:
Try solving 5 SQL questions from LeetCode or HackerRank this week. Start with SELECT, WHERE, and GROUP BY.
💬 Tap ❤️ for more!
Learning SQL is just the first step — practice is what builds real skill. Here are the best platforms for hands-on SQL:
1️⃣ LeetCode – For Interview-Oriented SQL Practice
• Focus: Real interview-style problems
• Levels: Easy to Hard
• Schema + Sample Data Provided
• Great for: Data Analyst, Data Engineer, FAANG roles
✔ Tip: Start with Easy → filter by “Database” tag
✔ Popular Section: Database → Top 50 SQL Questions
Example Problem: “Find duplicate emails in a user table” → Practice filtering, GROUP BY, HAVING
2️⃣ HackerRank – Structured & Beginner-Friendly
• Focus: Step-by-step SQL track
• Has certification tests (SQL Basic, Intermediate)
• Problem sets by topic: SELECT, JOINs, Aggregations, etc.
✔ Tip: Follow the full SQL track
✔ Bonus: Company-specific challenges
Try: “Revising Aggregations – The Count Function” → Build confidence with small wins
3️⃣ Mode Analytics – Real-World SQL in Business Context
• Focus: Business intelligence + SQL
• Uses real-world datasets (e.g., e-commerce, finance)
• Has an in-browser SQL editor with live data
✔ Best for: Practicing dashboard-level queries
✔ Tip: Try the SQL case studies & tutorials
4️⃣ StrataScratch – Interview Questions from Real Companies
• 500+ problems from companies like Uber, Netflix, Google
• Split by company, difficulty, and topic
✔ Best for: Intermediate to advanced level
✔ Tip: Try “Hard” questions after doing 30–50 easy/medium
5️⃣ DataLemur – Short, Practical SQL Problems
• Crisp and to the point
• Good UI, fast learning
• Real interview-style logic
✔ Use when: You want fast, smart SQL drills
📌 How to Practice Effectively:
• Spend 20–30 mins/day
• Focus on JOINs, GROUP BY, HAVING, Subqueries
• Analyze problem → write → debug → re-write
• After solving, explain your logic out loud
🧪 Practice Task:
Try solving 5 SQL questions from LeetCode or HackerRank this week. Start with SELECT, WHERE, and GROUP BY.
💬 Tap ❤️ for more!
❤7
✅ Data Analytics Roadmap for Freshers in 2025 🚀📊
1️⃣ Understand What a Data Analyst Does
🔍 Analyze data, find insights, create dashboards, support business decisions.
2️⃣ Start with Excel
📈 Learn:
– Basic formulas
– Charts & Pivot Tables
– Data cleaning
💡 Excel is still the #1 tool in many companies.
3️⃣ Learn SQL
🧩 SQL helps you pull and analyze data from databases.
Start with:
– SELECT, WHERE, JOIN, GROUP BY
🛠️ Practice on platforms like W3Schools or Mode Analytics.
4️⃣ Pick a Programming Language
🐍 Start with Python (easier) or R
– Learn pandas, matplotlib, numpy
– Do small projects (e.g. analyze sales data)
5️⃣ Data Visualization Tools
📊 Learn:
– Power BI or Tableau
– Build simple dashboards
💡 Start with free versions or YouTube tutorials.
6️⃣ Practice with Real Data
🔍 Use sites like Kaggle or Data.gov
– Clean, analyze, visualize
– Try small case studies (sales report, customer trends)
7️⃣ Create a Portfolio
💻 Share projects on:
– GitHub
– Notion or a simple website
📌 Add visuals + brief explanations of your insights.
8️⃣ Improve Soft Skills
🗣️ Focus on:
– Presenting data in simple words
– Asking good questions
– Thinking critically about patterns
9️⃣ Certifications to Stand Out
🎓 Try:
– Google Data Analytics (Coursera)
– IBM Data Analyst
– LinkedIn Learning basics
🔟 Apply for Internships & Entry Jobs
🎯 Titles to look for:
– Data Analyst (Intern)
– Junior Analyst
– Business Analyst
💬 React ❤️ for more!
1️⃣ Understand What a Data Analyst Does
🔍 Analyze data, find insights, create dashboards, support business decisions.
2️⃣ Start with Excel
📈 Learn:
– Basic formulas
– Charts & Pivot Tables
– Data cleaning
💡 Excel is still the #1 tool in many companies.
3️⃣ Learn SQL
🧩 SQL helps you pull and analyze data from databases.
Start with:
– SELECT, WHERE, JOIN, GROUP BY
🛠️ Practice on platforms like W3Schools or Mode Analytics.
4️⃣ Pick a Programming Language
🐍 Start with Python (easier) or R
– Learn pandas, matplotlib, numpy
– Do small projects (e.g. analyze sales data)
5️⃣ Data Visualization Tools
📊 Learn:
– Power BI or Tableau
– Build simple dashboards
💡 Start with free versions or YouTube tutorials.
6️⃣ Practice with Real Data
🔍 Use sites like Kaggle or Data.gov
– Clean, analyze, visualize
– Try small case studies (sales report, customer trends)
7️⃣ Create a Portfolio
💻 Share projects on:
– GitHub
– Notion or a simple website
📌 Add visuals + brief explanations of your insights.
8️⃣ Improve Soft Skills
🗣️ Focus on:
– Presenting data in simple words
– Asking good questions
– Thinking critically about patterns
9️⃣ Certifications to Stand Out
🎓 Try:
– Google Data Analytics (Coursera)
– IBM Data Analyst
– LinkedIn Learning basics
🔟 Apply for Internships & Entry Jobs
🎯 Titles to look for:
– Data Analyst (Intern)
– Junior Analyst
– Business Analyst
💬 React ❤️ for more!
❤8
𝐏𝐚𝐲 𝐀𝐟𝐭𝐞𝐫 𝐏𝐥𝐚𝐜𝐞𝐦𝐞𝐧𝐭 - 𝐆𝐞𝐭 𝐏𝐥𝐚𝐜𝐞𝐝 𝐈𝐧 𝐓𝐨𝐩 𝐌𝐍𝐂'𝐬 😍
Learn Coding From Scratch - Lectures Taught By IIT Alumni
60+ Hiring Drives Every Month
𝐇𝐢𝐠𝐡𝐥𝐢𝐠𝐡𝐭𝐬:-
🌟 Trusted by 7500+ Students
🤝 500+ Hiring Partners
💼 Avg. Rs. 7.4 LPA
🚀 41 LPA Highest Package
Eligibility: BTech / BCA / BSc / MCA / MSc
𝐑𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐍𝐨𝐰👇 :-
https://pdlink.in/4hO7rWY
Hurry, limited seats available!
Learn Coding From Scratch - Lectures Taught By IIT Alumni
60+ Hiring Drives Every Month
𝐇𝐢𝐠𝐡𝐥𝐢𝐠𝐡𝐭𝐬:-
🌟 Trusted by 7500+ Students
🤝 500+ Hiring Partners
💼 Avg. Rs. 7.4 LPA
🚀 41 LPA Highest Package
Eligibility: BTech / BCA / BSc / MCA / MSc
𝐑𝐞𝐠𝐢𝐬𝐭𝐞𝐫 𝐍𝐨𝐰👇 :-
https://pdlink.in/4hO7rWY
Hurry, limited seats available!
✅ How to Build a Job-Ready Data Analytics Portfolio 💼📊
1️⃣ Pick Solid Datasets
• Public: Kaggle, UCI ML Repo, data.gov
• Business-like: e-commerce, churn, marketing spend, HR attrition
• Size: 5k–200k rows, relatively clean
2️⃣ Create 3 Signature Projects
• SQL: Customer Cohort & Retention (joins, window functions)
• BI: Executive Sales Dashboard (Power BI/Tableau, drill-through, DAX/calculated fields)
• Python: Marketing ROI & Attribution (pandas, seaborn, A/B test basics)
3️⃣ Tell a Story, Not Just Charts
• Problem → Approach → Insight → Action
• Add one business recommendation per insight
4️⃣ Document Like a Pro
• README: problem, data source, methods, results, next steps
• Screenshots or GIFs of dashboards
• Repo structure: /data, /notebooks, /sql, /reports
5️⃣ Show Measurable Impact
• “Reduced reporting time by 70% with automated Power BI pipeline”
• “Identified 12% churn segment with a retention playbook”
6️⃣ Make It Easy to Review
• Share live dashboards (Publish to Web), short Loom/YouTube walkthrough
• Include SQL snippets
• Pin top 3 projects on GitHub and LinkedIn Featured
7️⃣ Iterate With Feedback
• Post drafts on LinkedIn, ask “What would you improve?”
• Apply suggestions, track updates in a CHANGELOG
🎯 Goal: 3 projects, 3 stories, 3 measurable outcomes.
💬 Double Tap ❤️ For More!
1️⃣ Pick Solid Datasets
• Public: Kaggle, UCI ML Repo, data.gov
• Business-like: e-commerce, churn, marketing spend, HR attrition
• Size: 5k–200k rows, relatively clean
2️⃣ Create 3 Signature Projects
• SQL: Customer Cohort & Retention (joins, window functions)
• BI: Executive Sales Dashboard (Power BI/Tableau, drill-through, DAX/calculated fields)
• Python: Marketing ROI & Attribution (pandas, seaborn, A/B test basics)
3️⃣ Tell a Story, Not Just Charts
• Problem → Approach → Insight → Action
• Add one business recommendation per insight
4️⃣ Document Like a Pro
• README: problem, data source, methods, results, next steps
• Screenshots or GIFs of dashboards
• Repo structure: /data, /notebooks, /sql, /reports
5️⃣ Show Measurable Impact
• “Reduced reporting time by 70% with automated Power BI pipeline”
• “Identified 12% churn segment with a retention playbook”
6️⃣ Make It Easy to Review
• Share live dashboards (Publish to Web), short Loom/YouTube walkthrough
• Include SQL snippets
• Pin top 3 projects on GitHub and LinkedIn Featured
7️⃣ Iterate With Feedback
• Post drafts on LinkedIn, ask “What would you improve?”
• Apply suggestions, track updates in a CHANGELOG
🎯 Goal: 3 projects, 3 stories, 3 measurable outcomes.
💬 Double Tap ❤️ For More!
❤3
Core SQL Interview Questions. With answers
1 What is SQL
• SQL stands for Structured Query Language
• You use it to read and manage data in relational databases
• Used in MySQL, PostgreSQL, SQL Server, Oracle
2 What is an RDBMS
• Relational Database Management System
• Stores data in tables with rows and columns
• Uses keys to link tables
• Example. Customer table linked to Orders table using customer_id
3 What is a table
• Structured storage for data
• Rows are records
• Columns are attributes
• Example. One row equals one customer
4 What is a primary key
• Uniquely identifies each row
• Cannot be NULL
• No duplicate values
• Example. user_id in users table
5 What is a foreign key
• Links one table to another
• Refers to a primary key in another table
• Allows duplicate values
• Example. user_id in orders table
6 Difference between primary key and foreign key
• Primary key ensures uniqueness
• Foreign key ensures relationship
• One table can have one primary key
• One table can have multiple foreign keys
7 What is NULL
• Represents missing or unknown value
• Not equal to zero or empty string
• Use IS NULL or IS NOT NULL to check
8 What are constraints
• Rules applied on columns
• Maintain data quality
• Common constraints
– NOT NULL
– UNIQUE
– PRIMARY KEY
– FOREIGN KEY
– CHECK
9 What are data types
• Define type of data stored
• Common types
– INT for numbers
– VARCHAR for text
– DATE for dates
– FLOAT or DECIMAL for decimals
10 Interview tip you must remember
• Always explain with a small example
• Speak logic before syntax
• Keep answers short and direct
Double Tap ❤️ For More
1 What is SQL
• SQL stands for Structured Query Language
• You use it to read and manage data in relational databases
• Used in MySQL, PostgreSQL, SQL Server, Oracle
2 What is an RDBMS
• Relational Database Management System
• Stores data in tables with rows and columns
• Uses keys to link tables
• Example. Customer table linked to Orders table using customer_id
3 What is a table
• Structured storage for data
• Rows are records
• Columns are attributes
• Example. One row equals one customer
4 What is a primary key
• Uniquely identifies each row
• Cannot be NULL
• No duplicate values
• Example. user_id in users table
5 What is a foreign key
• Links one table to another
• Refers to a primary key in another table
• Allows duplicate values
• Example. user_id in orders table
6 Difference between primary key and foreign key
• Primary key ensures uniqueness
• Foreign key ensures relationship
• One table can have one primary key
• One table can have multiple foreign keys
7 What is NULL
• Represents missing or unknown value
• Not equal to zero or empty string
• Use IS NULL or IS NOT NULL to check
8 What are constraints
• Rules applied on columns
• Maintain data quality
• Common constraints
– NOT NULL
– UNIQUE
– PRIMARY KEY
– FOREIGN KEY
– CHECK
9 What are data types
• Define type of data stored
• Common types
– INT for numbers
– VARCHAR for text
– DATE for dates
– FLOAT or DECIMAL for decimals
10 Interview tip you must remember
• Always explain with a small example
• Speak logic before syntax
• Keep answers short and direct
Double Tap ❤️ For More
❤11
𝗕𝗲𝗰𝗼𝗺𝗲 𝗮 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗲𝗱 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘀𝘁 𝗜𝗻 𝗧𝗼𝗽 𝗠𝗡𝗖𝘀😍
Learn Data Analytics, Data Science & AI From Top Data Experts
𝗛𝗶𝗴𝗵𝗹𝗶𝗴𝗵𝘁𝗲𝘀:-
- 12.65 Lakhs Highest Salary
- 500+ Partner Companies
- 100% Job Assistance
- 5.7 LPA Average Salary
𝗕𝗼𝗼𝗸 𝗮 𝗙𝗥𝗘𝗘 𝗗𝗲𝗺𝗼👇:-
𝗢𝗻𝗹𝗶𝗻𝗲:- https://pdlink.in/4fdWxJB
🔹 Hyderabad :- https://pdlink.in/4kFhjn3
🔹 Pune:- https://pdlink.in/45p4GrC
🔹 Noida :- https://linkpd.in/DaNoida
( Hurry Up 🏃♂️Limited Slots )
Learn Data Analytics, Data Science & AI From Top Data Experts
𝗛𝗶𝗴𝗵𝗹𝗶𝗴𝗵𝘁𝗲𝘀:-
- 12.65 Lakhs Highest Salary
- 500+ Partner Companies
- 100% Job Assistance
- 5.7 LPA Average Salary
𝗕𝗼𝗼𝗸 𝗮 𝗙𝗥𝗘𝗘 𝗗𝗲𝗺𝗼👇:-
𝗢𝗻𝗹𝗶𝗻𝗲:- https://pdlink.in/4fdWxJB
🔹 Hyderabad :- https://pdlink.in/4kFhjn3
🔹 Pune:- https://pdlink.in/45p4GrC
🔹 Noida :- https://linkpd.in/DaNoida
( Hurry Up 🏃♂️Limited Slots )
❤2
When preparing for an SQL project-based interview, the focus typically shifts from theoretical knowledge to practical application. Here are some SQL project-based interview questions that could help assess your problem-solving skills and experience:
1. Database Design and Schema
- Question: Describe a database schema you have designed in a past project. What were the key entities, and how did you establish relationships between them?
- Follow-Up: How did you handle normalization? Did you denormalize any tables for performance reasons?
2. Data Modeling
- Question: How would you model a database for an e-commerce application? What tables would you include, and how would they relate to each other?
- Follow-Up: How would you design the schema to handle scenarios like discount codes, product reviews, and inventory management?
3. Query Optimization
- Question: Can you discuss a time when you optimized an SQL query? What was the original query, and what changes did you make to improve its performance?
- Follow-Up: What tools or techniques did you use to identify and resolve the performance issues?
4. ETL Processes
- Question: Describe an ETL (Extract, Transform, Load) process you have implemented. How did you handle data extraction, transformation, and loading?
- Follow-Up: How did you ensure data quality and consistency during the ETL process?
5. Handling Large Datasets
- Question: In a project where you dealt with large datasets, how did you manage performance and storage issues?
- Follow-Up: What indexing strategies or partitioning techniques did you use?
6. Joins and Subqueries
- Question: Provide an example of a complex query you wrote involving multiple joins and subqueries. What was the business problem you were solving?
- Follow-Up: How did you ensure that the query performed efficiently?
7. Stored Procedures and Functions
- Question: Have you created stored procedures or functions in any of your projects? Can you describe one and explain why you chose to encapsulate the logic in a stored procedure?
- Follow-Up: How did you handle error handling and logging within the stored procedure?
8. Data Integrity and Constraints
- Question: How did you enforce data integrity in your SQL projects? Can you give examples of constraints (e.g., primary keys, foreign keys, unique constraints) you implemented?
- Follow-Up: How did you handle situations where constraints needed to be temporarily disabled or modified?
9. Version Control and Collaboration
- Question: How did you manage database version control in your projects? What tools or practices did you use to ensure collaboration with other developers?
- Follow-Up: How did you handle conflicts or issues arising from multiple developers working on the same database?
10. Data Migration
- Question: Describe a data migration project you worked on. How did you ensure that the migration was successful, and what steps did you take to handle data inconsistencies or errors?
- Follow-Up: How did you test the migration process before moving to the production environment?
11. Security and Permissions
- Question: In your SQL projects, how did you manage database security?
- Follow-Up: How did you handle encryption or sensitive data within the database?
12. Handling Unstructured Data
- Question: Have you worked with unstructured or semi-structured data in an SQL environment?
- Follow-Up: What challenges did you face, and how did you overcome them?
13. Real-Time Data Processing
- Question: Can you describe a project where you handled real-time data processing using SQL? What were the key challenges, and how did you address them?
- Follow-Up: How did you ensure the performance and reliability of the real-time data processing system?
Be prepared to discuss specific examples from your past work and explain your thought process in detail.
Here you can find SQL Interview Resources👇
https://news.1rj.ru/str/DataSimplifier
Share with credits: https://news.1rj.ru/str/sqlspecialist
Hope it helps :)
1. Database Design and Schema
- Question: Describe a database schema you have designed in a past project. What were the key entities, and how did you establish relationships between them?
- Follow-Up: How did you handle normalization? Did you denormalize any tables for performance reasons?
2. Data Modeling
- Question: How would you model a database for an e-commerce application? What tables would you include, and how would they relate to each other?
- Follow-Up: How would you design the schema to handle scenarios like discount codes, product reviews, and inventory management?
3. Query Optimization
- Question: Can you discuss a time when you optimized an SQL query? What was the original query, and what changes did you make to improve its performance?
- Follow-Up: What tools or techniques did you use to identify and resolve the performance issues?
4. ETL Processes
- Question: Describe an ETL (Extract, Transform, Load) process you have implemented. How did you handle data extraction, transformation, and loading?
- Follow-Up: How did you ensure data quality and consistency during the ETL process?
5. Handling Large Datasets
- Question: In a project where you dealt with large datasets, how did you manage performance and storage issues?
- Follow-Up: What indexing strategies or partitioning techniques did you use?
6. Joins and Subqueries
- Question: Provide an example of a complex query you wrote involving multiple joins and subqueries. What was the business problem you were solving?
- Follow-Up: How did you ensure that the query performed efficiently?
7. Stored Procedures and Functions
- Question: Have you created stored procedures or functions in any of your projects? Can you describe one and explain why you chose to encapsulate the logic in a stored procedure?
- Follow-Up: How did you handle error handling and logging within the stored procedure?
8. Data Integrity and Constraints
- Question: How did you enforce data integrity in your SQL projects? Can you give examples of constraints (e.g., primary keys, foreign keys, unique constraints) you implemented?
- Follow-Up: How did you handle situations where constraints needed to be temporarily disabled or modified?
9. Version Control and Collaboration
- Question: How did you manage database version control in your projects? What tools or practices did you use to ensure collaboration with other developers?
- Follow-Up: How did you handle conflicts or issues arising from multiple developers working on the same database?
10. Data Migration
- Question: Describe a data migration project you worked on. How did you ensure that the migration was successful, and what steps did you take to handle data inconsistencies or errors?
- Follow-Up: How did you test the migration process before moving to the production environment?
11. Security and Permissions
- Question: In your SQL projects, how did you manage database security?
- Follow-Up: How did you handle encryption or sensitive data within the database?
12. Handling Unstructured Data
- Question: Have you worked with unstructured or semi-structured data in an SQL environment?
- Follow-Up: What challenges did you face, and how did you overcome them?
13. Real-Time Data Processing
- Question: Can you describe a project where you handled real-time data processing using SQL? What were the key challenges, and how did you address them?
- Follow-Up: How did you ensure the performance and reliability of the real-time data processing system?
Be prepared to discuss specific examples from your past work and explain your thought process in detail.
Here you can find SQL Interview Resources👇
https://news.1rj.ru/str/DataSimplifier
Share with credits: https://news.1rj.ru/str/sqlspecialist
Hope it helps :)
❤1
𝗧𝗵𝗲 𝟯 𝗦𝗸𝗶𝗹𝗹𝘀 𝗧𝗵𝗮𝘁 𝗪𝗶𝗹𝗹 𝗠𝗮𝗸𝗲 𝗬𝗼𝘂 𝗨𝗻𝘀𝘁𝗼𝗽𝗽𝗮𝗯𝗹𝗲 𝗶𝗻 𝟮𝟬𝟮𝟲😍
Start learning for FREE and earn a certification that adds real value to your resume.
𝗖𝗹𝗼𝘂𝗱 𝗖𝗼𝗺𝗽𝘂𝘁𝗶𝗻𝗴:- https://pdlink.in/3LoutZd
𝗖𝘆𝗯𝗲𝗿 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆:- https://pdlink.in/3N9VOyW
𝗕𝗶𝗴 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀:- https://pdlink.in/497MMLw
👉 Enroll today & future-proof your career!
Start learning for FREE and earn a certification that adds real value to your resume.
𝗖𝗹𝗼𝘂𝗱 𝗖𝗼𝗺𝗽𝘂𝘁𝗶𝗻𝗴:- https://pdlink.in/3LoutZd
𝗖𝘆𝗯𝗲𝗿 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆:- https://pdlink.in/3N9VOyW
𝗕𝗶𝗴 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀:- https://pdlink.in/497MMLw
👉 Enroll today & future-proof your career!
✅ Basic SQL Queries Interview Questions With Answers 🖥️
1. What does SELECT do
• SELECT fetches data from a table
• You choose columns you want to see
Example: SELECT name, salary FROM employees;
2. What does FROM do
• FROM tells SQL where data lives
• It specifies the table name
Example: SELECT * FROM customers;
3. What is WHERE clause
• WHERE filters rows
• It runs before aggregation
Example: SELECT * FROM orders WHERE status = 'Delivered';
4. Difference between WHERE and HAVING
• WHERE filters rows before GROUP BY
• HAVING filters groups after aggregation
Example: WHERE filters orders, HAVING filters total_sales
5. How do you sort data
• Use ORDER BY
• Default order is ASC
Example: SELECT * FROM employees ORDER BY salary DESC;
6. How do you sort by multiple columns
• SQL sorts left to right
Example: SELECT * FROM students ORDER BY class ASC, marks DESC;
7. What is LIMIT
• LIMIT restricts number of rows returned
• Useful for top N queries
Example: SELECT * FROM products LIMIT 5;
8. What is OFFSET
• OFFSET skips rows
• Used with LIMIT for pagination
Example: SELECT * FROM products LIMIT 5 OFFSET 10;
9. How do you filter on multiple conditions
• Use AND, OR
Example: SELECT * FROM users WHERE city = 'Delhi' AND age > 25;
10. Difference between AND and OR
• AND needs all conditions true
• OR needs one condition true
Quick interview advice
• Always say execution order: FROM → WHERE → SELECT → ORDER BY → LIMIT
• Write clean examples
• Speak logic first, syntax next¹
Double Tap ❤️ For More
1. What does SELECT do
• SELECT fetches data from a table
• You choose columns you want to see
Example: SELECT name, salary FROM employees;
2. What does FROM do
• FROM tells SQL where data lives
• It specifies the table name
Example: SELECT * FROM customers;
3. What is WHERE clause
• WHERE filters rows
• It runs before aggregation
Example: SELECT * FROM orders WHERE status = 'Delivered';
4. Difference between WHERE and HAVING
• WHERE filters rows before GROUP BY
• HAVING filters groups after aggregation
Example: WHERE filters orders, HAVING filters total_sales
5. How do you sort data
• Use ORDER BY
• Default order is ASC
Example: SELECT * FROM employees ORDER BY salary DESC;
6. How do you sort by multiple columns
• SQL sorts left to right
Example: SELECT * FROM students ORDER BY class ASC, marks DESC;
7. What is LIMIT
• LIMIT restricts number of rows returned
• Useful for top N queries
Example: SELECT * FROM products LIMIT 5;
8. What is OFFSET
• OFFSET skips rows
• Used with LIMIT for pagination
Example: SELECT * FROM products LIMIT 5 OFFSET 10;
9. How do you filter on multiple conditions
• Use AND, OR
Example: SELECT * FROM users WHERE city = 'Delhi' AND age > 25;
10. Difference between AND and OR
• AND needs all conditions true
• OR needs one condition true
Quick interview advice
• Always say execution order: FROM → WHERE → SELECT → ORDER BY → LIMIT
• Write clean examples
• Speak logic first, syntax next¹
Double Tap ❤️ For More
❤5
✅ SQL Joins Interview Questions With Answers 🖥️
1. What is a JOIN in SQL. Explain with an example.
• JOIN combines data from multiple tables
• Tables connect using a common column
• Usually primary key to foreign key
Example tables
Customers
customer_id, name
Orders
order_id, customer_id, amount
Query
SELECT c.name, o.amount
FROM customers c
INNER JOIN orders o
ON c.customer_id = o.customer_id;
Explanation
• SQL matches customer_id in both tables
• Output shows only related customer order data
2. What is INNER JOIN. When do you use it.
• INNER JOIN returns only matching rows
• Rows without match are removed
Example
Find customers who placed orders
Query
SELECT c.customer_id, c.name
FROM customers c
INNER JOIN orders o
ON c.customer_id = o.customer_id;
Logic
• Customers without orders are excluded
• Only matched records appear
3. What is LEFT JOIN. Explain with use case.
• LEFT JOIN returns all rows from left table
• Matching rows from right table
• Non matches show NULL
Example
Find all customers and their orders
Query
SELECT c.name, o.order_id
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id;
Logic
• Customers without orders still appear
• order_id becomes NULL
4. Difference between INNER JOIN and LEFT JOIN.
• INNER JOIN removes non matching rows
• LEFT JOIN keeps all left table rows
• LEFT JOIN shows NULL for missing matches
Interview tip
Explain using one missing record example
5. What is RIGHT JOIN.
• Returns all rows from right table
• Matching rows from left table
• Rarely used in real projects
Example
SELECT c.name, o.order_id
FROM customers c
RIGHT JOIN orders o
ON c.customer_id = o.customer_id;
6. What is FULL OUTER JOIN.
• Returns all rows from both tables
• Matches where possible
• Non matches show NULL
Example
SELECT c.name, o.order_id
FROM customers c
FULL OUTER JOIN orders o
ON c.customer_id = o.customer_id;
Use case
• Data reconciliation
• Comparing two datasets
7. How do you find records present in one table but not in another.
Find customers with no orders
Query
SELECT c.customer_id, c.name
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
Logic
• LEFT JOIN keeps all customers
• WHERE filters non matched rows
8. Explain JOIN with WHERE clause. Common mistake.
• WHERE runs after JOIN
• Wrong WHERE condition breaks LEFT JOIN
Wrong
LEFT JOIN orders
WHERE orders.amount > 1000
Correct
LEFT JOIN orders
ON (link unavailable) = (link unavailable)
AND orders.amount > 1000
9. How do you join more than two tables.
• JOIN step by step
• Each JOIN needs condition
Example
SELECT c.name, o.order_id, p.product_name
FROM customers c
JOIN orders o
ON c.customer_id = o.customer_id
JOIN products p
ON o.product_id = p.product_id;
10. SQL execution order for JOIN queries.
• FROM
• JOIN
• WHERE
• GROUP BY
• HAVING
• SELECT
• ORDER BY
Interview advice
• Always explain logic first
• Draw table flow in words
• Then write query
Double Tap ♥️ For More
1. What is a JOIN in SQL. Explain with an example.
• JOIN combines data from multiple tables
• Tables connect using a common column
• Usually primary key to foreign key
Example tables
Customers
customer_id, name
Orders
order_id, customer_id, amount
Query
SELECT c.name, o.amount
FROM customers c
INNER JOIN orders o
ON c.customer_id = o.customer_id;
Explanation
• SQL matches customer_id in both tables
• Output shows only related customer order data
2. What is INNER JOIN. When do you use it.
• INNER JOIN returns only matching rows
• Rows without match are removed
Example
Find customers who placed orders
Query
SELECT c.customer_id, c.name
FROM customers c
INNER JOIN orders o
ON c.customer_id = o.customer_id;
Logic
• Customers without orders are excluded
• Only matched records appear
3. What is LEFT JOIN. Explain with use case.
• LEFT JOIN returns all rows from left table
• Matching rows from right table
• Non matches show NULL
Example
Find all customers and their orders
Query
SELECT c.name, o.order_id
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id;
Logic
• Customers without orders still appear
• order_id becomes NULL
4. Difference between INNER JOIN and LEFT JOIN.
• INNER JOIN removes non matching rows
• LEFT JOIN keeps all left table rows
• LEFT JOIN shows NULL for missing matches
Interview tip
Explain using one missing record example
5. What is RIGHT JOIN.
• Returns all rows from right table
• Matching rows from left table
• Rarely used in real projects
Example
SELECT c.name, o.order_id
FROM customers c
RIGHT JOIN orders o
ON c.customer_id = o.customer_id;
6. What is FULL OUTER JOIN.
• Returns all rows from both tables
• Matches where possible
• Non matches show NULL
Example
SELECT c.name, o.order_id
FROM customers c
FULL OUTER JOIN orders o
ON c.customer_id = o.customer_id;
Use case
• Data reconciliation
• Comparing two datasets
7. How do you find records present in one table but not in another.
Find customers with no orders
Query
SELECT c.customer_id, c.name
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
Logic
• LEFT JOIN keeps all customers
• WHERE filters non matched rows
8. Explain JOIN with WHERE clause. Common mistake.
• WHERE runs after JOIN
• Wrong WHERE condition breaks LEFT JOIN
Wrong
LEFT JOIN orders
WHERE orders.amount > 1000
Correct
LEFT JOIN orders
ON (link unavailable) = (link unavailable)
AND orders.amount > 1000
9. How do you join more than two tables.
• JOIN step by step
• Each JOIN needs condition
Example
SELECT c.name, o.order_id, p.product_name
FROM customers c
JOIN orders o
ON c.customer_id = o.customer_id
JOIN products p
ON o.product_id = p.product_id;
10. SQL execution order for JOIN queries.
• FROM
• JOIN
• WHERE
• GROUP BY
• HAVING
• SELECT
• ORDER BY
Interview advice
• Always explain logic first
• Draw table flow in words
• Then write query
Double Tap ♥️ For More
❤9
✅ SQL GROUP BY and AGGREGATION Interview Questions 🎓
1. What is GROUP BY in SQL.
• GROUP BY groups rows with same values
• Used with aggregate functions
• One row per group in output
Example
Find total salary per department
Logic
• Rows grouped by department
• SUM runs on each group
2. Why do we use aggregate functions.
• To summarize data
• To calculate totals, averages, counts
Common functions
• COUNT
• SUM
• AVG
• MIN
• MAX
3. What happens if you use GROUP BY without aggregation.
• Output shows unique combinations of grouped columns
Example
Logic
• Acts like DISTINCT
4. Difference between WHERE and HAVING.
• WHERE filters rows
• HAVING filters groups
• WHERE runs before GROUP BY
• HAVING runs after GROUP BY
Example
Find departments with total salary above 5,00,000
5. Can you use WHERE with GROUP BY.
• Yes
• WHERE filters raw data before grouping
Example
Ignore inactive employees
6. Common GROUP BY interview error.
Why does this query fail
Answer
• Non aggregated column must be in GROUP BY
• name is missing
Correct query
7. What's the difference between COUNT(*) COUNT(column)?
• COUNT(*) counts all rows
• COUNT(column) skips NULL values
Example
8. Find total orders per customer.
Logic
• One row per customer
• COUNT runs per customer group
9. Find customers with more than 5 orders.
Logic
• GROUP first
• Filter groups using HAVING
10. Execution order for GROUP BY queries.
• FROM
• WHERE
• GROUP BY
• HAVING
• SELECT
• ORDER BY
Interview advice
• Say execution order clearly
• Explain using one simple example
• Avoid mixing WHERE and HAVING logic
Double Tap ♥️ For More
1. What is GROUP BY in SQL.
• GROUP BY groups rows with same values
• Used with aggregate functions
• One row per group in output
Example
Find total salary per department
FROM employees
GROUP BY department;
Logic
• Rows grouped by department
• SUM runs on each group
2. Why do we use aggregate functions.
• To summarize data
• To calculate totals, averages, counts
Common functions
• COUNT
• SUM
• AVG
• MIN
• MAX
3. What happens if you use GROUP BY without aggregation.
• Output shows unique combinations of grouped columns
Example
FROM employees
GROUP BY department;
Logic
• Acts like DISTINCT
4. Difference between WHERE and HAVING.
• WHERE filters rows
• HAVING filters groups
• WHERE runs before GROUP BY
• HAVING runs after GROUP BY
Example
Find departments with total salary above 5,00,000
FROM employees
GROUP BY department
HAVING SUM(salary) > 500000;
5. Can you use WHERE with GROUP BY.
• Yes
• WHERE filters raw data before grouping
Example
Ignore inactive employees
FROM employees
WHERE status = 'Active'
GROUP BY department;
6. Common GROUP BY interview error.
Why does this query fail
FROM employees
GROUP BY department;
Answer
• Non aggregated column must be in GROUP BY
• name is missing
Correct query
FROM employees
GROUP BY department;
7. What's the difference between COUNT(*) COUNT(column)?
• COUNT(*) counts all rows
• COUNT(column) skips NULL values
Example
SELECT COUNT(delivery_date) FROM orders;
8. Find total orders per customer.
FROM orders
GROUP BY customer_id;
Logic
• One row per customer
• COUNT runs per customer group
9. Find customers with more than 5 orders.
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 5;
Logic
• GROUP first
• Filter groups using HAVING
10. Execution order for GROUP BY queries.
• FROM
• WHERE
• GROUP BY
• HAVING
• SELECT
• ORDER BY
Interview advice
• Say execution order clearly
• Explain using one simple example
• Avoid mixing WHERE and HAVING logic
Double Tap ♥️ For More
❤7
𝗙𝘂𝗹𝗹𝘀𝘁𝗮𝗰𝗸 𝗗𝗲𝘃𝗲𝗹𝗼𝗽𝗺𝗲𝗻𝘁 𝗵𝗶𝗴𝗵-𝗱𝗲𝗺𝗮𝗻𝗱 𝘀𝗸𝗶𝗹𝗹 𝗜𝗻 𝟮𝟬𝟮𝟲😍
Join FREE Masterclass In Hyderabad/Pune/Noida Cities
𝗛𝗶𝗴𝗵𝗹𝗶𝗴𝗵𝘁𝗲𝘀:-
- 500+ Hiring Partners
- 60+ Hiring Drives
- 100% Placement Assistance
𝗕𝗼𝗼𝗸 𝗮 𝗙𝗥𝗘𝗘 𝗱𝗲𝗺𝗼👇:-
🔹 Hyderabad :- https://pdlink.in/4cJUWtx
🔹 Pune :- https://pdlink.in/3YA32zi
🔹 Noida :- https://linkpd.in/NoidaFSD
Hurry Up 🏃♂️! Limited seats are available
Join FREE Masterclass In Hyderabad/Pune/Noida Cities
𝗛𝗶𝗴𝗵𝗹𝗶𝗴𝗵𝘁𝗲𝘀:-
- 500+ Hiring Partners
- 60+ Hiring Drives
- 100% Placement Assistance
𝗕𝗼𝗼𝗸 𝗮 𝗙𝗥𝗘𝗘 𝗱𝗲𝗺𝗼👇:-
🔹 Hyderabad :- https://pdlink.in/4cJUWtx
🔹 Pune :- https://pdlink.in/3YA32zi
🔹 Noida :- https://linkpd.in/NoidaFSD
Hurry Up 🏃♂️! Limited seats are available
❤3
✅ SQL Window Functions Interview Questions with Answers ✍️
1. What are window functions in SQL?
• Window functions perform calculations across related rows
• They do not reduce rows
• Each row keeps its detail
Key syntax: OVER (PARTITION BY, ORDER BY)
2. Difference between GROUP BY and window functions
• GROUP BY collapses rows
• Window functions keep all rows
• Window functions add calculated columns
3. What is ROW_NUMBER?
• Assigns unique sequential number
• No ties allowed
Example: Rank employees by salary
SELECT name, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn
FROM employees;
4. Difference between ROW_NUMBER, RANK, and DENSE_RANK
• ROW_NUMBER gives unique numbers
• RANK skips numbers on ties
• DENSE_RANK does not skip
Example salaries: 100, 100, 90
ROW_NUMBER → 1, 2, 3
RANK → 1, 1, 3
DENSE_RANK → 1, 1, 2
5. What is PARTITION BY?
• PARTITION BY splits data into groups
• Window function runs inside each group
Example: Rank employees per department
SELECT department, name, salary,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rank
FROM employees;
6. Find top 2 salaries per department
SELECT * FROM (
SELECT department, name, salary,
DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk
FROM employees
) t
WHERE rnk <= 2;
7. What is LAG?
• Accesses previous row value
• Used for comparisons
Example: Day over day sales
SELECT date, sales, LAG(sales) OVER (ORDER BY date) AS prev_day_sales
FROM daily_sales;
8. What is LEAD?
• Accesses next row value
Example: Compare today with next day
SELECT date, sales, LEAD(sales) OVER (ORDER BY date) AS next_day_sales
FROM daily_sales;
9. Calculate day over day growth
SELECT date, sales - LAG(sales) OVER (ORDER BY date) AS growth
FROM daily_sales;
10. Common window function interview mistakes
• Forgetting ORDER BY inside OVER
• Using WHERE instead of subquery to filter ranks
• Mixing GROUP BY with window logic incorrectly
Execution order: FROM → WHERE → GROUP BY → HAVING → SELECT → WINDOW → ORDER BY
Double Tap ♥️ For More
1. What are window functions in SQL?
• Window functions perform calculations across related rows
• They do not reduce rows
• Each row keeps its detail
Key syntax: OVER (PARTITION BY, ORDER BY)
2. Difference between GROUP BY and window functions
• GROUP BY collapses rows
• Window functions keep all rows
• Window functions add calculated columns
3. What is ROW_NUMBER?
• Assigns unique sequential number
• No ties allowed
Example: Rank employees by salary
SELECT name, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn
FROM employees;
4. Difference between ROW_NUMBER, RANK, and DENSE_RANK
• ROW_NUMBER gives unique numbers
• RANK skips numbers on ties
• DENSE_RANK does not skip
Example salaries: 100, 100, 90
ROW_NUMBER → 1, 2, 3
RANK → 1, 1, 3
DENSE_RANK → 1, 1, 2
5. What is PARTITION BY?
• PARTITION BY splits data into groups
• Window function runs inside each group
Example: Rank employees per department
SELECT department, name, salary,
RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS dept_rank
FROM employees;
6. Find top 2 salaries per department
SELECT * FROM (
SELECT department, name, salary,
DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk
FROM employees
) t
WHERE rnk <= 2;
7. What is LAG?
• Accesses previous row value
• Used for comparisons
Example: Day over day sales
SELECT date, sales, LAG(sales) OVER (ORDER BY date) AS prev_day_sales
FROM daily_sales;
8. What is LEAD?
• Accesses next row value
Example: Compare today with next day
SELECT date, sales, LEAD(sales) OVER (ORDER BY date) AS next_day_sales
FROM daily_sales;
9. Calculate day over day growth
SELECT date, sales - LAG(sales) OVER (ORDER BY date) AS growth
FROM daily_sales;
10. Common window function interview mistakes
• Forgetting ORDER BY inside OVER
• Using WHERE instead of subquery to filter ranks
• Mixing GROUP BY with window logic incorrectly
Execution order: FROM → WHERE → GROUP BY → HAVING → SELECT → WINDOW → ORDER BY
Double Tap ♥️ For More
❤4👍2
💡 𝗠𝗮𝗰𝗵𝗶𝗻𝗲 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗶𝘀 𝗼𝗻𝗲 𝗼𝗳 𝘁𝗵𝗲 𝗺𝗼𝘀𝘁 𝗶𝗻-𝗱𝗲𝗺𝗮𝗻𝗱 𝘀𝗸𝗶𝗹𝗹𝘀 𝗶𝗻 𝟮𝟬𝟮𝟲!
Start learning ML for FREE and boost your resume with a certification 🏆
📊 Hands-on learning
🎓 Certificate included
🚀 Career-ready skills
🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘 👇:-
https://pdlink.in/4bhetTu
👉 Don’t miss this opportunity
Start learning ML for FREE and boost your resume with a certification 🏆
📊 Hands-on learning
🎓 Certificate included
🚀 Career-ready skills
🔗 𝗘𝗻𝗿𝗼𝗹𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘 👇:-
https://pdlink.in/4bhetTu
👉 Don’t miss this opportunity
❤1
📈 Want to Excel at Data Analytics? Master These Essential Skills! ☑️
Core Concepts:
• Statistics & Probability – Understand distributions, hypothesis testing
• Excel – Pivot tables, formulas, dashboards
Programming:
• Python – NumPy, Pandas, Matplotlib, Seaborn
• R – Data analysis & visualization
• SQL – Joins, filtering, aggregation
Data Cleaning & Wrangling:
• Handle missing values, duplicates
• Normalize and transform data
Visualization:
• Power BI, Tableau – Dashboards
• Plotly, Seaborn – Python visualizations
• Data Storytelling – Present insights clearly
Advanced Analytics:
• Regression, Classification, Clustering
• Time Series Forecasting
• A/B Testing & Hypothesis Testing
ETL & Automation:
• Web Scraping – BeautifulSoup, Scrapy
• APIs – Fetch and process real-world data
• Build ETL Pipelines
Tools & Deployment:
• Jupyter Notebook / Colab
• Git & GitHub
• Cloud Platforms – AWS, GCP, Azure
• Google BigQuery, Snowflake
Hope it helps :)
Core Concepts:
• Statistics & Probability – Understand distributions, hypothesis testing
• Excel – Pivot tables, formulas, dashboards
Programming:
• Python – NumPy, Pandas, Matplotlib, Seaborn
• R – Data analysis & visualization
• SQL – Joins, filtering, aggregation
Data Cleaning & Wrangling:
• Handle missing values, duplicates
• Normalize and transform data
Visualization:
• Power BI, Tableau – Dashboards
• Plotly, Seaborn – Python visualizations
• Data Storytelling – Present insights clearly
Advanced Analytics:
• Regression, Classification, Clustering
• Time Series Forecasting
• A/B Testing & Hypothesis Testing
ETL & Automation:
• Web Scraping – BeautifulSoup, Scrapy
• APIs – Fetch and process real-world data
• Build ETL Pipelines
Tools & Deployment:
• Jupyter Notebook / Colab
• Git & GitHub
• Cloud Platforms – AWS, GCP, Azure
• Google BigQuery, Snowflake
Hope it helps :)
❤3
✅ SQL CTEs and Subqueries Interview Questions with Answers 🖥️
1. Find employees who earn more than the average salary.
Table: employees (employee_id, name, salary)
Logic: Inner query calculates average salary. Outer query filters employees above average.
2. Find employees who earn the highest salary in each department.
Table: employees (employee_id, name, department, salary)
Logic: Subquery runs per department. Matches max salary inside same department.
3. Find departments where average salary is greater than 60,000.
Logic: Inner query calculates department average. Outer query filters required departments.
4. Same query using CTE.
Logic: CTE stores aggregated result. Final query reads from CTE.
5. Find customers who placed more orders than the average number of orders.
Tables: customers (customer_id, name), orders (order_id, customer_id)
Logic: Inner query calculates orders per customer. Next level gets average. HAVING filters customers above average.
6. Find top-selling product by total sales amount.
Table: sales (product_id, amount)
Logic: Inner query calculates sales per product. Outer query finds max and matches it.
7. Rewrite using CTE.
Logic: CTE avoids repeating aggregation. Cleaner and readable.
8. Find employees whose salary is greater than their department average.
Logic: First compute department averages. Join back to employees. Filter higher earners.
Double Tap ♥️ For More
1. Find employees who earn more than the average salary.
Table: employees (employee_id, name, salary)
SELECT name, salary
FROM employees
WHERE salary > (
SELECT AVG(salary)
FROM employees
);
Logic: Inner query calculates average salary. Outer query filters employees above average.
2. Find employees who earn the highest salary in each department.
Table: employees (employee_id, name, department, salary)
SELECT name, department, salary
FROM employees e
WHERE salary = (
SELECT MAX(salary)
FROM employees
WHERE department = e.department
);
Logic: Subquery runs per department. Matches max salary inside same department.
3. Find departments where average salary is greater than 60,000.
SELECT department
FROM (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
) t
WHERE avg_salary > 60000;
Logic: Inner query calculates department average. Outer query filters required departments.
4. Same query using CTE.
WITH dept_avg AS (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
)
SELECT department
FROM dept_avg
WHERE avg_salary > 60000;
Logic: CTE stores aggregated result. Final query reads from CTE.
5. Find customers who placed more orders than the average number of orders.
Tables: customers (customer_id, name), orders (order_id, customer_id)
SELECT customer_id
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > (
SELECT AVG(order_count)
FROM (
SELECT COUNT(order_id) AS order_count
FROM orders
GROUP BY customer_id
) x
);
Logic: Inner query calculates orders per customer. Next level gets average. HAVING filters customers above average.
6. Find top-selling product by total sales amount.
Table: sales (product_id, amount)
SELECT product_id
FROM sales
GROUP BY product_id
HAVING SUM(amount) = (
SELECT MAX(total_sales)
FROM (
SELECT SUM(amount) AS total_sales
FROM sales
GROUP BY product_id
) t
);
Logic: Inner query calculates sales per product. Outer query finds max and matches it.
7. Rewrite using CTE.
WITH product_sales AS (
SELECT product_id, SUM(amount) AS total_sales
FROM sales
GROUP BY product_id
)
SELECT product_id
FROM product_sales
WHERE total_sales = (
SELECT MAX(total_sales)
FROM product_sales
);
Logic: CTE avoids repeating aggregation. Cleaner and readable.
8. Find employees whose salary is greater than their department average.
WITH dept_avg AS (
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department
)
SELECT e.name, e.salary
FROM employees e
JOIN dept_avg d ON e.department = d.department
WHERE e.salary > d.avg_salary;
Logic: First compute department averages. Join back to employees. Filter higher earners.
Double Tap ♥️ For More
❤2
✅ SQL CASE Statements and Data Cleaning Interview Questions with Answers 📊
1. Classify customers based on total spend
Table: orders (order_id, customer_id, amount)
Requirement:
- Gold if total_spend >= 100000
- Silver if total_spend between 50000 and 99999
- Bronze otherwise
Solution:
Table: users (user_id, age)
Requirement:
- Below 18
- 18 to 30
- Above 30
Solution:
Table: employees (employee_id, salary)
Solution:
Table: employees (employee_id, email)
Solution:
Table: customers (customer_id, name)
Solution:
Table: products (product_code)
Solution:
Table: orders (order_date)
Requirement: Convert to YYYY-MM-DD
Solution:
Table: users (user_id, last_login_date)
Requirement: Inactive if last login before 2023-01-01
Solution:
Table: customers (phone_number)
Solution:
Table: transactions (amount)
Requirement:
- High if amount >= 10000
- Medium if 5000 to 9999
- Low otherwise
Solution:
1. Classify customers based on total spend
Table: orders (order_id, customer_id, amount)
Requirement:
- Gold if total_spend >= 100000
- Silver if total_spend between 50000 and 99999
- Bronze otherwise
Solution:
SELECT customer_id,2. Create an age group column for users
CASE
WHEN SUM(amount) >= 100000 THEN 'Gold'
WHEN SUM(amount) >= 50000 THEN 'Silver'
ELSE 'Bronze'
END AS customer_category
FROM orders
GROUP BY customer_id;
Table: users (user_id, age)
Requirement:
- Below 18
- 18 to 30
- Above 30
Solution:
SELECT user_id,3. Replace NULL salary with 0
CASE
WHEN age < 18 THEN 'Below 18'
WHEN age BETWEEN 18 AND 30 THEN '18-30'
ELSE 'Above 30'
END AS age_group
FROM users;
Table: employees (employee_id, salary)
Solution:
SELECT employee_id, COALESCE(salary, 0) AS salary4. Count employees with missing email IDs
FROM employees;
Table: employees (employee_id, email)
Solution:
SELECT COUNT(*) AS missing_email_count5. Remove extra spaces from customer names
FROM employees
WHERE email IS NULL;
Table: customers (customer_id, name)
Solution:
SELECT customer_id, TRIM(name) AS clean_name6. Extract first 3 characters from product code
FROM customers;
Table: products (product_code)
Solution:
SELECT product_code, SUBSTRING(product_code, 1, 3) AS product_prefix7. Standardize date format
FROM products;
Table: orders (order_date)
Requirement: Convert to YYYY-MM-DD
Solution:
SELECT CAST(order_date AS DATE) AS clean_order_date8. Mark inactive users based on last login
FROM orders;
Table: users (user_id, last_login_date)
Requirement: Inactive if last login before 2023-01-01
Solution:
SELECT user_id,9. Handle empty string as NULL
CASE
WHEN last_login_date < '2023-01-01' THEN 'Inactive'
ELSE 'Active'
END AS user_status
FROM users;
Table: customers (phone_number)
Solution:
SELECT NULLIF(phone_number, '') AS phone_number10. Create a clean reporting column using multiple rules
FROM customers;
Table: transactions (amount)
Requirement:
- High if amount >= 10000
- Medium if 5000 to 9999
- Low otherwise
Solution:
SELECT amount,Double Tap ♥️ For More
CASE
WHEN amount >= 10000 THEN 'High'
WHEN amount >= 5000 THEN 'Medium'
ELSE 'Low'
END AS transaction_type
FROM transactions;
❤7
𝗙𝗥𝗘𝗘 𝗖𝗮𝗿𝗲𝗲𝗿 𝗖𝗮𝗿𝗻𝗶𝘃𝗮𝗹 𝗯𝘆 𝗛𝗖𝗟 𝗚𝗨𝗩𝗜😍
Prove your skills in an online hackathon, clear tech interviews, and get hired faster
Highlightes:-
- 21+ Hiring Companies & 100+ Open Positions to Grab
- Get hired for roles in AI, Full Stack, & more
Experience the biggest online job fair with Career Carnival by HCL GUVI
𝗥𝗲𝗴𝗶𝘀𝘁𝗲𝗿 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:-
https://pdlink.in/4bQP5Ee
Hurry Up🏃♂️.....Limited Slots Available
Prove your skills in an online hackathon, clear tech interviews, and get hired faster
Highlightes:-
- 21+ Hiring Companies & 100+ Open Positions to Grab
- Get hired for roles in AI, Full Stack, & more
Experience the biggest online job fair with Career Carnival by HCL GUVI
𝗥𝗲𝗴𝗶𝘀𝘁𝗲𝗿 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇:-
https://pdlink.in/4bQP5Ee
Hurry Up🏃♂️.....Limited Slots Available
❤1