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
Mi mesa se parece a esto. Me gustaría saber cómo seleccionar el valor máximo para cada bomba.
select a.name, value from out_pumptable as a,
(select name, max(value) as value from out_pumptable where group by posnumber)g where and g.value = value
este código hace el trabajo, pero obtengo dos entradas de la Bomba 1 ya que tiene dos entradas con el mismo valor.

GROUP BY. En estricto,GROUP BYtodas las columnas de suSELECTdeben aparecer en suGROUP BYo usarse en una función agregada.SELECT b.name, MAX(b.value) as MaxValue, MAX(b.Anothercolumn) as AnotherColumn FROM out_pumptabl INNER JOIN (SELECT name, MAX(value) as MaxValue FROM out_pumptabl GROUP BY Name) a ON a.name = b.name AND a.maxValue = b.value GROUP BY b.NameTenga en cuenta que esto sería mucho más fácil si tuviera una clave principal. Aquí hay un ejemplo
SELECT * FROM out_pumptabl c WHERE PK in (SELECT MAX(PK) as MaxPK FROM out_pumptabl b INNER JOIN (SELECT name, MAX(value) as MaxValue FROM out_pumptabl GROUP BY Name) a ON a.name = b.name AND a.maxValue = b.value)fuente
select name, value from( select name, value, ROW_NUMBER() OVER(PARTITION BY name ORDER BY value desc) as rn from out_pumptable ) as a where rn = 1fuente
id DESCelPARTITIONy envuelto esta consulta en unLEFT OUTER JOIN as grades ON grades.enrollment_id = enrollment.idy funciona perfectamente.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, AnotherColumnIntente así, funciona.
fuente
select * from (select * from table order by value desc limit 999999999) v group by v.namefuente
SELECT DISTINCT (t1.ProdId), t1.Quantity FROM Dummy t1 INNER JOIN (SELECT ProdId, MAX(Quantity) as MaxQuantity FROM Dummy GROUP BY ProdId) t2 ON t1.ProdId = t2.ProdId AND t1.Quantity = t2.MaxQuantity ORDER BY t1.ProdIdesto te dará la idea.
fuente