Hey I have a table with the following fields:
userid
action
now, action include login and logout. Here in this table there will be multiple userids with multiple actions. Is there a way that we can retrieve the user ids whose Logins are greater than logouts?
I wrote this:
select distinct(userid), action, count(*) from usertab where action in("LOGIN", "LOGOUT") group by userid, action order by userid desc
A snippet of result is:
ROBL LOGIN 2
ROBL LOGOUT 2
RIOS LOGIN 4
RIOS LOGOUT 4
PRATI LOGIN 43
PRATI LOGOUT 37
Now I need to extract PRATI only as that user has more logins than logouts. That way, I can get only users whose logins are more than logouts. I tried using count and having but I didn't get the result.
Is there any way to do it without views?
Any answers would be appreciated.
Thanks!