Get corrosponding record Of Row in Another Column of SQL Table

前端 未结 3 1502
傲寒
傲寒 2021-01-29 06:20

I am having SQL table where the records of the employee on daily basis are stored/saved I would like to get that result in tabular format

Consider a Table As Shown Below

3条回答
  •  遇见更好的自我
    2021-01-29 06:46

    Assuming that there is at most one row of each type for each person, you can do this using conditional aggregation:

    select name,
           max(case when action = 'INTIME' then dateandtime end) as intime,
           max(case when action = 'OUTTIME' then dateandtime end) as outtime,
           max(case when action = 'LUNCH' then dateandtime end) as lunch
    from t
    group by name;
    

    If you have multiple values for a given name, I would recommend that you ask a new question with details on how to handle that situation.

提交回复
热议问题