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.
Author |
Topic |
ayyoob1234
Starting Member
3 Posts |
Posted - 2013-06-11 : 11:57:29
|
hii have to extract a list of accounts where balance < 10000a/c_id start_dt end_dt balanceB12345 01-01-2007 25-06-2007 15000 B12345 26-05-2007 01-10-2007 15000 B12345 02-10-2007 31-12-2099 25000 my code is as follow :select a/c_id, sum(balance)from tablewhere sum(balance) > 10000group by a/c_idplzzz help |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-06-11 : 12:06:23
|
quote: Originally posted by ayyoob1234 hii have to extract a list of accounts where balance < 10000a/c_id start_dt end_dt balanceB12345 01-01-2007 25-06-2007 15000 B12345 26-05-2007 01-10-2007 15000 B12345 02-10-2007 31-12-2099 25000 my code is as follow :select a/c_id, sum(balance)from tablewhere sum(balance) > 10000group by a/c_idplzzz help
T-SQL syntax does not allow you to put an aggregate such as SUM in the WHERE clause. You have to use a HAVING clause like shown below:select a/c_id, sum(balance)from tablegroup by a/c_idHAVING sum(balance) > 10000 BTW, did you want to get accounts with balances LESS than 10000 or MORE than 10000? The query is looking for MORE than, but you said LESS than in the text of your posting. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-11 : 12:48:33
|
Hmm...how can balance be summated like this? Isnt balance field containing the balance as on that that date?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|