只是样本表:Cus_fi。
我可以吗
SELECT SUM(dollar,euro,pound) FROM cus_fi ; in 1 query.
并像这样按年龄范围显示结果。
20 - 25 1500 410 166
26 - 30 5300 2000 584
感谢帮助学生真的很想知道。
select
round(age / 5) * 5 - 4,
round(age / 5) * 5,
SUM(dollar),
SUM(euro)
FROM TEST
GROUP BY round(age / 5)
您可以使用更多列来扩展它。见演示:http ://sqlfiddle.com/#!2/160bb/15
试试这个:
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