If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > calculate matrix

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-05-10, 17:35
fenixoid fenixoid is offline
Registered User
 
Join Date: Oct 2010
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 10-06-10, 03:09
JarlH JarlH is offline
Registered User
 
Join Date: Dec 2008
Location: At work...
Posts: 68
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;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On