27,579
社区成员
发帖
与我相关
我的任务
分享
create table t_1
(
id int,
remark varchar(20)
)
create table t_2
(
id int,
value1 char(10),
value2 int,
remark varchar(20)
)
--t_1与t_2为 1:0,或者1:1,或者1:n,有对应关系时,关联键为id
-- t_1与t_2的关系中
--当1:0时,A有效
--当1:1时,若t_2中value1 或者value2不为空,则A有效
--当1:N时,在对应的n行t_2中,若存在任何一行value1 或者value2同时为空,则A无效
--求SQL
select *,
case
when not exists (select 1 from t_2 where id=t_1.id and value1 is null and value2 is null) then 1
else 0
end
from t_1