0

My table in oracle database is like this:

Rollno | mark1 | Mark2 | mark3 --------+-----------+-----------+--------+ 101 | 10 | 20 | 30 102 | 22 | 44 | 08 103 | 55 | 11 | 14 --------+-----------+-----------+--------+ 

And I want output like

Rollno | MAX(Mark1,mark2,mark3) --------+-------------------------+ 101 | 30 102 | 44 103 | 55 --------+-------------------------+ 

Any query suggestion?

2
  • 2
    Which dbms? Some products have a GREATEST function. NULL possible? Commented Jun 12, 2015 at 9:10
  • Use the greatest function Commented Jun 12, 2015 at 9:19

2 Answers 2

4

Use GREATEST function

SELECT Rollno, GREATEST (mark1, Mark2, mark3) AS Maxv FROM yourtable 
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, saw Oracle first after asking.
1

ANSI SQL compliant answer, written before Oracle was specified:

Use CASE to find largest column value:

select Rollno, case when mark1 > mark2 and mark1 > mark3 then mark1 when mark2 > mark3 then mark2 else mark3 end as max_value from tablename 

(NULL's not considered here.)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.