我可能会将其作为内部连接而不是存在,但我希望你的工作。
SELECT A.*
FROM TABLE_A A
INNER JOIN TABLE_B B
ON A.SID = B.SID
AND A.SDAY = B.SDAY
AND A.DATETIME <> B.DATETIME
如果您仍然没有得到结果,可以尝试发布一些示例数据供我们测试
您可以运行的完整测试以显示上述连接有效:
CREATE TABLE #Table_a
(
[SID] INT,
SDAY CHAR,
[DATETIME] DATETIME
)
CREATE TABLE #Table_b
(
[SID] INT,
SDAY CHAR,
[DATETIME] DATETIME
)
INSERT INTO #Table_a
( SID, SDAY, DATETIME )
VALUES ( 0, -- SID - int
'A', -- SDAY - char
'2012-12-27 23:00:01' -- DATETIME - datetime
)
INSERT INTO #Table_a
( SID, SDAY, DATETIME )
VALUES ( 2, -- SID - int
'B', -- SDAY - char
'2012-12-27 23:00:01' -- DATETIME - datetime
)
INSERT INTO #Table_a
( SID, SDAY, DATETIME )
VALUES ( 3, -- SID - int
'C', -- SDAY - char
'2012-12-27 23:00:01' -- DATETIME - datetime
)
INSERT INTO #Table_B
( SID, SDAY, DATETIME )
VALUES ( 0, -- SID - int
'A', -- SDAY - char
'2012-12-27 3:00:01' -- DATETIME - datetime
)
INSERT INTO #Table_B
( SID, SDAY, DATETIME )
VALUES ( 2, -- SID - int
'B', -- SDAY - char
'2012-12-27 3:00:01' -- DATETIME - datetime
)
INSERT INTO #Table_B
( SID, SDAY, DATETIME )
VALUES ( 3, -- SID - int
'C', -- SDAY - char
'2012-12-27 23:00:01' -- DATETIME - datetime
)
SELECT A.*
FROM #TABLE_A A
INNER JOIN #TABLE_B B
ON A.SID = B.SID
AND A.SDAY = B.SDAY
AND A.DATETIME <> B.DATETIME
DROP TABLE #Table_a
DROP TABLE #Table_b