只是样本表:Cus_fi。
我可以吗
SELECT SUM(dollar,euro,pound) FROM cus_fi ; in 1 query.
按年龄范围显示结果。
20 - 25 1500 410 166
26 - 30 5300 2000 584
感谢学生真正想要的帮助。
答案 0 :(得分:3)
select
round(age / 5) * 5 - 4,
round(age / 5) * 5,
SUM(dollar),
SUM(euro)
FROM TEST
GROUP BY round(age / 5)
您可以使用更多列扩展它。见DEMO:http://sqlfiddle.com/#!2/160bb/15
答案 1 :(得分:1)
试试这个:
SELECT age, SUM(dollar) AS Total_Dollar, SUM(Euro) AS Total_Euro,
SUM(Pound) AS Total_Pound
FROM cus_fi GROUP BY age
编辑:
SELECT CONCAT(2*floor(age/2), '-', 2*floor(age/2) + 2) as `age_range`, SUM(dollar) AS Total_Dollar, SUM(Euro) AS Total_Euro,
SUM(Pound) AS Total_Pound
FROM cus_fi GROUP BY 1 ORDER BY age