[英]get user who not login from last 30 days in sql asp.net
I want to try get record's who not logging from last 30 days. 我想尝试获取过去30天未登录的记录。 I have try and I also got the records but, that records display from the database who logging ed before 30 days. 我已经尝试过,但我也得到了记录,但是,该记录从30天之前登录ed的数据库中显示。 But I want to show, who's not logging from last 30 days from current date, which I can disable them. 但我想展示一下,谁可以从当前日期起过去30天不进行记录,可以禁用它们。
I try below query on sql 我尝试下面的SQL查询
select distinct CmsUserLogTime.UserId
from CmsUserLogTime
right join CmsUser on CmsUserLogTime.UserId = CmsUser.Id
where CmsUserLogTime.LoginLogoutTime <= DateAdd(Day, -30, GetDate())
order by 1 asc
I just want to compare from current date to last 30 days, which I can get the records. 我只想比较从当前日期到最近30天,就可以得到记录。
Thanks. 谢谢。
Using NOT IN
使用NOT IN
select
CmsUserLogTime.UserId
from CmsUserLogTime
inner join CmsUser on CmsUserLogTime.UserId = CmsUser.Id
where CmsUserLogTime.UserId in (select UserID from CmsUserLogTime group by UserID having max(LoginLogoutTime) <= dateadd(day,-30,getdate()))
Note, since you aren't returning columns from the CmsUser
table, I don't see the need to JOIN
to it, but left it in in case you actually do want columns from that table. 注意,由于您不是从CmsUser
表返回列,因此我看不到需要JOIN
,但如果您确实希望从该表中获取列, CmsUser
添加它。
Use DATEADD in your WHERE clause: 在WHERE子句中使用DATEADD:
... ...
WHERE CmsUserLogTime.LoginLogoutTime < DATEADD(day, -30, GETDATE())
You can also use abbreviation d or dd instead of day. 您也可以使用缩写d或dd代替day。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.