如果我有一张这样的桌子:
VALUE OWNER
--------------
test1 owner1
test2 owner1
test3 owner1
test4 owner1
test5 owner1
test1 owner2
test3 owner2
test5 owner2
如何为 owner1 带回以下内容
test2
test4
基本上我想要owner1而不是owner2的所有结果。
提前致谢
KS
如果我有一张这样的桌子:
VALUE OWNER
--------------
test1 owner1
test2 owner1
test3 owner1
test4 owner1
test5 owner1
test1 owner2
test3 owner2
test5 owner2
如何为 owner1 带回以下内容
test2
test4
基本上我想要owner1而不是owner2的所有结果。
提前致谢
KS
select * from tablename where OWNER = 'owner1' and `value` NOT IN (
select value from tablename where OWNER = 'owner2')
例如:
WITH my_data AS
(SELECT 'test1' AS value, 'owner1' AS owner FROM dual
UNION ALL SELECT 'test2' AS value, 'owner1' AS owner FROM dual
UNION ALL SELECT 'test3' AS value, 'owner1' AS owner FROM dual
UNION ALL SELECT 'test4' AS value, 'owner1' AS owner FROM dual
UNION ALL SELECT 'test5' AS value, 'owner1' AS owner FROM dual
UNION ALL SELECT 'test1' AS value, 'owner2' AS owner FROM dual
UNION ALL SELECT 'test3' AS value, 'owner2' AS owner FROM dual
UNION ALL SELECT 'test5' AS value, 'owner2' AS owner FROM dual)
SELECT
value
FROM my_data
WHERE owner = 'owner1'
MINUS
SELECT
value
FROM my_data
WHERE owner = 'owner2'
;
从 t 中选择值 where owner = 'owner1' Minus 从 t 中选择值 where owner = 'owner2'