conditional spliting into diffrent columns

  • Hi All,

    i have a table in the form shown below

    date |product |amount

    01/01/2010 |2 |3

    01/01/2010 |1 |4

    01/01/2010 |1 |6

    01/01/2010 |2 |7

    01/01/2010 |3 |2

    01/01/2010 |2 |4

    02/01/2010 |2 |3

    02/01/2010 |3 |5

    02/01/2010 |3 |1

    02/01/2010 |2 |1

    02/01/2010 |1 |2

    02/01/2010 |2 |4

    02/01/2010 |1 |2

    I would like to know a method or procedure that can to achieve a table as shown below

    date |1|2|3

    01/01/2010 |10|14|2

    02/01/2010 |6|8|6

    where 1,2,3 is the sum of each product for each day is this possible to select these and how i'll really appreciate any help on these. thanks in advance

  • This will get u there!

    SELECT * FROM

    ( SELECT * FROM <TABLE> ) PIVOT_TABLE

    PIVOT

    (SUM(AMOUNT) FROM PRODUCT IN ([1],[2],[3]))

    Replace <Table> with your table name!

    Tell us if that helped!!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply