SQL分组和总和声明总计

时间:2016-08-23 02:01:15

标签: mysql

我正在尝试将以下内容分组:

CLAIM #    LINE SEQ   AMNT BILLED   AMOUNT ALLOWED   AMOUNT PAID   COPAY
LA123456          1            20               18            15       3
LA123456          2            10                5             5       0
LA123456          3            50               30            30       0
MS123456          1            20               18            15       3
MS123456          2            10                5             5       0
MS123456          3            50               30            30       0

我希望看到这样的事情:

CLAIM #     AMOUNT BILLED   AMOUNT ALLOWED   AMOUNT PAID   COPAY
LA123456               80               53            50       3
MS123456               80               53            50       3

有关如何做的任何建议吗?

1 个答案:

答案 0 :(得分:0)

//The syntax is select sum(field1),sum(field2)from table_name group by field3

select sum(AMNT BILLED),sum(AMOUNT ALLOWED),sum(AMOUNT PAID),sum(COPAY) from table_name group by CLAIM

这是非常基本的

请参阅以下内容以供参考

http://www.tutorialspoint.com/mysql/mysql-sum-function.htm

http://www.mysqltutorial.org/mysql-sum/