SQL Server Performance

COUNT(CASE THEN (COUNT DISTINCT)) ?

Discussion in 'SQL Server 2005 General Developer Questions' started by apnw7931, Dec 26, 2010.

  1. apnw7931 New Member

    Hi,I have problem to code what i want to.Please find attached my table and also the result i want to obtain.I'm not capable of having the two last columns of my table Resultats (Compte Unique Jan, Compte Unique Fev).I would like to count the number of different (unique) account for January, the same for February.Hère is what i already have :
    Code:
    SelectProduit,Count(Compte),Count(CASE Date WHEN '01/01/2010' THEN 1 ELSE 0 END) AS "Compte Janv", Count(CASE Date WHEN '01/02/2010' THEN 1 ELSE 0 END) AS "Compte Fév",?? AS "Comptes Unique Jan",?? AS "Comptes Unique Fév"FROMma_tableWhereDate Between '01/01/2010' AND '01/02/2010'GROUP BYProduit
    I'll need something like :
    Code:
    CASE Date WHEN '01/01/2010' THEN (Count Distinct Compte)
    Could you please help me ?[IMG]
  2. Adriaan New Member

    Check out the PIVOT syntax.
    It's a lot of fun to work out ([;)]) so I'll let you do all the work.

Share This Page