table structure
=====================================================================
id |fee_amount|fee_paid|fee_type|fee_user|date | Fee_for
=====================================================================
1 | 2000 | 500 | REG | 105 | 01.02.2017 | FEB
-----------------------------------------------
2 | 2000 | 1000 | REG | 105 | 03.02.2017 | FEB
-----------------------------------------------
3 | 2000 | 500 | REG | 105 | 04.02.2017 | FEB
-----------------------------------------------
4 | 1000 | 500 | FEE | 105 | 10.03.2017 | MAR
-------------------------------------------------------------
5 | 1000 | 500 | FEE | 105 | 11.03.2017 | MAR
--------------------------------------------------------------
6 | 1000 | 1000 | FEE | 105 | 13.03.2017 | APR
从上面我保存了费用支付详细信息
一名学生将获得上述金额的部分金额
使用这个我需要获取总费用和已支付费用总额以及需要支付的余额
为此我使用了
SELECT SUM(fee_amount) as fee, SUM(fee_paid) as paid ,fee_type
FROM tbl_fee A WHERE fee_user='105'
group by fee_type
having SUM(fee_amount)!=(SUM(fee_paid)
但它越来越
6000 | 2000 | REG
2000 | 1000 | FEE
我需要得到
2000 | 2000 | REG
1000 | 1000 | FEE
最佳答案
只需使用此查询即可获取您需要的结果
SELECT fee_amount as fee, SUM(fee_paid) as paid ,fee_type FROM tbl_fee A WHERE fee_user='105' group by fee_type
关于php - 从 mysql 查询中选择不同的 sumof,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42760182/