我有两张表 一个memberinfo (会员信息 包括UserName ,qq),一个LoginIp(登录日志 包括 UserName ,logindate)。我给出一个时间点。我想列出这段时间登录的用户信息。去掉重的记录 还显示最后一次登录的时间,按时间排序 select * from Tb_memberinfo where F_MemberName in (select distinct[UserName] from [LoginIp] where UserName <>'游客' and F_type=1 and logindate<'20010-1-1') 该怎么改啊
From table_name
Group By col1,col2
select UserName,max(logindate) logindate from [LoginIp] where UserName <>'游客' and F_type=1 and cast( logindate as varchar(50))<'20010-1-1' group by UserName
From table_name
Group By col1,col2
感觉这个不错,简洁明了
(select [UserName],max(logindate) from [LoginIp] where UserName <>'游客'
and F_type=1 and logindate<'20010-1-1') b on a.F_MemberName=b.[UserName]试试吧,这分,跟白捡的一样
选择列表中的列 'LoginIp.UserName' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
消息 8155,级别 16,状态 2,第 1 行
没有为 'b' 的列 2 指定任何列。
消息 207,级别 16,状态 1,第 1 行
列名 'logindate' 无效。
,Max([logindate]) as time1
FROM LoginIp
group by username
order by time1
select * from (select max(Convert(datetime,logindate)) as logintime,UserName from [loginIp] where UserName <>'游客' and F_type=1 and datediff(d,logindate,'2010-1-1')>0 group by UserName) a inner join Tb_memberinfo b on a.UserName=b.F_MemberName这条语句应该可以满足你的要求。