有没有办法计算GROUP_CONCAT内的值?
例如,这是我的查询:
$realIP = file_get_contents("http://ipecho.net/plain");
给出了这个输出:
我希望SELECT users.*,
GROUP_CONCAT(written.score separator ' - ') as Wscore,
student_subject.*
FROM users
JOIN written ON users.idnumber=written.idnumber
JOIN student_subject ON users.idnumber=student_subject.idnumber
WHERE
student_subject.teacher='$login_session'
AND student_subject.section='$section'
AND student_subject.level='$level'
AND student_subject.year='$year'
AND student_subject.subject='$subject'
GROUP BY users.idnumber
列填充TOTAL
值的总和。
表'表'看起来像:
答案 0 :(得分:0)
我找到了解决问题的查询:
SELECT users.*,
GROUP_CONCAT(written.score separator ' - ') as Wscore,
student_subject.*,
SUM(written.score) as total
FROM users
JOIN written ON users.idnumber=written.idnumber
JOIN student_subject ON users.idnumber=student_subject.idnumber
WHERE
student_subject.teacher='$login_session'
AND student_subject.section='$section'
AND student_subject.level='$level'
AND student_subject.year='$year'
AND student_subject.subject='$subject'
GROUP BY users.idnumber
关键更改是将SUM(written.score) as total
添加到选择列表中。它产生了正确的结果: