在MySQL中查询满足两个字段最小值的记录
在做项目的过程中,我遇到了一个查询数据库的问题。。。
就是项目需要查询一个表中的一条记录
而这条记录需要同时满足的条件就是:价格最低、以及时间最早
我写的SQL语句如下:
--竞拍信息表
CREATE TABLE customerauction(
id int primary key auto_increment,
phone varchar(20) not null,
auctionprice double(4,2) not null,
isbn varchar(20) not null,
userauctiondate datetime not null
);
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('1',2.0,'sdsdsds','1908-04-05 09:29:09');
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('2',2.0,'sdsdsds','1908-04-05 09:29:09');
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('8',1.0,'sdsdsds','1908-04-05 09:29:09');
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('3',1.0,'sdsdsds','1908-04-05 09:39:09');
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('4',1.0,'sdsdsds','1908-04-05 09:49:09');
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('5',2.0,'sdsdsds','1908-04-05 09:59:09');
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('6',2.0,'sdsdsds','1908-04-05 09:19:09');
insert into customerauction (phone,auctionprice,isbn,userauctiondate) values('7',2.0,'sdsdsds','1908-04-05 09:09:09');
select * from customerauction;
查询语句:
select * FROM (select * from customerauction order by userauctiondate ) as aaa group by auctionprice limit 0,1;