SQLTeam.com | Weblogs | Forums

[SQL] Who spent most money

Hello guys, i'm doing a project for my class and i would appreciate it if you guys help me with this query!

I need to find the name of the customer who spent most money on orders (assume that there might be more than 1 customer spent the same max amount). Provide the country that person comes from
We use w3 school for the database. You can google: w3 school sql and click on "try it yourself"

I think it is using the sqlite

Thanks so much

Welcome

Could you please show us what you tried?

hi

i tried doing this !! hope this helps

i wrote the SQL ... the top most record is your answer

... there maybe two or three records with the same max(amount ) ..
.. in that case .. take the top 2 or 3 records

select 
      customers.customername 
    , customers.country 
	, sum(products.price)
from 
    customers 
       join 
    orders 
	      on customers.customerid = orders.customerid
      join 
    orderdetails 
          on orders.orderid
       join
    products 
          on products.productid = orderdetails.productid
group by 
      customers.customername 
    , customers.country 
order by 
      sum(products.price) desc

Hi from @harishgg1 suggestion, i was able to do the query. Thanks alot