Interview Question for Nones


Country: United States
Interview Type: In-Person




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

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

with userlog as (select ul.*,
                        rank() over (partition by ul.name, ul.event order by ul.name, ul.event, ul.event_time asc) as rn
                   from user_log ul
				   )
select u1.name
      ,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 u1.name order by u1.name))/60 as sum_spend_time
  from userlog u1 left join userlog u2 on u1.name = u2.name 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.
0
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;

or

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;

or

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


Add a Comment
Name:

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

Books

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

Videos

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