`
lixielong
  • 浏览: 15711 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

在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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics