I have the following database scheme:
infos (id: int, date: date, provider_id: int)
provider(id: int, type: int, name: varchar)
On any given date, I allow up to 5 different providers each having a different type. What I want is something like this:
DATE | provider.name with type = 0 | …. | … | PROVIDER.name with type = 4 |
If there is no provider with the correct type on the specified date, then there should be a null value.
I’m struggling to get this setup correctly and would like to avoid doing it later on in my php program (like looping over all results and then aggregating them there, which is possible but seems to be ugly).
I’m using MySQL btw.
You want to do this with a simple join and aggregation: