Showing posts with label loss1. Show all posts
Showing posts with label loss1. Show all posts

Monday, March 12, 2012

Question on Query

Hi, please help...

I have a table:

Brand | Profit | Loss

1 | 100 | 11
2 | 234 | 22
3 | 300 | 33
and want to get the result: Sum(Profit) where brand <= 2, Sum(Loss) where Brand = 3
The result should be look like:
Profit | Loss
334 | 33
Can you show me the sql query please? I am urgent need it for my work... please help..

I think this should work
Select (Select sum(Profit) From tableName Where brand<=2) As Profit,
(Select sum(Loss) From tableName Where brand=3) As Loss|||Many thanks, it works fine.
I don't know that the sql query can be just simply, thx for the help.|||One more question, is it possible i can sum up those 2 values?
so that the total will be:
Total
367|||

SELECT
Sum(Profit) as Total
WHERE
Brand <= 2
or
Brand = 3

|||

I think you have make a mistake. i want to get the result ofsum(profit) where brand <=2+ sum(loss) where brand = 3.
but not sum all the profit or loss
The result should be [(100)<- from brand 1 profit] + [(234)<- from brand 2 profit] + [(33)<- from brand 3 loss]

Total
367

|||

Try this

Select (Select sum(Profit) From tableName Where brand<=2) As Profit,
(Select sum(Loss) From tableName Where brand=3) As Loss,
((Select sum(Profit) From tableName Where brand<=2) + (Select sum(Loss) From tableName Where brand=3)) As Total