Link to home
Start Free TrialLog in
Avatar of AXISHK
AXISHK

asked on

Sum up a field in SQL Statement

I have a table like this

account,   year,   period, amount
491         2008         1          100
491         2008          1           50
491         2008          1        -100
491         2008          1        -200

Result
account   year  period  DrAmt      CrAmt        
491         2008     1      150          -300

The amount is either +ve or -ve value. Is it possible to write a single SQL statement to display a summary of +ve value and -ve value in two separate calculation field ?

thank
ASKER CERTIFIED SOLUTION
Avatar of dan_neal
dan_neal
Flag of United States of America 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
select  account, sum(amount) as Total from <table name>
group by account

--group by might not be needed, if you get errors, try just
select  sum(amount) as Total from <table name>