I have a mySQL table similar to following example :
DOC_OwnerID DOC_type DOC_start_date DOC_end_date
100 JANUARY 1/1/2017 12/31/2018
100 JANUARY 1/1/2018 12/31/2019
100 DRIVER 1/5/2018 1/4/2019
100 LICENSE 2/5/2015 2/5/2016
100 LICENSE 4/5/2018 2/5/2019
200 JANUARY 1/2/2017 1/2/2018
200 DRIVER 1/2/2018 1/2/2019
In my application logic, I need to find of any owner (DOC_OwnerID) has the three basic mandatory documents (JANUARY,DRIVER,LICENSE) per given time period. Count of 3 is necessary to show owner has three documents. (Document names are unique per time period)
For an example : OwnerID = 100, Date = 4/9/2018
true => 100 JANUARY 1/1/2018 12/31/2019
true => 100 DRIVER 1/5/2018 1/4/2019
true => 100 LICENSE 4/5/2018 2/5/2019
Should return 3 to show all three documents are valid for the given date. I could use COUNT but how am I select the records as DPC_Type is not unique.
But owner = 200 never will be true since he does not have LICENSE recorded.
I could do this in my application by reading all records for the owner. How could I do this in sql at once ?
Thanks, Pubudu