Link to home
Start Free TrialLog in
Avatar of W.E.B
W.E.B

asked on

SQL 2008 GROUP BY

Hello,
I'm trying to use below code to get some totals per client.
results I'm getting is about 10-15 lines per client.
I need to get only one line per client

SELECT fo.AccountNumber,cl.AccountCode,cl.AccountstartDate, cl.Name,
(Select SUM(fo.SubTotalAmount) where fo.ServiceTypeID in (122,123,124)) AS [OVN],
(Select SUM(fo.SubTotalAmount) where fo.ServiceTypeID NOT in (122,123,124)) AS [Local],
SUM(fo.SubTotalAmount) AS [SubTotalAamount],
SUM(fo.TotalAmount) AS [TotalAamount]
FROM  FinalizedOrders fo JOIN Clients cl ON fo.AccountNumber = cl.AccountNumber
WHERE fo.OrderDate BETWEEN '2013-01-01' AND '2013-12-31'
GROUP BY fo.AccountNumber,cl.AccountCode,cl.AccountstartDate, cl.Name,fo.ServiceTypeID
order BY fo.AccountNumber

Any help is appreciated,
Thanks,
ASKER CERTIFIED SOLUTION
Avatar of MohitPandit
MohitPandit
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of W.E.B
W.E.B

ASKER

Awesome.

I will have a second similar question shortly.

thanks again.
Avatar of W.E.B

ASKER

Thank you