Ask @rasansmn:

There are two tables as Customers and Orders connected through foreign keys. Write a SQL Query to list all customers with the highest purchase amount of orders. Ex: If a customer has 3 orders 100, 300, 500 as purchase amounts, the list should display details of 500 order along with customer details.

SELECT [c].[id], [c].[cus_name], [o].[id], [o].[amount] FROM [customer] [c] INNER JOIN [order] [o] ON WHERE O.amount IN (SELECT MAX(amount) FROM [order] GROUP BY [customer_id])

View more