4
I have this data entered in my table.
mysql> SELECT * FROM db_cotacao;
+----+------------+-------+------------+--------+---------+
| id | data | valor | validade | idforn | idativo |
+----+------------+-------+------------+--------+---------+
| 1 | 2019-02-10 | 20 | 2020-07-02 | 1 | 1 |
| 2 | 2019-02-10 | 30 | 2020-07-02 | 1 | 2 |
| 3 | 2019-02-10 | 40 | 2020-07-02 | 1 | 3 |
| 4 | 2019-02-10 | 5 | 2020-07-02 | 2 | 1 |
| 5 | 2019-02-10 | 8 | 2020-07-02 | 2 | 2 |
| 6 | 2019-02-10 | 4 | 2020-07-02 | 2 | 3 |
+----+------------+-------+------------+--------+---------+
I’d like to do a search where you can introduce me to a camp group idative with the lowest field values value.
Following use query:
mysql> SELECT idforn, idativo, MIN(valor) AS minimo FROM db_cotacao
-> GROUP BY idativo;
+--------+---------+--------+
| idforn | idativo | minimo |
+--------+---------+--------+
| 1 | 1 | 5 |
| 1 | 2 | 8 |
| 1 | 3 | 4 |
+--------+---------+--------+
Displays the lowest values correctly. But the field idforn does not correspond to the lowest values, but to the first items grouped.
Anyone can help?
Thank you very much friend. It is the first time I use the site.
– Eduardo Souza