Hello, I have a table that has a User_ID, then many columns that have integer values. They are named s1_1 through s1_5, s2_1 through s2_5, s3_1 through s3_5, s4_1 through s4_5 and s5_1 through s5_5. So, in other words, there are 25 columns total with these integer values, and 1 User_ID column. What I need to do with the where clause of my select statement is add up all of the values that are stored in s1_1 through s5_5 and see if they match between two User_IDs. I have figured it out thus far:
select s.User_ID from some_data s, some_data s2 where s.User_ID='1' and s2.User_ID='2' and (this is where I'm stumped).
What would be the best way to add all those up and match between the two? I'm really really hoping that I don't have to do a where (s.s1_1+s.s1_2+s.s1_3...+s.s5_5 = s2.s1_1+s2.s1_2+s2.s1_3...+s2.s5_5). What would be nice is if I could either a) Use some sort of an alias scheme to say something like "s_total = (s.s1_1+s.s1_2+s.s1_3, etc.)" or b) Use some sort of a function to transverse through all of the columns and add them up - like a loop of sorts.
What makes matters worse is it's not an exact match either, I have to match them within + or - 5%, so it would be (aliased): where s_total <= s2_total*1.05 and s_total >= s2_total*.95
You can see where the statement could get extremely unwieldy when doing a + or - 5% match.
Any help on this would be GREATLY appreciated.
TIA
select s.User_ID from some_data s, some_data s2 where s.User_ID='1' and s2.User_ID='2' and (this is where I'm stumped).
What would be the best way to add all those up and match between the two? I'm really really hoping that I don't have to do a where (s.s1_1+s.s1_2+s.s1_3...+s.s5_5 = s2.s1_1+s2.s1_2+s2.s1_3...+s2.s5_5). What would be nice is if I could either a) Use some sort of an alias scheme to say something like "s_total = (s.s1_1+s.s1_2+s.s1_3, etc.)" or b) Use some sort of a function to transverse through all of the columns and add them up - like a loop of sorts.
What makes matters worse is it's not an exact match either, I have to match them within + or - 5%, so it would be (aliased): where s_total <= s2_total*1.05 and s_total >= s2_total*.95
You can see where the statement could get extremely unwieldy when doing a + or - 5% match.
Any help on this would be GREATLY appreciated.
TIA