I have below candidate table details
Table_TraineeInfo
TraineeID BatchId Name Mobile
--------------------------------------------------
243 45 demo201 9888562341
244 45 demo202 9888562342
246 45 demo204 9888562344
This is my batch details of above candidate have reference id 45 in both common tables
Table_Batch_Lookup
BatchId BatchStartDate BatchEndDate
------------------------------------------------------------------------
45 2019-11-27 00:00:00.000 2019-11-29 23:59:59.000
Below is my Trainee attendance log table have common between Table_TraineeInfo and Table_Attendance_Log is TraineeID
Table_Attendance_Log
TraineeID BatchId Attendance Date
------------------------------------------------------------
243 45 Present 2019-11-27 17:55:56.513
243 45 Present 2019-11-28 17:58:06.220
243 45 Absent 2019-11-29 18:00:56.820
244 45 Present 2019-11-29 18:05:03.930
246 45 Absent 2019-11-28 18:09:08.567
246 45 Present 2019-11-29 18:09:08.567
I want output like below merge the three tables and get one output as batch candidate attendance report using a SQL query or possible way.
TraineeID BatchId Name Mobile 2019-11-27 2019-11-28 2019-11-29 Score
-----------------------------------------------------------------------------------------------------------------------------
243 45 demo201 9888562341 Present Present Absent 3/2
244 45 demo202 9888562342 No Record No Record Present 3/1
246 45 demo204 9888562344 No Record Absent Present 3/1
I will explain above output first four columns will fill using Table_TraineeInfo and next dataes will fill base on BatchStartDate and BatchEndDate from Table_Batch_Lookup and Present and absent will base on Table_Attendance_Log no data availabe in attendacne list then fill no record, finally score Present will 1 value and out of 3 days.