我有FEATURE和FEATURE_DETAILS表。 FEATURE_DETAILS可以有很多功能。
FEATURE_DETAILS
feature_deatails_id | feature_id
1 1
1 2
1 4
2 1
2 2
2 4
2 5
我在选择feature_deatails_id时遇到问题5 feature_id。所以结果应该是:
feature_deatails_id | feature_id
1 null
答案 0 :(得分:0)
这应该可以解决你的目的
with data as (
select 1 as feature_details_id, 1 feature_id from dual
union select 1,2 from dual
union select 1,4 from dual
union select 2,1 from dual
union select 2,2 from dual
union select 2,4 from dual
union select 2,5 from dual
)
select distinct feature_details_id, NULL feature_id from data
where feature_details_id not in (
select feature_details_id from data
where feature_id = 5)
;
上述查询的作用是 -
答案 1 :(得分:0)
使用NOT IN应该没问题
SELECT DISTINCT FEATURE_DETAILS_ID, NULL AS FEATURE_ID
FROM FEATURE_DETAILS
WHERE FEATURE_DETAILS_ID NOT IN (
SELECT FEATURE_DETAILS_ID FROM FEATURE_DETAILS WHERE FEATURE_ID = 5
);
答案 2 :(得分:-2)
选择feature_deatails_id,null为feature_id 来自feature_details feature_id!= 5
这应该可以解决你的目的。