I have a table named rjs_attendance with following four column
_________________________________________________
|attenedance_id | admin_id | note | created_date|
-------------------------------------------------
A user can make attendance several times in a day. Odd entry is assumed as sign in and even entry is assumed as sign out. The output I need looks something like this.
_______________________________________________________________________________
|admin_id | time_in | time_in_note | time_out | time_out_note | date |
-------------------------------------------------------------------------------
|1 |10:00 | none | 11:00 | none | 2015-12-24|
-------------------------------------------------------------------------------
|1 |11:30 |none |12:15 |none | 2015-12-24|
-------------------------------------------------------------------------------
I'm not able to fetch all record of the same date, but I'm able to fecth one record of the same date. The query I have run is as follows:
SELECT
`atd_in`.`admin_id` AS `admin_id`,
CAST(MIN(`atd_in`.`created_date`) AS TIME) AS `time_in`,
`atd_in`.`note` AS `time_in_note`,
CAST(MAX(`atd_out`.`created_date`) AS TIME) AS `time_out`,
`atd_out`.`note` AS `time_out_note`,
CAST(`atd_in`.`created_date` AS DATE) AS `date_on`
FROM
`zf2`.`rjs_attendance` `atd_in`
LEFT JOIN `zf2`.`rjs_attendance` `atd_out`
ON
`atd_in`.`admin_id` = `atd_out`.`admin_id`
AND CAST(`atd_in`.`created_date` AS DATE) = CAST(`atd_out`.`created_date` AS DATE)
AND `atd_in`.`attendance_id` <> `atd_out`.`attendance_id`
GROUP BY
CAST(`atd_in`.`created_date` AS DATE), `atd_in`.`admin_id`
Any help is greatly appreciated.