用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;

你可能感兴趣的:(sql,mysql)