根据mysql中的另一列收集1个元组中的最小值和3个不同列的总和

时间:2014-12-24 04:52:11

标签: mysql

我有下表

 __________________________________________________________
|             |              |             |      |       |
|OpeningAmount|PeriodicAmount|ClosingAmount|Years | Month |
-----------------------------------------------------------
| 10000       |  100         | 9900        | 2014 | 1     |
| 99000       |  100         | 9800        | 2014 | 2     |
| 98000       |  100         | 9700        | 2014 | 3     |
| 97000       |  100         | 9600        | 2014 | 4     |
| 10000       |  100         | 9900        | 2015 | 1     |
| 99000       |  100         | 9800        | 2015 | 2     |
| 98000       |  100         | 9700        | 2015 | 3     |
| 97000       |  100         | 9600        | 2015 | 4     |
-----------------------------------------------------------

我需要关注表格

 ____(MAX)_______(SUM)___________(MIN)_____________
|             |              |             |      |
|OpeningAmount|PeriodicAmount|ClosingAmount|Years |
---------------------------------------------------
| 10000       |  400         | 9600        | 2014 |
| 10000       |  400         | 9600        | 2015 |
---------------------------------------------------

请帮我在Mysql中处理它

2 个答案:

答案 0 :(得分:0)

select max(OpeningAmount),sum(PeriodicAmount),min(ClosingAmount),Years 
from YOUR_TABLE_NAME_GOES_HERE group by Years;

答案 1 :(得分:0)

select max(OpeningAmount),
SUM(PeriodicAmount),
MIN(ClosingAmount),
Years
from MyTable
GROUP BY 
Years