SQL文问题,高手赐教

一张表内字段name age C D E1 2 3 4 5取出来的结果为name age1 21 31 41 5
2025-12-25 05:30:12
推荐回答(3个)
回答1:

我见过
name col
1 2,3,4,5
查出
name col
1 2
1 3
1 4
1 5
的,是用正则表达式实现的:
select name, regexp(col,'[^,]+',1,level) col from table_name connect by level < 5

你的题目可以直接套用:
select name, regexp(col,'[^,]+',1,level) col from (select name ,age||','||C||','||D||','||E col) a connect by level < 5

回答2:

SQL> select * from test;

NAME AGE C D E
---- --- -- -- --
1 2 3 4 5
SQL> select name,age from test
2 union all
3 select name,c from test
4 union all
5 select name,d from test
6 union all
7 select name,e from test;

NAME AGE
---- ---
1 2
1 3
1 4
1 5

SQL>

满意请采纳

回答3:

select * from
(
select name,age from table
union all
select name,C from table
union all
select name,D from table
union all
select name,E from table
) as a
where a.name=条件
order by a.name