Esteemed StackOverflow Community,
I have a table with the following data. I want to be able to produce n
rows based on 5 - value in column E
.
Also want to be able to make the value in column F
zero, keeping the values for A, B, C, D intact.
I'm not in a position to create a temp table.
INPUT
Table1
A B C D E F
AA BB CC DD 1 100
AA BB CC DD 3 200
AA BB CC DD 5 300
EE FF GG HH 1 600
Table2
key desc
1 AABBCCDD
2 EEFFGGHHH
OUTPUT
A B C D E F key
AA BB CC DD 1 100 1
AA BB CC DD 3 200 1
AA BB CC DD 5 300 1
AA BB CC DD 2 0 1
AA BB CC DD 4 0 1
EE FF GG HH 1 600 2
EE FF GG HH 2 0 2
EE FF GG HH 3 0 2
EE FF GG HH 4 0 2
EE FF GG HH 5 0 2
My existing SQL looks like this.
SELECT A.*,B.key from table1 as A
JOIN table2 as B on concat(A.A,A.B,A.C) = B.desc;