select a.id,
b.name,
Nid=(case when a.FNType=0 then (select b1.name from table2 b1 where b1.id=a.Nid) when a.FNType=1 then (select c1.name from table3 c1 where c1.id=a.Nid) End),
a.FNType,
Pid=c.name,
Nxid=c.name
from table1 a,table2 b,table3 c
where a.Fid=b.id
and c.id=a.pid结果
id name Nid FNType Pid Nxid
---------------------------------------- ----------------------------------
1 设计 设计 0 2D设计 2D设计
2 工艺 铜公工艺 1 铜公工艺 铜公工艺(所影响的行数为 2 行)
b.name,
Nid=(case when a.FNType=0 then (select b1.name from table2 b1 where b1.id=a.Nid) when a.FNType=1 then (select c1.name from table3 c1 where c1.id=a.Nid) End),
a.FNType,
Pid=c.name,
Nxid=c.name
from table1 a,table2 b,table3 c
where a.Fid=b.id
and c.id=a.pid结果
id name Nid FNType Pid Nxid
---------------------------------------- ----------------------------------
1 设计 设计 0 2D设计 2D设计
2 工艺 铜公工艺 1 铜公工艺 铜公工艺(所影响的行数为 2 行)
Fid=b.name,
Nid=(case when a.FNType=0 then (select b1.name from table2 b1 where b1.id=a.Nid) when a.FNType=1 then (select c1.name from table3 c1 where c1.id=a.Nid) End),
a.FNType,
Pid=c.name,
Nxid=c.name
from table1 a,table2 b,table3 c
where a.Fid=b.id
and c.id=a.pid
from table1 a