Given a table, Table, with columns N1, N2, N3, how can I get all combinations satisfying the condition N1 + N2 + N3 > 10?
For example, querying the table:
N1 N2 N3
Row1 1 5 4
Row2 4 4 3
Should give the result:
N1 N2 N3
Row1 4 5 4
Row2 4 4 4
Row3 4 4 3
Row3 4 5 3
How can I do this in T-SQL?
I haven’t tested it but something like this should work. Cross join will give you all the combinations and you filter them to return only those which satisfy your condition.
DISTINCTis there to filter duplicate combinations which may occur if i.e. all three columns have the same value in one row.