dang
dang

Reputation: 2412

Select max of a column with multiple condition

I have a dataset:

variable value zip    interval score
a        10    10017  10       8
a        10    10017  10       10
a        10    10017  11       12
a        10    10017  11       8
a        10    10018  10       8
a        10    10018  10       10
a        10    10018  11       12
a        10    10018  11       8
b        10    10017  10       11
b        10    10017  10       8
b        10    10017  11       9
b        10    10017  11       8

I need to find MAX of score using Oracle SQL while taking the following into consideration:

The output of above should be:

variable value zip    interval score
a        10    10017  10       10
a        10    10017  11       12
a        10    10018  10       10
a        10    10018  11       12
b        10    10017  10       11
b        10    10017  11       9

Upvotes: 0

Views: 79

Answers (3)

Robert
Robert

Reputation: 25753

Try this:

select variable,value,zip,interval, max(score)
from tab
group by variable,value,zip,interval

Upvotes: 1

CodeNewbie
CodeNewbie

Reputation: 2091

This query should do the trick for you.

SELECT variable, value, zip, interval, max(score) score
FROM myTable
GROUP BY variable, value, zip, interval;

Upvotes: 0

SimarjeetSingh Panghlia
SimarjeetSingh Panghlia

Reputation: 2200

Try this

select variable,value,zip,interval,max(score) 
from tab
group by variable,value,zip,interval

Upvotes: 0

Related Questions