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
 General SQL Server Forums
 New to SQL Server Programming
 Grouping with LIKE

Author  Topic 

dbillings
Starting Member

1 Post

Posted - 2009-05-07 : 20:14:40
I want to create subtotals and totals for a table based on the first two digits of an accountid. For example...

account balance
100001 10.00
100002 20.00
110001 10.00
110002 5.00

So I want to group a total for 100001 and 100002 for a total of 30.00 and group 110001 and 110002 for a total of 15.00. Any ideas on how I would do this?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-05-07 : 20:27:34
[code]select left(account, 2), sum(balance)
from table
group by left(account, 2)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-08 : 10:27:07
[code]
select account/10000, sum(balance)
from table
group by account/10000
[/code]
Go to Top of Page
   

- Advertisement -