2016-10-06 26 views
0

惠,如何從表中獲取的值大於0 SQLite中

我有客戶表

date idClient nameClient  OpenBal open Payable dr cr comPay close 

2016-10-5 CL-MK Kashif CL-MK 9000 33134 0 5000 0  0  0 
2016-10-5 CL-MK Kashif CL-MK 0  33134 0 6000 0  0  0 
2016-10-5 CL-MA Asim CL-MA -8000 33134 0  0 0  0  0 
2016-10-5 CL-MA Asim CL-MA  0  33134 0 7000 0  0  0 
2016-10-5 CL-MA Asim CL-MA  0  33134 0  0 0  0  0 
2016-10-5 CL-MW Waqar CL-MW 4000  33134 0 5000 0  0  0 
2016-10-5 CL-MW Waqar CL-MW  0  33134 0  0 0  0  0 
2016-10-5 CL-MW Waqar CL-MW  0  33134 0 8000 0  0  0 
2016-10-5 CL-MF Fahad CL-MF -7000  33134 0  0 0  0  0 
2016-10-5 CL-MF Fahad CL-MF 0  33134 0  0 0  0  0 
2016-10-5 CL-MF Fahad CL-MF 0  33134 0 10000 20000 150000 0 
2016-10-5 CL-MF Fahad CL-MF 0  33134 0  0 0  0  0 

我用這個查詢的結果來總結所有客戶端

SELECT idClient,nameMemb,min(OpenBal)as OpenBal,sum(open) as open,(min(openBal)+sum(open))as able,sum(re)as re ,sum(cr) as cr,sum(comPay)as comPay,(min(openBal)+sum(open)-sum(re)-sum(cr)+sum(comPay))as close from AddClient WHERE strftime ('%m', date) = '10' group by nameMemb 

的表中的近列有0和負數 我想得到的數值大於零..

我試試這個

SELECT idClient,nameMemb,min(OpenBal)as OpenBal,sum(open) as open,(min(openBal)+sum(open))as able,sum(re)as re ,sum(cr) as cr,sum(comPay)as comPay,(min(openBal)+sum(open)-sum(re)-sum(cr)+sum(comPay))as close from AddClient WHERE strftime ('%m', date) = '10' and close > 0 group by nameMemb 

但這個查詢不給我結果。

+0

我真的不明白你在問什麼是你想要的數據?你可以使用有(min(openBal)+ sum(open)-sum(re)-sum(cr)+ sum(comPay))> 0 –

+0

什麼在「re」列中 –

+0

還要小心保留字如open和關閉 –

回答

0

我相信你需要在你的小組之後使用having子句。就像:

SELECT 
    idClient,nameMemb,min(OpenBal)as OpenBal,sum(open) as open,(min(openBal)+sum(open))as able,sum(re)as re ,sum(cr) as cr,sum(comPay)as comPay,(min(openBal)+sum(open)-sum(re)-sum(cr)+sum(comPay))as close 
from 
    AddClient 
WHERE 
    strftime ('%m', date) = '10' 
group by 
    nameMemb 
having 
    close > 0