Skip to content Skip to sidebar Skip to footer

Update Login Date With Logout Date Using Mysql And Nodejs

I have a userregister table. First i need to check for same day if there is multiple login by same catId on same day.Than i need to update the logout field with next login field va

Solution 1:

As i said in your post yesterday you can do this in full mysql with some variables:

SET @last_login:=NULL;
SET @last_user:=NULL; 
SET @last_cat:=NULL; 

UPDATE userRegister r JOIN (
SELECT name, userId, catId,  login,
if((logout is NULL) AND (@last_user=userId) AND (@last_cat=catId), @last_login, logout) as logout
, @last_login :=login as dummy_log
, @last_user:=userId as dummy_user
, @last_cat:=catId as dummy_cat
FROM userRegister 
ORDER BY userId, catId, login desc) d USING(userId, catId, login) SET r.logout = d.logout;

Post a Comment for "Update Login Date With Logout Date Using Mysql And Nodejs"