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

SQL Questions

The document contains a series of advanced SQL questions focusing on topics such as window functions, recursive queries, and performance optimization techniques. It includes specific queries for tasks like finding the second highest salary, calculating rolling averages, and detecting cycles in hierarchical data. Additionally, it provides links to resources for practicing SQL problems and improving skills.

Uploaded by

varunidjayan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

SQL Questions

The document contains a series of advanced SQL questions focusing on topics such as window functions, recursive queries, and performance optimization techniques. It includes specific queries for tasks like finding the second highest salary, calculating rolling averages, and detecting cycles in hierarchical data. Additionally, it provides links to resources for practicing SQL problems and improving skills.

Uploaded by

varunidjayan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL QUESTIONS

Write a query to find the second highest salary in a table without using LIMIT, OFFSET, or subqueries.

Using window functions, how would you retrieve the Nth highest salary from an employee table?

Given an employee’s table with a self-referencing manager column, write a recursive CTE to display the complete
reporting hierarchy for a specific employee.

Write an SQL query to detect cycles in a hierarchical table using recursive techniques.

How would you retrieve the top three orders per customer in a large orders table using window functions?

Write a query to pivot row data into columns using only CASE statements.

Design a query that calculates a 7-day rolling average of sales using window functions.

Write an SQL query to identify missing dates in a continuous date series and fill in those gaps with zero values.

Given a table of user logins with timestamps, write a query to compute the maximum gap between consecutive
logins per user.

Write a query to compute a running total of sales, partitioned by region and ordered by date.

How can you optimize a query that relies on multiple correlated subqueries by rewriting it with joins?

Discuss and demonstrate an indexing strategy that could improve performance on a table with billions of rows.

Write a query using a correlated subquery to compare each product’s sales against the average sales for its category.

Given three tables (customers, orders, products), write a query to compute total revenue per customer and rank
them accordingly.

Using advanced SQL techniques, write a query to generate a cumulative sum of orders for each day.

Write a recursive query to traverse a graph represented by node relationships and list all paths between two given
nodes.

How would you use dynamic SQL to pivot a dataset when the target columns are not known at runtime?

Given a table of order details with timestamps, write a query to compute the time difference between the first and
last order for each customer.

These questions cover advanced SQL concepts like window functions, self-joins, aggregations, string operations,
date/time handling, and recursion.

➤ 𝗦𝗤𝗟

Basics - Riti Kumari


https://lnkd.in/g8x9AmyH

Advanced - Sumit Mittal


https://lnkd.in/dPPpttHg
200+ Problems solved - Ankit Bansal
https://lnkd.in/dWCVfXsA

Best Platforms to practise SQL Problems daily


- Dataford - https://lnkd.in/gtqdw864
- LeetCode - https://lnkd.in/gkCpv7NA
- Namaste SQL - https://lnkd.in/gQTuepVf
- HackerRank - https://lnkd.in/gnFS4frz
- DataLemur - https://datalemur.com/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy