Results 1 to 2 of 2

Thread: denormalize

  1. #1
    Join Date
    Oct 2003
    Posts
    3

    Unanswered: denormalize

    Hi,

    Please let me know if I can populate the target table using a single query and if so how.

    Thanks in Advance,
    Yeshwant

    Source_table
    acct score type
    1 100 CB
    1 200 RIX
    2 300 BS

    Target table
    acct CB RIX BS
    1 100 200
    2 300

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yes, if there are only going to be a limited number of known columns

    insert into target_table
    select acct
    , sum(case when type='CB' then score else null end) as CB
    , sum(case when type='RIX' then score else null end) as RIX
    , sum(case when type='BS' then score else null end) as BS
    from source_table
    group by acct
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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