Amazon SQL Question
Amazon SQL Question
3. Write a query to retrieve all customers who purchased more than $100.
9. Write a query to find customers who haven't made any purchases in the last 6 months.
11. Write a query to group data by month and calculate total sales per month.
15. Write a query to calculate the average purchase amount for all customers.
17. Write a query to count the number of customers who registered in 2023.
18. Explain the purpose of the ORDER BY clause.
19. Write a query to calculate the total revenue from each product category.
20. Write a query to retrieve all customers with more than one purchase.
22. Write a query to retrieve the second-highest salary from an employee table.
23. Write a query to display the first and last name of all customers whose name starts with
‘A’.
24. Explain the difference between INNER JOIN and OUTER JOIN.
25. Write a query to retrieve the total count of orders for each customer.
26. Write a query to display the names of customers who made a purchase in the last 30 days.
27. What is a PRIMARY KEY and how is it different from a UNIQUE constraint?
29. Write a query to select customers who registered in January and made purchases in
February.
31. Write a query to retrieve customers whose purchase total is between $50 and $100.
33. Write a query to calculate the percentage of orders from a specific product category.
34. Write a query to select all customers who made purchases in both 2022 and 2023.
35. How do you use the CASE statement to create conditional queries?
36. Write a query to find unique customers who made a purchase within 10 days of
registering.
37. Write a query to retrieve the 5th highest salary from an employee table.
38. Explain the use of GROUP BY and HAVING together.
39. Write a query to display products that have not been sold in the last month.
40. Write a query to create a histogram of the number of comments per user in a month.
43. Write a query to find the top 3 selling products in each region.
45. Write a query to retrieve all orders placed in the last 6 months and group them by
customer.
46. How would you optimize a query with multiple joins and aggregations?
47. Write a query using COALESCE to replace NULL values with a default value.
48. Write a query to rank customers by the total amount they have spent.
49. Write a query to retrieve the names of employees who have not received a salary
increase.
50. Write a query to find products where the price has decreased compared to the previous
month.
52. Write a query to find customers who made a purchase in every quarter of 2022.
55. Write a query to retrieve the most frequently purchased product category.
58. Write a query to calculate the retention rate of customers over the past year.
59. Write a query to find customers who made repeat purchases within the same week.
60. How do you use a self-join to compare records within the same table?
61. Write a query to calculate the average number of orders per customer per month.
62. Write a query to display the month-over-month growth rate for sales.
63. How would you handle performance issues in a query with large datasets?
64. Write a query to retrieve the last purchase date for each customer.
66. Write a query to find customers whose total purchase amount exceeds the average
purchase amount.
67. Write a query to calculate the number of days between a customer’s registration and first
purchase.
68. Write a query to list all products that were sold in December but not in January.
69. How do you use window functions like ROW_NUMBER(), RANK(), and DENSE_RANK()?
70. Write a query to merge two tables based on a common field and calculate the difference
between their values.
71. Write a query to calculate a rolling average of the last 3 months of sales by product.
72. Write a query using a Common Table Expression (CTE) to calculate cumulative sales by
region.
73. Write a query to find all customers who have made purchases in the same store multiple
times.
74. Write a query to detect anomalies in sales data based on historical patterns.
75. Write a query to retrieve customers whose total purchase amount is more than 2 standard
deviations above the mean.
76. Write a query to calculate the lifetime value (LTV) of customers based on their purchase
history.
77. Write a query to find the top 5 products with the highest month-over-month sales growth.
78. Write a query to identify customers who have not made a purchase in over 12 months.
79. Write a query to create a sales forecast for the next quarter based on historical data.
80. Write a query to retrieve the top 10 customers by purchase amount within each product
category.
81. Write a query to identify and remove duplicate records from a table.
82. Write a query to find products that have been consistently sold over the last 6 months.
83. Write a query to calculate the churn rate of customers over the past year.
85. Write a query to calculate the total number of refunds issued in each month.
86. Write a query to retrieve customers who have consistently increased their purchase
amount month over month.
87. Write a query to calculate the average time between purchases for each customer.
89. Write a query to calculate the probability of customer churn based on their purchase
history.
91. Write a query to predict future sales using a linear regression model in SQL.
92. Write a query to identify customers who are most likely to respond to a marketing
campaign based on past behavior.
94. Write a query to calculate the average customer acquisition cost based on sales and
marketing data.
95. Write a query to optimize inventory levels by analyzing sales trends and product turnover.
97. Write a query to analyze customer purchase behavior and identify cross-sell
opportunities.
98. Write a query to forecast inventory needs based on historical sales data.
99. Write a query to calculate the ROI of marketing campaigns based on customer purchases.
100. Write a query to segment customers based on their purchase frequency and average
order value.
These questions cover a wide range of SQL skills, from basic querying to advanced, for entry-
level interviews at Amazon and similar companies.