简体   繁体   中英

Exclude from result if Sum = 0

How to exclude records from the result if (+)LotQty has the same with (-)LotQty but different Transtype .

Example : from this

Docentry  Transtype  LotQty
4594      67          250.000000
4643      60         -250.000000
9253      67          100.000000
16822     60         -200.000000

to this

Docentry  Transtype  LotQty
9253      67         100.000000
16822     60        -200.000000**

Im not sure on the Group by part because of the aggregate but, you can try this:

 SELECT A.Docentry, A.Transtype, A.LotQty 
 FROM your_table as A 
 WHERE A.ItemCode IN 
    (SELECT B.ItemCode 
      FROM your_table as B 
      WHERE SUM(B.LotQty) = 0 
      GROUP BY B.ItemCode)

您可以使用ABS函数获取绝对值并进行比较。

Select * from Table T1 join Table T2 Where ABS(T1.LotQty)<>ABS(T2.LotQty)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM