Query group by pair of column result

前端 未结 2 648
一个人的身影
一个人的身影 2021-01-15 11:15

Currently my dataset consist of 4 columns, id, status, user_id, created_date

so after a while the data can be lik

2条回答
  •  失恋的感觉
    2021-01-15 11:38

    Simple implementation over provided inputs. i have data set like:

    select id, stat[status],dater[Date], name[Name] from tablelogin
    

    Data Extraction:

    Select t1.id, t1.dater[login], t2.dater[logout], t1.name[name], datediff(day,t1.dater, t2.dater)[days] from tablelogin t1, tablelogin t2 where t1.name=t2.name and t2.id>t1.id and t2.stat='logout'
    

    you need to work on logic and control, when records grows the above query may produce different results.

提交回复
热议问题