× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I think the following script properly mimics the given scenario, and hopefully provides the proper DELETE statement logic:

create table qtemp.batchdet (doc_nr int, batch_nr int, amount int)
;
insert into qtemp.batchdet values
(1, 1, 100), (1, 1, -100), (1, 2, 100), (1, 2, -120), (3, 4, 100)
;
delete from qtemp.batchdet m
where exists (select 1 from qtemp.batchdet s
where m.doc_nr = s.doc_nr and m.batch_nr = s.batch_nr
group by s.doc_nr, s.batch_nr having sum(s.amount)=0 )
;
select * from qtemp.batchdet
DOC_NR BATCH_NR AMOUNT
1 2 100
1 2 120-
3 4 100
******** End of data ********

Regards, Chuck

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.