Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sum of Amount from Subquery

Author  Topic 

MadForPlaid
Starting Member

1 Post

Posted - 2013-05-29 : 13:13:50
Given the sample results from a subquery:

Store.....Ticket...Date........Cashier....POS...Dept.....Sum
1..........10......2012-08-30.....25.......12....6......45.34
1..........10......2012-08-30.....25.......12....6......265.89
2..........12......2012-07-15.....38.......9....16......41.40
2..........12......2012-07-15.....38.......9....16......125.69

How can I then query off of that to arrive at 1 row (per each match) returned with the sum of amount?

Store.....Ticket...Date........Cashier....POS...Dept.....Sum
1..........10......2012-08-30.....25.......12....6......311.23
2..........12......2012-07-15.....38.......9....16......167.09

Thanks for any help,

Paul B.

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2013-05-29 : 13:18:58
SELECT Store, Ticket, DAte, CAshier, POS, Dept, Sum(SumColumn)
FROM TableName
Group by Store, Ticket, DAte, CAshier, POS, Dept

Cheers
MIK
Go to Top of Page
   

- Advertisement -