16 views
23 Jan 2026
Find customers who placed at least one order in 3 consecutive months (any year). Return customer_id only. Hint: convert to month buckets, then use a window row_number trick....
3 views
23 Jan 2026
You have Customers(customer_id, name, city). Write a query to show only customer_id and name for customers living in 'Mumbai'. Keep it simple: one WHERE condition....
3 views
23 Jan 2026
From Orders(order_id, order_date), show the latest 10 orders. Sort by order_date (newest first). If dates are same, you can sort by order_id too....
2 views
23 Jan 2026
You need a small city-wise report. From Customers(city), return city and how many customers are in that city....
4 views
23 Jan 2026
From Employees and Departments, show only those departments where employee count is more than 5. Display dept_name and the count....
3 views
23 Jan 2026
From Orders(status), list all different statuses available. You should not repeat the same status in output....
2 views
23 Jan 2026
From Orders(customer_id, total_amount), find the customer who spent the most overall. First do SUM per customer, then pick the highest one....
2 views
23 Jan 2026
Make a simple daily sales report for the last 7 days. From Orders(order_date, total_amount), show order_date and total sales per day....
4 views
23 Jan 2026
List customers who never placed any order. You can solve using LEFT JOIN + NULL check (or NOT EXISTS)....
2 views
23 Jan 2026
Assume order_id should be continuous. Using a helper Numbers(n) table, list the missing order_id between MIN(order_id) and MAX(order_id)....
2 views
23 Jan 2026
For each department, return employee(s) who have the second highest salary. Use DENSE_RANK so ties are handled nicely....
3 views
23 Jan 2026
Create month-wise revenue and also show a rolling 3-month total. First aggregate by month, then apply a window sum over the last 3 months....
2 views
23 Jan 2026
Assume Payments.amount is negative for refunds. Find customers where total refund is more than 30% of total paid amount. Use conditional SUM....
2 views
23 Jan 2026
For each customer, show the first time they ordered and the most recent order date. This is a clean use of MIN and MAX....
2 views
23 Jan 2026
From OrderItems(order_id, product_id), count how often two products are bought in the same order. Return top 10 pairs by count....