Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

ms access - Compare value of rows SUM in SQL query

I would like to select the rows where OutgoingInvoice.TPP field not equals the SUM of Products.IncomingSUM where the OutgoingInvoice.ID = Products.OutgoingInvoice

I wrote this SQL query:

SELECT j.* FROM OutgoingInvoice AS j WHERE (((j.TPP)<>(select sum (jj.IncomingSUM) from Products as jj where jj.OutgoingInvoice = j.ID ) ));

It do not shows any rows, but there are some. What do I wrong?

question from:https://stackoverflow.com/questions/65545738/compare-value-of-rows-sum-in-sql-query

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could try using WHERE NOT EXISTS instead of <>

 SELECT j.* FROM OutgoingInvoice AS j 
 WHERE NOT EXISTS(((j.TPP) = (select sum (jj.IncomingSUM) from Products as jj where jj.OutgoingInvoice = j.ID ) ));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...