我有两个公司的带有相同“ id”的表,我需要“全选”做为减去在具体日期开具发票的特殊公司。
我尝试过减负功能,但是它在我们的ERP系统中不起作用,但是我可以使用“除外”,但是它不能按我需要的方式工作。
SELECT ad.idfirmy FROM aadresar as ad .............\\ (select all)
EXCEPT
SELECT DISTINCT f.idfirmy FROM ddoklfak as f ...... \\ (this i need minus from all sellect)
WHERE modul = 'FAV' and f.datvyst >= '<<datum_od>>' and f.datvyst <=
'<<datum_do>>') db on db.idfirmy = ad.idfirmy
对于序言,我具有“确认值193451”,该值在第二选择中,但在结果之后仍然是该值,但非常糟糕。
我需要第二个选择从第一个减去
答案 0 :(得分:0)
我建议您删除db
部分
SELECT ad.idfirmy
FROM aadresar AS ad
EXCEPT
SELECT DISTINCT f.idfirmy
FROM ddoklfak AS f
WHERE modul = 'FAV' AND f.datvyst >= '<<datum_od>>'
AND f.datvyst <= '<<datum_do>>';
或者改用NOT EXISTS
SELECT ad.idfirmy
FROM aadresar AS ad
WHERE NOT EXISTS
(
SELECT 1
FROM ddoklfak AS f
WHERE f.idfirmy = ad.idfirmy
AND modul = 'FAV'
AND f.datvyst >= '<<datum_od>>'
AND f.datvyst <= '<<datum_do>>'
);