Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2010
    Posts
    12

    Unanswered: Sql Query Needed

    Year Tera Experiant Screen Assessment
    2007 400 300 200 100
    2008 4000 3000 2000 1000
    2009 40000 30000 20000 10000
    2010 40000 30000 20000 10000


    This sample table I need SQL Query which prints below

    2010 2009 2008 2007 Year
    10000 10000 1000 100 Assessment
    20000 20000 2000 200 Screen
    30000 30000 3000 300 Experiant
    40000 40000 4000 400 Tera

  2. #2
    Join Date
    Jul 2010
    Posts
    6
    This might give you a hint...

    SELECT
    SUM([2010]) AS Sum2010,
    SUM([2009]) AS Sum2009,
    SUM([2008]) AS Sum2008,
    SUM([2007]) AS Sum2007,
    [Year]
    FROM
    (SELECT
    CASE WHEN Year='2010' THEN Assessment ELSE 0 END AS '2010',
    CASE WHEN Year='2009' THEN Assessment ELSE 0 END AS '2009',
    CASE WHEN Year='2008' THEN Assessment ELSE 0 END AS '2008',
    CASE WHEN Year='2007' THEN Assessment ELSE 0 END AS '2007',
    'Assessment' AS 'Year'
    FROM #tbl) GROUP BY [Year]

    UNION ALL

    SELECT
    SUM([2010]) AS Sum2010,
    SUM([2009]) AS Sum2009,
    SUM([2008]) AS Sum2008,
    SUM([2007]) AS Sum2007,
    [Year]
    FROM
    (SELECT
    CASE WHEN Year='2010' THEN Screen ELSE 0 END AS '2010',
    CASE WHEN Year='2009' THEN Screen ELSE 0 END AS '2009',
    CASE WHEN Year='2008' THEN Screen ELSE 0 END AS '2008',
    CASE WHEN Year='2007' THEN Screen ELSE 0 END AS '2007',
    'Screen' AS 'Year'
    FROM #tbl) GROUP BY [Year]

  3. #3
    Join Date
    Jul 2010
    Posts
    12
    Thanks for the Query it works fine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •