hello
I have been really struggling with a problem that maps values from one column into values in another column. I'll explain this as clearly as I can: (I'm not even sure that this can be done in SQL, but I thought I'd ask for assistance anyway!)
a) Consider the table shown below. Look at the first 6 integer values in column Val1, corresponding to Case = 1. For every such case, there will be three values = 0, and 3 non-zero entries. These represent MAPPINGS (in the mathematical sense). So...
For case = 1: p maps to q (1 space below), r maps to t (2 spaces below), and s maps to u (2 spaces below) and...
For case = 2: p maps to t (4 spaces below), r maps to u (3 spaces below), and s maps to q (2 spaces ABOVE).
So far, column Val2 is empty.
b) What I need to do is transform the values in column Val1, then write the transformed values in column Val2. The TRANSFORMATION RULE is given in the following table:
Here's how the transposition rule is applied (referring to tblData, Case = 1): (shown in the table below.)
tblData says 'p maps to q', so tblTranspose changes this to 'r maps to u', which is 3 spaces below it. (recorded in column Val2 below)
tblData says 'r maps to t', so tblTranspose changes this to 'q maps to t', which is 3 spaces below it. (recorded in column Val2 below)
tblData says 's maps to u', so tblTranspose changes this to 'p maps to s', which is 3 spaces below it. (recorded in column Val2 below)
Here's how the transposition rule is applied (referring to tblData, Case = 2): (shown in the table below.)
tblData says 'p maps to t', so tblTranspose changes this to 'r maps to t', which is 2 spaces below it. (recorded in column Val2 below)
tblData says 'r maps to u', so tblTranspose changes this to 'q maps to s', which is 2 spaces below it. (recorded in column Val2 below)
tblData says 's maps to q', so tblTranspose changes this to 'p maps to u', which is 5 spaces below it. (recorded in column Val2 below)
I just can't seem to figure out how to write the code to fill column Val2.
(by the way, my actual problem uses (0, 1, 2, 3, 4, 5) in the ColNum column, not (p, q, r, s, t, u). I think this
actually simplifies the problem, but it makes describing the problem in this forum more confusing!)
Many thanks for any help, even if it is just to get me pointed in the right direction.
Vicky C.
I have been really struggling with a problem that maps values from one column into values in another column. I'll explain this as clearly as I can: (I'm not even sure that this can be done in SQL, but I thought I'd ask for assistance anyway!)
a) Consider the table shown below. Look at the first 6 integer values in column Val1, corresponding to Case = 1. For every such case, there will be three values = 0, and 3 non-zero entries. These represent MAPPINGS (in the mathematical sense). So...
For case = 1: p maps to q (1 space below), r maps to t (2 spaces below), and s maps to u (2 spaces below) and...
For case = 2: p maps to t (4 spaces below), r maps to u (3 spaces below), and s maps to q (2 spaces ABOVE).
So far, column Val2 is empty.
Code:
tblData Case ColNum Val1 Val2
-------------------------------------
1 p 1
1 q 0
1 r 2
1 s 2
1 t 0
1 u 0
2 p 4
2 q 0
2 r 3
2 s -2
2 t 0
2 u 0
3 ... etc ...
b) What I need to do is transform the values in column Val1, then write the transformed values in column Val2. The TRANSFORMATION RULE is given in the following table:
Code:
tblTranspose V1 V2
----------
p r
q u
r q
s p
t t
u s
Here's how the transposition rule is applied (referring to tblData, Case = 1): (shown in the table below.)
tblData says 'p maps to q', so tblTranspose changes this to 'r maps to u', which is 3 spaces below it. (recorded in column Val2 below)
tblData says 'r maps to t', so tblTranspose changes this to 'q maps to t', which is 3 spaces below it. (recorded in column Val2 below)
tblData says 's maps to u', so tblTranspose changes this to 'p maps to s', which is 3 spaces below it. (recorded in column Val2 below)
Here's how the transposition rule is applied (referring to tblData, Case = 2): (shown in the table below.)
tblData says 'p maps to t', so tblTranspose changes this to 'r maps to t', which is 2 spaces below it. (recorded in column Val2 below)
tblData says 'r maps to u', so tblTranspose changes this to 'q maps to s', which is 2 spaces below it. (recorded in column Val2 below)
tblData says 's maps to q', so tblTranspose changes this to 'p maps to u', which is 5 spaces below it. (recorded in column Val2 below)
Code:
tblData Case ColNum Val1 Val2
-------------------------------------
1 p 1 3
1 q 0 3
1 r 2 3
1 s 2 0
1 t 0 0
1 u 0 0
2 p 4 5
2 q 0 2
2 r 3 2
2 s -2 0
2 t 0 0
2 u 0 0
3 ... etc ...
I just can't seem to figure out how to write the code to fill column Val2.
(by the way, my actual problem uses (0, 1, 2, 3, 4, 5) in the ColNum column, not (p, q, r, s, t, u). I think this
actually simplifies the problem, but it makes describing the problem in this forum more confusing!)
Many thanks for any help, even if it is just to get me pointed in the right direction.
Vicky C.