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
從上面我節省了費用支付細節選擇MySQL查詢不同sumof具有
一個學生作爲支付部分利用這一點,我需要獲得上述值
量總費用和總支付的費用,餘額需要支付
爲了這個,我用
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
查看https://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple- sql-query – Strawberry
SELECT fee_amount as fee,SUM(fee_paid)as paid,fee_type FROM tbl_fee A WHERE fee_user ='105' group by fee_type having fee_amount!=(SUM(fee_paid),它會解決您的問題,我認爲。 – Bharath