Home Forums Programming General Complex Query using Self-Joins RE: Complex Query using Self-Joins

  • Try this:

    SELECT tag_date

    , SUM(close_total)

    , ISNULL(SUM(CASE id WHEN 1 THEN close_total ELSE 0 END), 0) AS col1

    , ISNULL(SUM(CASE id WHEN 2 THEN close_total ELSE 0 END), 0) AS col2

    , ISNULL(SUM(CASE id WHEN 3 THEN close_total ELSE 0 END), 0) AS col3

    FROM @t1

    GROUP BY tag_date

    __________________________________________________________________________________________________________
    How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/