首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

在MySQL中怎么查询唯一最低值

2012-07-03 
在MySQL中如何查询唯一最低值唯一最低价:就是在数据库中的所有的记录中,唯一的一个最低值。举一个例子:在数

在MySQL中如何查询唯一最低值
唯一最低价:就是在数据库中的所有的记录中,唯一的一个最低值。举一个例子:在数据库中有五个数:1、1、2、2、3。唯一最低值是3,而不是1和2。



数据库中代码~~~~

————————————————————

CREATE table toms(
id int primary key auto_increment,
name varchar(20) not null,
price int
)
drop table price1;
insert into toms values(1,'tom', 10);
insert into toms values(2,'jerry', 20);
insert into toms values(3,'mary', 10);
insert into toms values(4,'john', 30);
insert into toms values(5,'jack', 40);

insert into toms values(6,'jack', 20);




select price
   from (select all(id), price,count(*)
           from toms     
           group by price
           having count(*)=1 order by price limit 0,1 ) as aaa;



输出结果是:30

热点排行