select c.name ,d.code from 表d d,表c c where d.no3 = c.no3 and d.no1 = c.no1 and d.no2 = c.no2 union select b.name ,d.code from 表d d,表b b where d.no1 = b.no1 and d.no2 = b.no2 and d.no3 is null union select a.name ,d.code from 表d d,表a a where d.no1 = a.no1 and d.no2 is null
设计表严重不合理,假如表d记录往下递增,字段也递增,岂不是接着创建表,为什不把code与name对应起来 表e(code,name) 001 a 002 b 003 c
union
select b.name ,d.code from 表d d,表b b where d.no1 = b.no1 and d.no2 = b.no2 and d.no3 is null
union
select a.name ,d.code from 表d d,表a a where d.no1 = a.no1 and d.no2 is null
表e(code,name)
001 a
002 b
003 c