gpt4 book ai didi

mysql - 带求和函数的 GROUP CONCAT

转载 作者:行者123 更新时间:2023-11-30 00:25:52 25 4
gpt4 key购买 nike

我想连接我的 sum 函数的总和,请帮助我,谢谢这是我的查询:

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

最佳答案

所以只需使用concat即可。 (内部联接会更简洁。)

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

关于mysql - 带求和函数的 GROUP CONCAT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22891848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com