想到用group by 但它只能显示第一条,而不能显示最新一条,
想加个order by time desc,可是orber by只能加在group by后面。
有什么办法可以查询出group by的分组中,每组内的排序中最大或最小的一行数据?
想到用group by 但它只能显示第一条,而不能显示最新一条,
想加个order by time desc,可是orber by只能加在group by后面。
有什么办法可以查询出group by的分组中,每组内的排序中最大或最小的一行数据?
方案一: 通过同表子查询或联查找到最大的数据ID
<code>select * from track where id in(select max(id) from track group by target_id); or select * from track where id in(select substring_index(group_concat(id order by id desc),',',1) as maxid from track group by target_id);</code>
方案二:分两步查询,php中先查询最大ID,再通过ID数组查询列表数据
本系统经过多次升级改造,系统内核经过多次优化组合,已经具备相对比较方便快捷的个性化定制的特性,用户部署完毕以后,按照自己的运营要求,可实现快速定制会费管理,支持在线缴费和退费功能财富中心,管理会员的诚信度数据单客户多用户登录管理全部信息支持审批和排名不同的会员级别有不同的信息发布权限企业站单独生成,企业自主决定更新企业站信息留言、询价、报价统一管理,分系统查看分类信息参数化管理,支持多样分类信息,
0
select a.* from(select max(id) as id from info group by userid) b left join info a on a.id=b.id
把查询结果存起来,再取
使用order by
<code>select * from (
select (@mycnt := @mycnt + 1) as ROWNUM,name,age
from tb where AGe < 20 order by name,age
) as A where ROWNUM = 1
</code>只懂SqlServer,这个是仿照SqlServer写法的,可以试试
<code>SELECT a.id, a.user_id, a.info, a.create_time
FROM (SELECT id, user_id, info, create_time FROM tbl_user
ORDER BY user_id, create_time DESC, id DESC) a
GROUP BY a.user_id</code>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号