SQL Server query that asks to return to most recent date customer log in to the system -


i have interview question looks this:

table user has columns:

user_id , name , phone_num 

table userhistory has columns:

user_id , date , action 

write sql query returns name, phone number , recent date user has logged in on last 30 days (you can tell user has logged in if action field in userhistory set "logged_on").

i newbie sql , wrote query below:

select *  #temp (select user_id        user        join user_history on user.user_id = user_history.user_id)      max(datediff(day, date, getdate()) between 1 , 30  select       u.name, u.phone_number       #temp t  join      user u on u.user_id =  t.user_id 

i not provided data table, can take , shed insights on please?

a simpler version have been like:

select u.name, u.phone_num, max(date) mostrecentlogon user u join userhistory uh on u.user_id = uh.user_id uh.action = "logged_on" , uh.date >= dateadd(d, -30, getdate()) group u.name, u.phone_num 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -