我得到的查询工作正常:
SELECT Course, Period, Room, Location, TeacherId, GROUP_CONCAT(StudentId) as Students
FROM cursosv2
GROUP BY Course, Period, Room, Location, TeacherID;
我想要的(可能太基本)是在结果查询中有一个新列,例如NEW COLUMN A,其中包含句点+ room +'final'的连接值。但我一直在例外。不知道真正的原因。
我在尝试什么...
SELECT Course, Period, Room, Period+' '+Room+' Final' as test, Location, TeacherId, GROUP_CONCAT(StudentId) as Students
FROM cursosv2
GROUP BY Course, Period, Room, Location, TeacherID;
感谢。
答案 0 :(得分:1)
您还应该使用concat进行字符串连接(而非+)并添加到
组{{1}}
答案 1 :(得分:0)
您可以使用CONCAT_WS来实现这一目标。
('',Column1,column2)AS column_name
SELECT Course, Period, Room, concat_ws(' ', Room, Period) AS roomperiod, Location, TeacherId, GROUP_CONCAT(StudentId) as Students FROM cursosv2 GROUP BY Course, Period, Room, Location, TeacherID;
https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_concat-ws
答案 2 :(得分:0)
使用concat
连接而不是+
。并将test
添加到group by
子句:
SELECT Course, Period, Room, concat(Period,' ',Room,' Final') as test,
Location, TeacherId, GROUP_CONCAT(StudentId) as Students
FROM cursosv2
GROUP BY Course, Period, Room, test, Location, TeacherID;