怎么样用MYSQL筛选出符合条件的记录?

MySql 码拜 8年前 (2016-02-14) 1035次浏览
表A字段
id(int)  uid(int)  type(int)  utctime(bigint) msg(text)
现要根据时间(数值,找最大的那个), 筛选出每个用户最后记录的消息(msg), 还要区分出类别(type)
本人写了一个
select * from A group by A.uid, A.type order by utctime desc
但总是找的utctime最小的那个, 即使是这样
select * from (select * from A order by A.utctime desc) B group by B.uid, B.type
还是不行, 不知道group到底是怎么运作的, 求指导
解决方案

100

select id,uid,type,utctime,msg from tableName A where not exists(select 1 from tableName B where A.type=B.type and A.utctime < B.utctime)

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么样用MYSQL筛选出符合条件的记录?
喜欢 (0)
[1034331897@qq.com]
分享 (0)