This is the table from which i have to find working hours of each employee on monthly basis with their location too and mainly to fetch the details based on their start and end date as input in transdate.
startdate enddate Empno transdate Location hours
03/07/2017 06/09/2018 11 02/04/2018 BAN 8
03/07/2017 06/09/2018 11 03/04/2018 BAN 8
03/07/2017 06/09/2018 11 04/04/2018 BAN 8
03/07/2017 06/09/2018 11 05/04/2018 BAN 8
03/07/2017 06/09/2018 11 06/04/2018 BAN 8
03/07/2017 06/09/2018 11 09/04/2018 BAN 8
03/07/2017 06/09/2018 11 10/04/2018 BAN 8
03/07/2017 06/09/2018 11 11/04/2018 BAN 8
03/07/2017 06/09/2018 11 12/04/2018 BAN 8
I wrote a correlated subquery but which fetches the total working hours based on their start and end date.
Expected results:
Location Empno Month Year Hours
BAN 11 Apr 2018 176
BAN 11 May 2018 176
BAN 11 Jun 2018 168
BAN 11 Jul 2018 176
BAN 11 Aug 2018 176
BAN 11 Sep 2018 176
BAN 11 Oct 2018 24
You could see the last value in Hours is only 24 because the employee left the firm in that month working only for three days.