I have a complex mysql statement that I'm trying to write in Eloquent but I'm stuck with the sub/derived tables.
The statement works... Can anyone help with the converting to eloquent.. or point me in the write direction.
I'm beginning to think that I should write some mysql statements the delete and recreate tables and then add the tables to the queries... What makes the most sense here?????
It's basically three tables...
tblpractitioners - Name and information about practitioner
tblservicedutyscheduledprac - Hold schedule information for practitioner
tblpracsuitablepositions - Suitable positions for practitioners.
This query basically pulls up a list of practitoners that are in sevice and indicates who has served last month with an x and removes anyone how has already been placed in service for that month.
It allows you to pick someone to place in service. I just used set the values for the previous month query and current month query to test this out.
Select
tblpractitioners.id,
Concat_Ws(', ', tblpractitioners.LastName, tblpractitioners.Salutation) As PracName,
tblpractitioners.Availability,
tblpractitioners.LastServiceDate,
tblpractitioners.ServiceNotes,
tblpractitionerphones.PhoneNumber,
tblphonetypes.Description,
qryPreviousMonthService.Indicator,
tblpracsuitablepositions.PracDutiesID,
tblkuppracduties.DutyAbrv,
tblkuppracduties.DutyDesc
From
tblpractitioners Inner Join
tblpractitionerphones On tblpractitionerphones.pracid = tblpractitioners.id
And tblpractitionerphones.PhoneTypeID = tblpractitioners.PrimaryPhoneID Left Join
tblphonetypes On tblphonetypes.id = tblpractitionerphones.PhoneTypeID Left Join
(Select
tblpractitioners.id,
tblpractitioners.FirstName,
tblpractitioners.LastName,
tblservicedutyscheduledprac.pracid,
tblservicedutyscheduledprac.PRACName,
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%c") As PMonth,
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%Y") As PYear,
If(tblservicedutyscheduledprac.id Is Null, '', 'X') As Indicator
From
tblpractitioners Inner Join
tblservicedutyscheduledprac On tblservicedutyscheduledprac.pracid = tblpractitioners.id
Where
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%c") = 4 And
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%Y") = 2018) qryPreviousMonthService On
qryPreviousMonthService.id = tblpractitioners.id Left Join
(Select
tblpractitioners.id,
tblpractitioners.FirstName,
tblpractitioners.LastName,
tblservicedutyscheduledprac.ServiceDate,
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%c") As Month,
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%Y") As Year,
tblservicedutyscheduledprac.pracid,
tblservicedutyscheduledprac.PRACName
From
tblservicedutyscheduledprac Inner Join
tblpractitioners On tblservicedutyscheduledprac.pracid = prac.tblpractitioners.id
Where
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%c") = 5 And
Date_Format(tblservicedutyscheduledprac.ServiceDate, "%Y") = 2018 And
tblservicedutyscheduledprac.pracid <> 0) qrySuitablePostitionsExcludeSelected On
qrySuitablePostitionsExcludeSelected.id = tblpractitioners.id Inner Join
tblpracsuitablepositions On tblpracsuitablepositions.pracid = tblpractitioners.id Inner Join
tblkuppracduties On tblkuppracduties.id = tblpracsuitablepositions.PracDutiesID
Where
tblpractitioners.InService = 1 And
tblpracsuitablepositions.PracDutiesID = 1