消息:操作数应包含1列

时间:2017-03-27 20:04:19

标签: php mysql codeigniter

我在下一个代码遇到问题:

操作数应包含1列

mysql代码:

SELECT classes.id,
    concat(classes.grade_name+"/"+classes.section_name+"/"+classes.class_order) AS classname,

(SELECT sum(points)
FROM studentspoints
WHERE points_type = 1
    AND studentspoints.grade_order = classes.grade_order
    AND studentspoints.class_order = classes.class_order) AS p1,

(SELECT sum(points)
FROM studentspoints
WHERE points_type = 2
    AND studentspoints.grade_order = classes.grade_order
    AND studentspoints.class_order = classes.class_order) AS p2
FROM classes
GROUP by(grade_order,class_order)

1 个答案:

答案 0 :(得分:1)

我认为你必须使用MySQL' concat'功能如

CONCAT(classes.grade_name, "/", classes.section_name, "/", classes.class_order) as classname

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat

你也可以像这样简单地使用CONCAT_WS:

CONCAT_WS("/", classes.grade_name, classes.section_name)

https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_concat-ws