要在一个表中查询数据,条件是uid in (1,2,3)。那么满足uid=1或者2或者3的都查询到。
如何做到每满足一个条件只取一条?
例如uid为1,2,3分别都几条,通过sql查询,只查询uid为1的第一条,uid为2的第一条,uid为3的第一条。
国微CMS企业方案基于“核心+系统+模块+插件”的架构体系,拓展性良好。能非常方便站长及企业搭建企业信息平台。 手机短信体系平台A、 每个售后问题回复,客户均可收到快捷通知短信。B、 每个货物发送,均有一个快捷短信息发给收货方。C、 每个客户均可按实际需求收到手机短信回复与问候。D、每个订单申请都会有一个快捷短信回复。E、每个代理商申请代理均可得到短信回复。
0
首先你的数据当中必须有一个id,一个uid
查询uid为1,2,3分别都几条:(假定表名为'user',表中只有两个字段,分别为id和uid)
select id,count(uid) from user group by uid having uid=1 or uid=2 or uid =3;
select * from user where uid=1 limit 1;
你可以 对查询出来的结果集 在分组 取一条
select * from tbl_name a where (select count(*) from tbl_name where uid=a.uid and id<a.id) = 1 and uid in (1,2,3)
每个条件只取一条:
select * from tt where uid in(1,2,3) group by uid ;
select a.* from table a where 1> (select count(1) from table b where a.id = b.id and a.id > b.id ) and a.uid in (1,2,3)
select top 1 * from table group by id
group by 可以实现
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号