I have an enquiry about MySQL statement about combining two rows in a table using sql statement. Initially, I have implemented codes to show in the data grid view the employee's shift.
LocationName | StationName | 12:00 - 13:00 | 13:00 - 14:00 | 14:00 - 15:00
T2 | Counter | Michael Joyce | Michael Joyce | Michael Joyce
As you can see, there were two employees under the same Location and Station. Next step, I'm going to use SQL statement to type out the format and eventually used the SQL statement to reportviewer.
This is the SQL statement that I tried to show to the same format as shown above.
select
z.LocationName,
z.StationName,
a.12001300,
b.13001400,
c.14001500
from (SELECT DISTINCT
LocationName,
StationName
FROM satsschema.employeeslot
where AllocationDate = '10-Aug'
and LocationName = 'T2 PML'
and StationName is not null) z
left outer join (SELECT
LocationName,
StationName,
EmpName AS '12001300'
FROM satsschema.employeeslot
WHERE Assigned = true
and AllocationDate = '10-Aug'
and (EmpTime = '12:00:00' && EmpTime < '13:00:00')) a
on z.LocationName = a.LocationName
and z.StationName = a.StationName
left outer join (SELECT
LocationName,
StationName,
EmpName AS '13001400'
FROM satsschema.employeeslot
WHERE Assigned = true
and AllocationDate = '10-Aug'
and (EmpTime = '13:00:00' && EmpTime < '14:00:00')) b
on a.LocationName = b.LocationName
and a.StationName = b.StationName
left outer join (SELECT
LocationName,
StationName,
EmpName AS '14001500'
FROM satsschema.employeeslot
WHERE Assigned = true
and AllocationDate = '10-Aug'
and (EmpTime = '14:00:00' && EmpTime < '15:00:00')) c
on b.LocationName = c.LocationName
and b.StationName = c.StationName
This SQL statement shown above showed the following results that did not match what I wanted. It shows like this:
LocationName | StationName | 12:00 - 13:00 | 13:00 - 14:00 | 14:00 - 15:00
T2 | Counter | Michael | Michael | Michael
As you can see, It only shows one employee in the Location and Station only. How could be done to the SQL statement that I could also see other employees if there were more then one inside the Location and Station. Any opinions?