i have one table and one column in this.there is 15 data(integer).i want to count
positive numbers and negative numbers
and also
sum of total numbers
in one query . can any one help me .........
i have one table and one column in this.there is 15 data(integer).i want to count
positive numbers and negative numbers
and also
sum of total numbers
in one query . can any one help me .........
I'll give you psudeo code to help you with your homework.
3 aggregates:
select (select sum(mycolumn) from mytable where mycolumn > 0) as positive_sum,
       (select sum(mycolumn) from mytable where mycolumn < 0) as negative_sum,
       sum(mycolumn) as total_sum
from   mytable
Try this
SELECT  SUM(CASE WHEN Col > 0 THEN 1 ELSE 0 END) AS Pos,
     SUM(CASE WHEN Col < 0 THEN 1 ELSE 0 END) AS Neg,
     SUM(Col) AS Tot
FROM    Table
Or...
SELECT  
     COUNT(CASE WHEN Col > 0 THEN 1 END) AS NumPositives,
     COUNT(CASE WHEN Col < 0 THEN 1 END) AS NumNegatives,
     SUM(Col) AS Tot
FROM  TableName;
Or you could consider using SIGN(Col), which gives 1 for positive numbers and -1 for negative numbers.