求高手,用SQL怎样将数据表中一个条记录中的三个字段转换为多条记录?

源表:
字段1 字段2 字段3 字段4
aaa bbb ccc 50
ddd eee fff 50

转换后:
字段1 字段2
aaa 50
bbb 50
ccc 50
ddd 50
.
.
.
还是不行,用Jseven_jy的方法查出来少记录的,但还是要谢谢你.
我用Kettle的行转列工具可以实现我的要求,但我在ACCESS里运行你的SQL,结果却少记录,好像是字段1和字段3的重复项会被覆盖.

Jseven_jy的方法, UNION 的地方, 变为 UNION ALL 就可以了。
也就是:
(select 字段1, 字段4 from 源表 ) union all
(select 字段2 as 字段1, 字段4 from 源表) union all
(select 字段3 as 字段1, 字段4 from 源表)

因为使用 union ,会把重复的合并掉。
union all 不合并重复的。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-01-25
(select 字段1, 字段4 from 源表)union
(select 字段2 as 字段1, 字段4 from 源表)union
(select 字段3 as 字段1, 字段4 from 源表)

我这边测试是对的啊。。。你再试试呢。。。

希望对你有帮助。。。。。
第2个回答  2011-01-25
select
case when t2.f1 = 1 then t1.f1
when t2.f1 = 2 then t1.f2
when t2.f1 = 3 then t1.f3 end f1,
f4
from 原表 t1,
(select 1 f1 from dual
union all
select 2 f1 from dual
union all
select 3 f1 from dual) t2
相似回答