简体   繁体   中英

Lock the users who are not logged to system more than 90 days

I have a requirement to lock the password(Login table) field of the Login_Id(Login Table) not logged to the system for more than 90 days. For that I have multiple Login_Date(Login_History table) for each login_id. I need to select the most recent login_date and compare if it is less than 90 days.

I have this query -

UPDATE a
SET a.password = 'LOCKED'
FROM login a, login_history b 
WHERE a.password != 'LOCKED'
AND b.login_date in (SELECT max(login_date) FROM login_history WHERE a.login_id = login_id HAVING max(login_date) < sysdate - 90);

I am not able to update the record and getting error.

You can try

UPDATE login 
SET password = 'LOCKED'
WHERE password != 'LOCKED'
AND login_id in ( SELECT b.login_id from login_history b group by b.login_id HAVING 
 max(b.login_date) < sysdate - 90 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM