mysql查询某些数据的最小值
Posted mentalidade
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql查询某些数据的最小值相关的知识,希望对你有一定的参考价值。
查询一些用户的首笔订单:
select a.* from tb_order as a right join
(select user_id, min(create_time) as maxtime from tb_order where user_id in(111,222,333) group by user_id) as b
on a.user_id=b.user_id and a.create_time = b.maxtime;
用如下验证,和上述sql结果匹配
select * FROM tb_order where user_id in (111) order by create_time asc limit(1);
select * FROM tb_order where user_id in (222) order by create_time asc limit(1);
select * FROM tb_order where user_id in (333) order by create_time asc limit(1);
以上是关于mysql查询某些数据的最小值的主要内容,如果未能解决你的问题,请参考以下文章