sql 如何查询用户登录表中所有用户的最后一次登录的id,时间,ip等记录

wangjgdd 2011-04-27 06:59:49
表中有多个字段,id,name,ip,logintime我想取出表中所有用户最后一次登录的记录,请大侠帮忙,谢谢
...全文
1386 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Truth is my belief 2011-09-26
  • 打赏
  • 举报
回复
CSDN里面的低手真够多的,上面各位写的SQL语句真2啊。
--小F-- 2011-04-27
  • 打赏
  • 举报
回复
select
*
from
tb t
where
logintime=(select max(logintime) from tb where name=t.name)
--小F-- 2011-04-27
  • 打赏
  • 举报
回复
select * from tb where not exists(select 1 from tb where name=t.name and logintime>t.logintime)
Shawn 2011-04-27
  • 打赏
  • 举报
回复
select b.* from
(select distinct name from tb) a
cross apply
(select top(1) * from tb where name = a.name order by logintime desc) b
Shawn 2011-04-27
  • 打赏
  • 举报
回复
select * from tb a
where not exists(select 1 from tb where name = a.name and logintime > a.logintime)

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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