Afficher un message
Vieux 24/03/2008, 15h33   #4
Uri Dimant
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Doing Summation on multiple criterias on the same column in a single query

Hi
SUM(CASE WHEN indicator =0 THEN value END ) as val1
SUM(CASE WHEN indicator =1 THEN value END ) as val1
FROM tbl




"Darsin" <darsin@gmail.com> wrote in message
news:8fc9e52e-1606-44d9-a722-4ae0f29542b6@s13g2000prd.googlegroups.com...
> Hi all
> I need to perform a summation on a column of a table based on a
> criteria given in another column in the same table. The catch is i
> need to perform different sums according to the number of criterias in
> the criteria column, in a single query. the structure of the table is
> somethinmg like this (only relevant columns are shown)
>
> TABLE1
> Value - numeric(20,6)
> Month - int
> indicator - bit
>
> Now i need to do something like:
>
> SELECT Month, SUM(Value) FROM TABLE1
> WHERE indicator = 1
> GROUP BY Month
>
> and also
>
> SELECT Month, SUM(Value) FROM TABLE1
> WHERE indicator = 0
> GROUP BY Month
>
>
> How can i do this in a single query, something like this:
> SELECT Month, SUM(Value where indicator=1), SUM(Value where
> indicator=0) and so on .......
>
> Could any body please me on this ?



  Réponse avec citation
 
Page generated in 0,14088 seconds with 9 queries