誤ってレコードを表示しないカウント関数。
DELIMITER $$
DROP PROCEDURE IF EXISTS `AbsentReportproctest`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `AbsentReportproctest`(IN _fromdate DATETIME, IN _todate DATETIME)
BEGIN
CREATE TEMPORARY TABLE daterange25 (dte DATE);
CREATE TEMPORARY TABLE daterange26 (dte DATE);
SET @counter := -1;
WHILE (@counter < DATEDIFF(DATE(_todate), DATE(_fromdate))) DO
INSERT INTO daterange25 VALUES (DATE_ADD(_fromdate, INTERVAL @counter:=@counter + 1 DAY));
INSERT INTO daterange26 VALUES (DATE_ADD(_fromdate, INTERVAL @counter:=@counter + 1 DAY));
END WHILE;
SELECT tp.EMPCODE, d.dte,gc.count
FROM test_prefixmaster tp
INNER JOIN(SELECT tp.EMPCODE,COUNT(*)AS count
FROM test_prefixmaster tp
JOIN daterange26 d
LEFT JOIN test_prefixtransactions tpt ON (tp.EMPCODE = tpt.empcode)
AND DATE(S_DateTime) = d.dte
WHERE tpt.empcode IS NULL
GROUP BY tp.EMPCODE) gc on tp.EMPCODE = gc.EMPCODE
JOIN daterange25 d
LEFT JOIN test_prefixtransactions tpt ON (tp.EMPCODE = tpt.empcode)
AND DATE(S_DateTime) = d.dte
WHERE tpt.empcode IS NULL;
DROP TABLE daterange25;
DROP TABLE daterange26;
END$$
DELIMITER ;