Hello guys i am little bit confuse here with the code
can any one help me out ..
i want max customer paid in shopping and their name
i dont know that i am using right way or not but guide me here

Select sum(od.unitprice * od.quantity) as Amount,
        (Select ContactName from Customers where customerId in (o.customerid)) as CustomerName  from [Order Details] as od
        inner join orders as o on o.orderid = od.orderid
        inner join customers as c on o.customerid = c.customerid
group by o.customerid

here if i use

Max(sum(od.unitprice * od.quantity)) as Amount

i get error can you please correct the code... i want the customer name
who have paid amount very much.

Recommended Answers

All 3 Replies

Select sum(od.unitprice * od.quantity) as Amount,
ContactName  as customername  from [Order Details] as od
        inner join orders as o on o.orderid = od.orderid
        inner join customers as c on o.customerid = c.customerid
group by o.customerid,ContactName  
order by amount desc limit 1

I am getting error

Incorrect syntax near 'LIMIT'.

i am using sql 2008

well i used TOP 1 before the sum() functions and now its working ..
thanks for helping me out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.