我创建了以下简单 View :

CREATE VIEW cs.MyTestPO AS
SELECT ttdpur401100.t_orno
, ttdpur401100.t_item
, ttcibd001100.t_dsca
FROM ttdpur401100
    JOIN ttcibd001100 ON ttcibd001100.t_item = ttdpur401100.t_item

然后 SELECT * FROM cs.MyTestPO 返回 276376 行

如果我自己运行 select 语句
SELECT ttdpur401100.t_orno
, ttdpur401100.t_item
, ttcibd001100.t_dsca
FROM ttdpur401100
     JOIN ttcibd001100 ON ttcibd001100.t_item = ttdpur401100.t_item

它返回 277488 行

任何人都可以建议为什么 View 缺少 SELECT 语句返回的 1112 行。

最佳答案

要查看集合之间的差异,请尝试

SELECT d
d.t_orno    , d.t_item    , c.t_dsca
FROM ttdpur401100 d
   inner  JOIN ttcibd001100 c ON
c.t_item = d.t_item left outer join
cs.MyTestPO t on d.t_item = t.t_item
where
t.t_item is null

关于SQL Server VIEW 结果与 SELECT 不同,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14821263/

10-11 03:10