0

I have 3 columns with values ranging from 0.1 to 0.9. I want to create a calculated field in sql which would give an output 'Y' if any of the 3 columns has a value greater than 0.8, if not the output should be 'N'. Please see below example - Any help would be appreciated, thanks !

Table example

enter image description here

1 Answer 1

0

Many DBMS provides GREATEST() function to find a max value from given columns, so using it,

SELECT *, IF(GREATEST(col1, col2, col3) > 0.8, 'Y', 'N') AS calculated_col 
  FROM (
    SELECT 0.8 col1, 0.2 col2, 0.3 col3 UNION ALL
    SELECT 0.3, 0.3, 0.2 UNION ALL
    SELECT 0.2, 0.9, 0.5
  );

Note : you're mentioning only greater than 0.8 except equal to 0.8, so the below result looks different from yours.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.