Interview Question for Nones

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
of 0 vote

The question seems incomplete, and I would prefer to log the session id for ease of request.

with userlog as (select ul.*,
                        rank() over (partition by, ul.event order by, ul.event, ul.event_time asc) as rn
                   from user_log ul
      ,u1.event_time login_time
      ,isnull(u2.event_time, getdate()) out_time
	  ,case when u2.event_time is null then 'online' else '-' end status
	  ,datediff(minute, u1.event_time, isnull(u2.event_time, getdate())) spend_time_in_m
	  ,datediff(minute, u1.event_time, isnull(u2.event_time, getdate()))/60 spend_time_in_h
	  ,(sum(datediff(minute, u1.event_time, isnull(u2.event_time, getdate()))) over (partition by order by as sum_spend_time
  from userlog u1 left join userlog u2 on = and u1.rn = u2.rn and u2.event = 'out'
 where u1.event = 'login'
 order by 1

- jk August 20, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

select A,(la - c) as total_time_spend from (select A,B,c,lag(c,1) over (partition by A order by A) as la from t4 ) where la is not null;


with exp as ( select A,max(c) as logout,min(c) as login from t4 group by A)
SELECT A,(logout - login) as total_spent_time from exp;


with exp as (
select a,max(c) as logout,min(c) as login from t4 group by a order by a
select a, (logout - login) as total_time_spend from exp;

Here A is name, B is event, C is event time

- sriharsha.vemuri31 August 24, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

This query gives the hours spent per user per day.

with cte as

( select name,event,time,row_number() over(partition by date(event_time), name order by event_time) as rnm from table)

select,date(a.event_time),sum(datediff(hr,b.event_time,a.event_time)) from cte a join cte b on a.rnm=b.rnm-1 and a.event='login' group by,date(a.event_time)


- Anonymous February 29, 2020 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More