declare @intervalday int; set @intervalday=3; with t as (select ROW_NUMBER() over(order by logindate) as RowID ,username,loginDate from ( select distinct UserName,CONVERT (char(10),Logindate,102) as Logindate from login) a) select UserName from t as t1 where DATEDIFF(day, t1.Logindate ,(select logindate from t as t2 where t1.RowID+@intervalday-1=T2.rowID))>@intervalday
添加一个计数的字段,每次登录时检查当前登录时间与上一次登录时间间隔,小于一天计数+1,否则清零。
这个我知道啊,现在就是要直接用SQL查询