SQL query return rows to columns dynamically

25 views Asked by At

I have one table as job_status which is having columns as date, status

here is the query which i prepared

SELECT DATE_FORMAT(date,'%D %M %Y') DATE, status STATUS, 
COUNT(*) COUNT
FROM job_status
where date BETWEEN '2022-10-13 00:00:00' AND '2022-10-18 23:59:59' 
GROUP BY DATE_FORMAT(created_on,'%D %M %Y'), status

But the current results shows as

DATE    STATUS      COUNT
14-Oct  Pending     5
14-Oct  Completed   5   
14-Oct  HOLD        6   
15-Oct  Pending     1   
15-Oct  Completed   2   
15-Oct  HOLD        3   
16-Oct  Pending     4   
16-Oct  Completed   5   
16-Oct  HOLD        6   

Status can be dynamic or any other, hence i have not kept in where condition.

But i want to show the results as

STATUS      14-OCT  15-OCT  16-OCT
Pending     5       1       4
Completed   5       2       5
HOLD        5       3       6
0

There are 0 answers