0

只是样本表:Cus_fi。

在此处输入图像描述

我可以吗

SELECT SUM(dollar,euro,pound) FROM cus_fi ; in 1 query.

并像这样按年龄范围显示结果。

   20 - 25   1500    410     166
   26 - 30   5300    2000    584

感谢帮助学生真的很想知道。

4

2 回答 2

3
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

于 2013-09-27T07:36:34.200 回答
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
于 2013-09-27T07:34:20.083 回答