在开发中遇到一个问题,类似代码我编了一个,如下:select tb1.*,td.flagg from (
select 1 t1 from dual
UNION
select 2 t1 from dual
UNION
select 3 t1 from dual) tb1
left join
(select 'Y' flagg from dual) td
on exists
( select t1 from
( select 1 t1 from dual
UNION
select 2 t1 from dual) tb2
where tb1.t1 = tb2.t1)
运行结果是:
T1 FLAGG
1 Y
2 Y
3 Y期望结果是:
T1 FLAGG
1 Y
2 Y
3 null有高手能解释一下吗?
select 1 t1 from dual
UNION
select 2 t1 from dual
UNION
select 3 t1 from dual) tb1
left join
(select 'Y' flagg from dual) td
on exists
( select t1 from
( select 1 t1 from dual
UNION
select 2 t1 from dual) tb2
where tb1.t1 = tb2.t1)
运行结果是:
T1 FLAGG
1 Y
2 Y
3 Y期望结果是:
T1 FLAGG
1 Y
2 Y
3 null有高手能解释一下吗?
select tb1.*,(case when tb1.t1=tb2.t1 then 'y' else null end) from (
select 1 t1 from dual
UNION
select 2 t1 from dual
UNION
select 3 t1 from dual) tb1
left join
( select 1 t1 from dual
UNION
select 2 t1 from dual) tb2
on tb1.t1 = tb2.t1 T1 (
--------- -
1 y
2 y
3
你觉得你 exist达到效果没 完全没有啊 3都被显示出来了
select tb1.*,case when exists
( select t1 from
( select 1 t1 from dual
UNION
select 2 t1 from dual) tb2
where tb1.t1 = tb2.t1) then 'Y' else 'N' end tttt from (
select 1 t1 from dual
UNION
select 2 t1 from dual
UNION
select 3 t1 from dual) tb1谢谢各位参与