如何用MYSQL筛选出符合条件的记录?

Sidyhe 2016-01-05 12:21:34
表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到底是怎么运作的, 求解
...全文
449 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sidyhe 2016-01-05
  • 打赏
  • 举报
回复
引用 1 楼 benluobobo 的回复:
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)
谢谢, 也没有其他人帮助, 分都给你吧.
benluobo 2016-01-05
  • 打赏
  • 举报
回复
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)

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧