Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2002
    Posts
    104

    Unanswered: query--column values as columns in other table

    Hello All,

    Can anyone please help me here .

    i have data something like

    id code value units
    1 1 A 10
    1 1 B 10
    1 1 C 10
    2 2 A 20
    2 2 B 20
    2 2 C 20
    3 3 A 30
    3 3 B 30
    3 3 C 30

    i wish to get resultset as

    id code A B C
    1 1 10 10 10
    2 2 20 20 20
    3 3 30 30 30

    Assuming id, code as Primary Key.

    ANy help wud be appreciatied,

    Thanx alot in advance,

    --Pooja

  2. #2
    Join Date
    Dec 2002
    Posts
    104

    Re: query--column values as columns in other table

    Originally posted by pooja
    Hello All,

    Can anyone please help me here .

    i have data something like

    id code value units
    1 1 A 10
    1 1 B 10
    1 1 C 10
    2 2 A 20
    2 2 B 20
    2 2 C 20
    3 3 A 30
    3 3 B 30
    3 3 C 30

    i wish to get resultset as

    id code A B C
    1 1 10 10 10
    2 2 20 20 20
    3 3 30 30 30

    Assuming id, code as Primary Key.

    ANy help wud be appreciatied,

    Thanx alot in advance,

    --Pooja
    I have come up with this query...

    select id,code,
    A = sum(case when value = "A" then unit else 0 end) ,
    B=sum(case when value = "B" then unit else 0 end ),
    C= sum(case when value = "C" then unit else 0 end)
    from a
    group by id,code

    I am sure there must be some polished way to do this.

    --Pooja
    Last edited by pooja; 03-09-04 at 11:01.

Posting Permissions

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