Я получил решение для этого. Код немного длинный.
$first_day_this_month = date('Y-m-01');
$last_day_this_month = date('Y-m-t');
$sql = "SELECT eid,
GROUP_CONCAT(if(DAY(`empdates`) = 1, `attStatus`, NULL)) AS '01',
GROUP_CONCAT(if(DAY(`empdates`) = 2, `attStatus`, NULL)) AS '02',
GROUP_CONCAT(if(DAY(`empdates`) = 3, `attStatus`, NULL)) AS '03',
GROUP_CONCAT(if(DAY(`empdates`) = 4, `attStatus`, NULL)) AS '04',
GROUP_CONCAT(if(DAY(`empdates`) = 5, `attStatus`, NULL)) AS '05',
GROUP_CONCAT(if(DAY(`empdates`) = 6, `attStatus`, NULL)) AS '06',
GROUP_CONCAT(if(DAY(`empdates`) = 7, `attStatus`, NULL)) AS '07',
GROUP_CONCAT(if(DAY(`empdates`) = 8, `attStatus`, NULL)) AS '08',
GROUP_CONCAT(if(DAY(`empdates`) = 9, `attStatus`, NULL)) AS '09',
GROUP_CONCAT(if(DAY(`empdates`) = 10, `attStatus`, NULL)) AS '10',
GROUP_CONCAT(if(DAY(`empdates`) = 11, `attStatus`, NULL)) AS '11',
GROUP_CONCAT(if(DAY(`empdates`) = 12, `attStatus`, NULL)) AS '12',
GROUP_CONCAT(if(DAY(`empdates`) = 13, `attStatus`, NULL)) AS '13',
GROUP_CONCAT(if(DAY(`empdates`) = 14, `attStatus`, NULL)) AS '14',
GROUP_CONCAT(if(DAY(`empdates`) = 15, `attStatus`, NULL)) AS '15',
GROUP_CONCAT(if(DAY(`empdates`) = 16, `attStatus`, NULL)) AS '16',
GROUP_CONCAT(if(DAY(`empdates`) = 17, `attStatus`, NULL)) AS '17',
GROUP_CONCAT(if(DAY(`empdates`) = 18, `attStatus`, NULL)) AS '18',
GROUP_CONCAT(if(DAY(`empdates`) = 19, `attStatus`, NULL)) AS '19',
GROUP_CONCAT(if(DAY(`empdates`) = 20, `attStatus`, NULL)) AS '20',
GROUP_CONCAT(if(DAY(`empdates`) = 21, `attStatus`, NULL)) AS '21',
GROUP_CONCAT(if(DAY(`empdates`) = 22, `attStatus`, NULL)) AS '22',
GROUP_CONCAT(if(DAY(`empdates`) = 23, `attStatus`, NULL)) AS '23',
GROUP_CONCAT(if(DAY(`empdates`) = 24, `attStatus`, NULL)) AS '24',
GROUP_CONCAT(if(DAY(`empdates`) = 25, `attStatus`, NULL)) AS '25',
GROUP_CONCAT(if(DAY(`empdates`) = 26, `attStatus`, NULL)) AS '26',
GROUP_CONCAT(if(DAY(`empdates`) = 27, `attStatus`, NULL)) AS '27',
GROUP_CONCAT(if(DAY(`empdates`) = 28, `attStatus`, NULL)) AS '28',
GROUP_CONCAT(if(DAY(`empdates`) = 29, `attStatus`, NULL)) AS '29',
GROUP_CONCAT(if(DAY(`empdates`) = 30, `attStatus`, NULL)) AS '30',
GROUP_CONCAT(if(DAY(`empdates`) = 31, `attStatus`, NULL)) AS '31',
COUNT(if(`attStatus`='P', `attStatus`, NULL)) AS 'totalP',
COUNT(if(`attStatus`='A', `attStatus`, NULL)) AS 'totalA',
COUNT(if(`attStatus`='L', `attStatus`, NULL)) AS 'totalL'
FROM `attendance `
WHERE `empdates` BETWEEN '".$first_day_this_month."' AND '".$last_day_this_month."'
GROUP BY id";