表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到底是怎么运作的, 求指导
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)