Perdonar por seguir el OT.
Hacerlo en mysql creo que no es tan dificil. Siempre y cuando no se me
olvide algo. o pase algo por alto.
Yo lo harÃa asÃ:
mysql> create database test33;
Query OK, 1 row affected (0.00 sec)
mysql> use test33;
Database changed
mysql> create table products(id INT, name VARCHAR(256),price INT,
PRIMARY
KEY(id,name));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into products VALUES (1, “camion”, 100), (2, “coche”, 50),
(3,“moto”,25), (4,“camion”,20),(5,“coche”,40);Query OK, 5 rows affected
(0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select name,min(price) as price from products group by name;
±-------±------+
| name | price |
±-------±------+
| camion | 20 |
| coche | 40 |
| moto | 25 |
±-------±------+
3 rows in set (0.00 sec)
mysql> select * from (select name,min(price) as price from products
group by
name) as prices JOIN products USING(name,price);
±-------±------±—+
| name | price | id |
±-------±------±—+
| moto | 25 | 3 |
| camion | 20 | 4 |
| coche | 40 | 5 |
±-------±------±—+
3 rows in set (0.00 sec)
Ahora bien, como se hace eso en rails… Ni idea, probablemente usando
un
map en el resultado del minimun(:group => …)