-2

I have a table like this in mySql Database. this is an employee attendance table

Status    Date
P      2021-01-06
A      2021-01-08
P      2021-01-09
P      2021-01-10
A      2021-01-18
P      2021-01-17

I want this table in following format.

2021-01-06     2021-01-08    2021-01-09    2021-01-10     2021-01-18    2021-01-17
    P              A             P             P               A            P

How can I fix this?

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

You can use conditional aggregation:

select max(case when date = '2021-01-06' then status end) as x_20210106,
       max(case when date = '2021-01-07' then status end) as x_20210107,
       . . . 
from t;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786