如何从Sqlite中的表中获取大于0的值

时间:2016-10-06 15:12:00

标签: sql 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

在结果表中,close列有0和负velues 我希望价值大于零..

我试试这个

  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

但是这个查询没有给我结果。

1 个答案:

答案 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 
having 
  close > 0