天天看點

用SQL語句把物品按名字分組後,隻顯示價格最低的那一條記錄

如在MySQL中操作:

create table table1(id int auto_increment primary key,name varchar(50),price float default 0);

insert into table1(name,price) values('玉米',10);

insert into table1(name,price) values('大米',20);

insert into table1(name,price) values('小麥',30);

insert into table1(name,price) values('西瓜',40);

insert into table1(name,price) values('玉米',15);

insert into table1(name,price) values('大米',16);

insert into table1(name,price) values('小麥',35);

insert into table1(name,price) values('西瓜',36);

 解決方案:

select name,min(price) from table1 group by name order by price;

本文出自:馮立彬的部落格