一张表的字段与另一张表字段的值关联
有两张表,A表,有字段:id,a1,a2,a3,...... ;B表,有字段: id,column,name。怎么查甲、乙、丙对应的A表的值
column可以重复不,不能重复的话,你就先B表列转行,然后关联查询 select B.name,
(case B.column
when 'a1' then A.a1
when 'a2' then A.a2
when 'a3' then A.a3
else 0
end) value
from A,B where A.id=B.id 这个表结构首先就感觉有点迷,不利于查询。。。 select b.name,(select case when b.column = 'a1' then a1when b.column = 'a2' then a2 when b.column = 'a2' then a2 from a where a.id = b.id) as val from b
页:
[1]