Created
April 22, 2016 05:29
-
-
Save MahbbRah/5a837dd407af646c494590cce668294a to your computer and use it in GitHub Desktop.
How to convert this in php query ?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
SET @sql = NULL; | |
SELECT | |
GROUP_CONCAT(DISTINCT | |
CONCAT( | |
'max(CASE WHEN ca.date = ''', | |
date_format(date, '%Y-%m-%d'), | |
''' THEN coalesce(p.status, ''P'') END) AS `', | |
date_format(date, '%Y-%m-%d'), '`' | |
) | |
) INTO @sql | |
FROM calendar | |
where date>='2013-06-01' | |
and date <= '2013-06-05'; | |
SET @sql | |
= CONCAT('SELECT ca.studentname, | |
ca.rollno, | |
ca.class, ', @sql, ' | |
from | |
( | |
select c.date, a.studentname, a.rollno, a.class | |
from calendar c | |
cross join tbl_admission a | |
) ca | |
left join tbl_absentees p | |
on ca.rollno = p.rollno | |
and ca.date = p.date | |
where ca.date>=''2013-06-01'' | |
and ca.date <= ''2013-06-05'' | |
group by ca.studentname, ca.rollno, ca.class | |
order by ca.rollno'); | |
PREPARE stmt FROM @sql; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment