读书人

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

发布时间: 2012-07-03 13:37:43 作者: rapoo

在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

读书人网 >Mysql

热点推荐