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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-04-29 : 10:33:40
|
Brian writes "I've gone over a few things now trying to figure how i can group a set of records by being negative or positive.--------------------Sample Table--------------------Type Amount---- ---------4 5.004 10.954 -8.0012 44.956 6.956 -6.956 -3.00--------------------End Result--------------------Type Amount Count---- ------ -----4 15.95 24 -8.00 112 44.95 16 6.95 16 -9.95 2 I've tried a few things though the end result is not what i'm looking for. Am I missing something?Thanks,Brian" |
|
|
YellowBug
Aged Yak Warrior
616 Posts |
Posted - 2002-04-29 : 10:58:37
|
| Try this:select type, sum(amount) as amt , County = count(type) from tSamplewhere amount >= 0group by typeunionselect type, sum(amount), count(type) from tSamplewhere amount < 0group by typeorder by type asc, amt descHow do you want the result sorted?What condition puts the type 12 record in the middle? |
 |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-04-30 : 00:59:16
|
| How About doing it in a single queryselect Type,sum(amount) as Amount,Count(1) as Countsfrom tSamplegroup by Sign(Amount),TypeHTH-------------------------------------------------------------- |
 |
|
|
|
|
|