Forum

Top SQL Query Chall...
 
Share:
Notifications
Clear all

Top SQL Query Challenges Asked in Product-Based Companies (Google, Amazon, Flipkart) — 2025 Edition

1 Posts
1 Users
0 Reactions
257 Views
Posts: 134
Admin
Topic starter
(@sql-admin)
Reputable Member
Joined: 6 years ago

Product-based companies like Google, Amazon, and Flipkart test your SQL problem-solving skills using real-world datasets.

Unlike service-based companies, their interviews focus on complex query logic, analytical thinking, and code optimization — not just definitions.

This post covers top SQL query challenges (2025 edition) based on actual interview experiences, along with optimized query solutions you can practice directly in MySQL, PostgreSQL, or SQL Server.


🔹 Top SQL Query Challenges & Solutions (2025 Edition)

1️⃣ Find the 2nd Highest Salary Without Using TOP or LIMIT

Question:
Write a query to get the second-highest salary from an Employee table.

 
SELECT MAX(Salary)
FROM Employees
WHERE Salary < (SELECT MAX(Salary) FROM Employees);

Frequently asked in Amazon & Flipkart SQL coding rounds.


2️⃣ Display Employees With Higher Salary Than Their Manager

Question:
Find employees whose salary is higher than their manager’s.

 
SELECT e.emp_name
FROM Employees e
JOIN Employees m ON e.manager_id = m.emp_id
WHERE e.salary > m.salary;

📌 Tests understanding of self joins and hierarchical data.


3️⃣ Retrieve Top 3 Products by Sales per Category

Question:
Find top 3 best-selling products in each category.

 
SELECT * FROM (
SELECT Category, Product,
SUM(Sales) AS TotalSales,
RANK() OVER(PARTITION BY Category ORDER BY SUM(Sales) DESC) AS rnk
FROM Sales
GROUP BY Category, Product
) t
WHERE rnk <= 3;

Common in Google Data Engineer interviews (tests window functions).


4️⃣ Get Customers Who Ordered Continuously for 3 Days

Question:
Find customers who made purchases on 3 consecutive days.

 
SELECT DISTINCT c1.customer_id
FROM Orders c1, Orders c2, Orders c3
WHERE c2.order_date = c1.order_date + 1
AND c3.order_date = c1.order_date + 2
AND c1.customer_id = c2.customer_id
AND c2.customer_id = c3.customer_id;

Shows ability to handle sequence-based logic.


5️⃣ Find Duplicate Records in a Table

 
SELECT name, COUNT(*)
FROM Customers
GROUP BY name
HAVING COUNT(*) > 1;

To delete duplicates but keep one:

 
DELETE FROM Customers
WHERE rowid NOT IN (
SELECT MIN(rowid) FROM Customers GROUP BY name
);

6️⃣ Find Employees Who Earn the Maximum Salary in Each Department

 
SELECT e.emp_name, e.department, e.salary
FROM Employees e
JOIN (
SELECT department, MAX(salary) AS MaxSalary
FROM Employees
GROUP BY department
) s ON e.department = s.department AND e.salary = s.MaxSalary;

Flipkart & Amazon often combine this logic with RANK() questions.


7️⃣ Calculate Cumulative Revenue by Month

 
SELECT month,
SUM(revenue) OVER(ORDER BY month ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningRevenue
FROM Sales;

Tests your understanding of window functions and analytical calculations.


8️⃣ Identify Employees With More Than Average Salary

 
SELECT * FROM Employees
WHERE salary > (SELECT AVG(salary) FROM Employees);

Simple but common — product companies test for clarity and efficiency.


9️⃣ Find Departments With More Than 5 Employees

 
SELECT department, COUNT(*) AS emp_count
FROM Employees
GROUP BY department
HAVING COUNT(*) > 5;

Shows aggregate function + HAVING clause mastery.


🔟 Find 3rd Highest Order Amount Using DENSE_RANK()

 
SELECT order_id, amount
FROM (
SELECT order_id, amount,
DENSE_RANK() OVER(ORDER BY amount DESC) AS rnk
FROM Orders
) ranked
WHERE rnk = 3;

Real question asked in Google and Microsoft partner data interviews.


💡 Pro Tips for Product-Based SQL Interviews

  • Focus on analytical queries, not just CRUD.

  • Practice writing nested subqueries, window functions, and CTEs.

  • Avoid “SELECT *”; always specify columns.

  • Learn to explain your query logic step-by-step — clarity matters more than speed.

  • Optimize queries and explain why your approach is efficient.


🧩 Conclusion

These SQL coding challenges (2025 edition) reflect what companies like Google, Amazon, and Flipkart expect from data professionals.

To stand out, practice these problems daily using mock datasets.
Remember — the key to success in product-based interviews is not just knowing syntax, but demonstrating how you think through data logically.

Consistent practice = guaranteed improvement + higher interview confidence.


Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: