私はStored Procedure
MySQLで書いた。
それぞれ任意の月の列で日を取得しようとしています。
以下はsql query
DELIMITER $$
DROP PROCEDURE IF EXISTS `GenerateReport`$$
CREATE
DEFINER = `FreeUser`@`localhost`
PROCEDURE `databasename`.`GenerateReport`(
IN gDate DATE,
IN gUserID VARCHAR(10)
)
BEGIN
DECLARE gStart INT;
DECLARE gDays INT;
SET gStart = 1;
SET gDays = DAY(LAST_DAY(gDate));
SELECT e.AssociateID, CONCAT(e.FirstName, ' ', e.MiddleName, ' ', e.LastName) AS `EmployeeName`, d.DesignationName,
ts.TSDate,
/* Trying to get days in column, Starts here */
loopOne: LOOP
IF gStart <= gDays THEN
gStart = gStart + 1;
case gStart IS NOT NULL THEN 'ItsDate' ELSE 'NoDate' END,
ITERATE loopOne;
END IF;
LEAVE loopOne;
END LOOP loopOne;
/* Trying to get days in column, ends here */
gStart AS `Start`, gDays AS `NoofDays`
FROM timesheet ts
LEFT JOIN employee e ON e.EmpID = ts.EmpID
LEFT JOIN designation d ON d.DesignationId = e.DEsignationID
WHERE DATE_FORMAT(ts.TSDate, '%Y-%m') = DATE_FORMAT(gDate, '%Y-%m')
GROUP BY e.AssociateID;
END$$
DELIMITER ;
望ましい出力
追加の UI 用の画像を検討してください。以下は適切な表現ではない可能性があります
----------------------------------------------------------
AssociateID | EmployeeName | DesignationName | 1 | 2 | 3 | 4 | .... | 31 | Start | gDays
---------------------------------------------------------
001 |John Carter | Dae ja | ItsDate | ItsDate| .... | ItsDate | 1 | 31
----------------------------------------------------------------------------------