๐ SQL Interview Question (Must-Know)
Question:
You have a table orders with the following columns:
order_id, customer_id, order_date, order_amount
๐ Write an SQL query to find the total order amount for each customer who has placed more than 3 orders.
โ
Solution:
SELECT
customer_id,
SUM(order_amount) AS total_order_amount
FROM orders
GROUP BY customer_id
HAVING COUNT(order_id) > 3;
๐ง Explanation:
GROUP BY customer_id โ groups orders per customer
SUM(order_amount) โ calculates total spending
HAVING COUNT(order_id) > 3 โ filters customers with more than 3 orders
๐ React with ๐ฅ or ๐ if this helped
๐ Want more SQL interview questions & real-world scenarios? React and stay tuned!
Post #2005
1.46K
- โค 2