`
JAVA天地
  • 浏览: 656000 次
  • 性别: Icon_minigender_1
  • 来自: 太原
文章分类
社区版块
存档分类
最新评论

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics