I had problem while executing this SQL statement in MySQL workbench. Can anyone point out the problem for me?
SELECT concat(LocationName,' - ', StationName) AS LocationStation, EmpName AS '0000-0100', EmpName AS '0100-0200', EmpName AS '0200-0300', EmpName AS '0300-0400', EmpName AS '0400-0500', EmpName AS '0500-0600', EmpName AS '0600-0700', EmpName AS '0700-0800', EmpName AS '0800-0900', EmpName AS '0900-1000', EmpName AS '1000-1100', EmpName AS '1100-1200', FROM satsschema.employeeslot
WHERE LocationName = 'T2 PML'
and AllocationDate = '10-Aug'
and (EmpTime >= '00:00:00' and EmpTime <= '12:00:00')
The above statemnt prompted me this error, “You have an error in your SQL syntax, check the manual that corresponds to your MySQL server version for the right syntax to use neat ‘FROM satsschema.employeeslot WHERE LocationName = ‘T2 PML’ and AllocationDate = ‘ at line 1.”
Secondly, Is there any other ways that could make this line shorter besides typing everything out?
EmpName AS '0000-0100', EmpName AS '0100-0200', EmpName AS '0200-0300', EmpName AS '0300-0400', EmpName AS '0400-0500', EmpName AS '0500-0600', EmpName AS '0600-0700', EmpName AS '0700-0800', EmpName AS '0800-0900', EmpName AS '0900-1000', EmpName AS '1000-1100', EmpName AS '1100-1200', FROM satsschema.employeeslot
Help will be greatly appreciated.
Remove the comma before
FROM. It causes the error.Note that the error message said exactly where was the error.
In MySQL, the
ASkeyword is optional for column aliasing, so you may writeEmpName '0000-0100'in place ofEmpName AS '0000-0100'. I don’t think there is a short solution to give more than one alias to one column as it’s really not something that is often necessary.