Group Mysql Values

-1

Dear, I have a table with the configuration:

Tipo Medida Valor
1      0.2  5.00
1      0.4  6.00
1      0.1  5.00
1      0.3  5.00
2      0.1  3.00
2      0.2  3.00
2      0.3  5.00
2      0.4  5.00

I would like to group the values where they should contain the same type, a minimum and maximum value for this type since the value is the same. The result would be something like:

Tipo Minimo Maximo Valor
  1   0.1     0.3  5.00
  1   0.4     0.4  6.00
  2   0.1     0.2  3.00
  2   0.3     0.4  5.00

Thank you

    
asked by anonymous 02.10.2014 / 21:30

1 answer

1
Assuming your table is called "table", and your database manager supports the MIN and MAX aggregate functions (mysql and postgres support), the following query should solve your problem.

SELECT tipo, MIN(medida) AS minimo, MAX(medida) AS maximo, valor
FROM tabela
GROUP BY tipo, valor
    
02.10.2014 / 21:41