Skip to content

shlokGIT/Subqery-AND-window-function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Subqery-AND-window-function

🧠 SQL Practice: Subqueries & Window Functions

This repository contains a comprehensive collection of SQL queries focused on Subqueries and Window Functions, covering Beginner → Advanced level problems.

It is designed for:

  • 📊 Data Analyst Interview Preparation
  • 🏢 MNC SQL Coding Rounds
  • 📚 Concept Mastery (Real-world Scenarios)

🗂️ Database Used

Database Name: parks_and_recreation

Tables:

  1. employee_demographics
  2. employee_salary
  3. park_departments

📊 Topics Covered

🔹 Subqueries

  • Single Row Subqueries
  • Multi-row Subqueries (IN, ANY, ALL)
  • Correlated Subqueries
  • Nested Subqueries
  • EXISTS / NOT EXISTS
  • Aggregate Subqueries

🔹 Window Functions

  • ROW_NUMBER()
  • RANK() vs DENSE_RANK()
  • PARTITION BY
  • LAG() & LEAD()
  • FIRST_VALUE() & LAST_VALUE()
  • NTILE()
  • PERCENT_RANK()
  • Running calculations
  • Trend analysis

🧩 Problem Categories

🟢 Beginner Level

  • Find highest / lowest salary
  • Employees above average salary
  • Second highest salary
  • Department-based filtering

🟡 Intermediate Level

  • Nth highest salary
  • Department-wise max/min salary
  • Correlated subqueries
  • Employee count per department

🔴 Advanced Level

  • Top N salaries (without window functions)
  • Salary comparison using nested subqueries
  • Duplicate detection
  • Complex filtering using EXISTS

🟣 Window Function Use Cases

Ranking

  • Rank employees globally & department-wise

Salary Analysis

  • Compare with department average
  • Difference from average salary

Trend Analysis

  • Salary increase/decrease detection

Advanced Analytics

  • Top N per department
  • Percent contribution of salary
  • Salary buckets using NTILE()

🛠️ Skills Demonstrated

Advanced SQL Query Writing

Analytical Thinking

Real-world Data Analysis

Window Function Mastery

Performance-Oriented Query Design


🎯 Use Cases

Data Analyst Interviews

Business Intelligence Reporting

Salary & HR Analytics

Data Exploration Tasks


📌 Author

Shlok Singh

🎓 B.Tech CSE

💼 Aspiring Data Analyst

🧰 Skills: SQL, Excel, Advanced Excel, Power BI