Skip to content
Advertisement

Perform counting for lookup in SQL

I would like to perform lookup based on the number of Yes in Input.

In ID No.1, Output1 is A because it is first Yes, Output2 is B because it is second Yes. In ID No.2, Output1 is blank because Input1 is n/a, subsequent output is based on number of Yes appeared. In ID No.3, it shows counting is skipped when the Input2 is not Yes. (so Output3 is H)

Are there any way to do the recursive counting? (Or the only way to find Output3 is to list all 4 possible scenarios? (blank, from Col1, from Col2 and from Col3?)

I would be grateful if I can a way to do it recursively because I have more than 10 input columns.

Advertisement

Answer

Use CASE statement to calculate output as following:

— Update —

Try this version where I have used REGEXP_SUBSTR and CASE statement as follows:

Cheers!!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement