반응형

각 그룹에서 최댓값을 뽑아내는 sql문은 아래와 같다.

Name    Value   AnotherColumn
-----------
Pump 1  8000.0  Something1
Pump 1  10000.0 Something2
Pump 1  10000.0 Something3
Pump 2  3043    Something4
Pump 2  4594    Something5
Pump 2  6165    Something6

 

1.

select name, max(value)
from out_pumptable
group by name

 

2.

select Name, Value, AnotherColumn
from out_pumptable
where Value =
(
  select Max(Value)
  from out_pumptable as f where f.Name=out_pumptable.Name
)
group by Name, Value, AnotherColumn

 

 

 

https://stackoverflow.com/questions/4510185/select-max-value-of-each-group

 

Select max value of each group

Name Value AnotherColumn ----------- Pump 1 8000.0 Something1 Pump 1 10000.0 Something2 Pump 1 10000.0 Something3 Pump 2 3043 Something4 Pump 2 4594 Something5 Pump 2 6165 Some...

stackoverflow.com

 

반응형