• ID Name LoggedTime In/Out

    ---- -------- ---------------- ---------

    001 Alen 9:00 I

    002 Alice 9:43 I

    001 Alen 9:49 O

    003 Bitchel 9:54 I

    002 Alice 12:03 O

    003 Bitchel 12:04 O

    The required result is like this.

    ID Name Duration

    001 Alen 0:54

    002 Alice 2: 20

    003 Bitchel 2:10

    It's not very much information we have. Let's say there is a uniqueness of Id and In/Out, you could do something like this:

    select

    i.ID,

    i.Name,

    Duration = datediff( minute, i.LoggedTime, o.LoggedTime )

    from EmpWorkTime i

    inner join EmpWorkTime o on i.ID = o.ID and o.[In/Out] = 'O'

    where [In/Out] = 'I'