Afficher un message
Vieux 25/03/2008, 11h18   #10
Darsin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Doing Summation on multiple criterias on the same column in asingle query

On Mar 24, 6:32pm, "Tom Moreau" <t...@dont.spam.me.cips.ca> wrote:
> Try:
>
> SELECT
> Month
> , SUM(CASE WHEN indicator = 0 THEN Value ELSE 0 END) Value0
> , SUM(CASE WHEN indicator = 1 THEN Value ELSE 0 END) Value1
> FROM TABLE1
> GROUP BY Month
>
> --
> Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
> SQL Server MVP
> Toronto, ON Canadahttps://mvp.support.microsoft.com/profile/Tom.Moreau
>
> "Darsin" <dar...@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 ?


Hi all,

First of all my apologies for using Month, Value, etc keywords in the
example, will remember to not do it again, and thank you for a prompt
reply.
Secondly, initially i used a temp table to fill the first case and
then updated the temp table with the second case.
now the total number of records are around 50,000 and above, so my
question is will there be a performance (query excute time)
improvement or degradation. In case any furthur details are required
than please do let me know.

Thanks

in case if it there
  Réponse avec citation
 
Page generated in 0,05891 seconds with 9 queries