Group By中的条件求和查询Mysql

时间:2016-06-08 14:44:08

标签: mysql

我有一个包含以下架构的viewtable:

No_quotation        |period   |total_hour
001/QY-RKS/05/2016  Mar-16      21.0
001/QY-RKS/05/2016  Mar-16      21.0
002/QY-RKS/05/2016  Apr-16      18.0
002/QY-RKS/05/2016  Apr-16      18.0

我需要像这样总结表

No_quotation        |period   |total_hour
001/QY-RKS/05/2016  Mar-16      42.0
002/QY-RKS/05/2016  Apr-16      36.0

1 个答案:

答案 0 :(得分:0)

您只需对每个total_hour / No_quotation群组period列进行汇总:

SELECT No_quotation, period, SUM(total_hour) AS total_hour
FROM viewtable
GROUP BY No_quotation, period