Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010
    Posts
    1

    Unanswered: calculate matrix

    Hello,

    need some help. I have some data from joined tables:


    0 aaa 12
    0 bbb 15
    0 aaa 20
    0 ccc 0
    1 aaa 30
    1 ccc 14
    1 ddd 7
    1 ccc 8
    2 aaa 23
    2 ddd 78
    2 bbb 200
    2 bbb 98

    need to calculate everything from 3rd colum, by 2d colum's name and group by 1st colum's name.

    The result should be like this (the main thing I need is the calculated data):

    ____0__1__2
    aaa 32 30 23
    bbb 15 0 298
    ccc 0 22 0
    ddd 0 7 78

    is it possible at all? 1,2,3...is to 50, and aaa, bbb, ccc... about 53k

  2. #2
    Join Date
    Dec 2008
    Location
    At work...
    Posts
    92
    I think this is what you ask for:

    select c2, sum(case when c1 = 0 then c3 else 0 end) as sum0,
    sum(case when c1 = 1 then c3 else 0 end) as sum1,
    ...
    sum(case when c1 = 50 then c3 else 0 end) as sum50
    from tt
    group by c2;

Posting Permissions

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