954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Count the total and group clause

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.

shayankhan
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
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
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

I am getting error Incorrect syntax near 'LIMIT'.
i am using sql 2008

shayankhan
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

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

shayankhan
Newbie Poster
18 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You