我想要总结我的总和函数,请帮助我,谢谢 这是我的问题:
SELECT t1.province, t2.fullname,sum(t1.total_vote) AS total
FROM votes AS t1, candidate AS t2
WHERE t1.candidate_id = t2.id
GROUP BY t2.id, t1.province
ORDER BY t2.id
答案 0 :(得分:0)
所以只需使用concat
即可。 (并且inner join
会更整洁。)
SELECT concat(t2.fullname, ' has ', sum(t1.total_vote), ' votes in ', t1.province, '.') AS concatinated_line
FROM votes AS t1
INNER JOIN candidate AS t2 ON t1.candidate_id = t2.id
GROUP BY t2.id, t1.province
ORDER BY t2.id
答案 1 :(得分:0)
上面的答案应该是正确的,只需在SELECT:
中添加一个结束的parensSELECT concat(t2.fullname, ' has ', sum(t1.total_vote), ' votes in ', t1.province, '.') AS concatinated_line
FROM votes AS t1
INNER JOIN candidate AS t2 ON t1.candidate_id = t2.id
GROUP BY t2.id, t1.province
ORDER BY t2.id
答案 2 :(得分:0)
试试这个:
SELECT fullname , GROUP_CONCAT(cast(total as char))
FROM
(
SELECT t2.fullname fullname,sum(t1.total_vote) AS total
FROM votes AS t1, candidate AS t2
WHERE t1.candidate_id = t2.id
GROUP BY t2.id, t1.province
ORDER BY t2.id
) s