[PHP]
如下:
SQL> select * from t_list;
P_NO P_NAME TYPE_A TYPE_B TYPE_C
---------- ---------- ------ ------ ------
1 产品1A11B11
1 产品1
B12
1 产品1A11
1 产品1
C11
1 产品1A12
2 产品2
B22
2 产品2A21B21C21
2 产品2
B22C22
2 产品2
B23
2 产品2A22B24
3 产品3A31B31C31
3 产品3A32
3 产品3
C31
3 产品3A33 C32
14 rows selected
SQL>
SQL> select p_no,
2 p_name,
3 type_a,
4 type_b,
5 type_c
6from
7(
8selectp_no,
9
p_name,
10
decode(ma,lag(ma, 1) over(partition by p_no order by ma), null, ma) type_a,
11
decode(mb,lag(mb, 1) over(partition by p_no order by mb), null, mb) type_b,
12
decode(mc,lag(mc, 1) over(partition by p_no order by mc), null, mc) type_c
13from
14(selectp_no,
15
p_name,
16
max(ma) over(partition by p_no order by ma) ma,
17
max(mb) over(partition by p_no order by mb) mb,
18
max(mc) over(partition by p_no order by mc) mc
19from
20(select p_no,
21
p_name,
22
decode(rn1, 1, type_a, null, type_a, null) ma,
23
decode(rn2, 1, type_b, null, type_b, null) mb,
24
decode(rn3, 1, type_c, null, type_c, null) mc
25from
26(selectp_no,
27 p_name,
28 type_a,
29 type_b,
30 type_c,
31 decode(type_a, null, null, row_number() over(partition by p_no, type_a order by rownum)) rn1,
32 decode(type_b, null, null, row_number() over(partition by p_no, type_b order by rownum)) rn2,
33 decode(type_c, null, null, row_number() over(partition by p_no, type_c order by rownum)) rn3
34fromt_list))))
35where type_a is not null
36 or type_b is not null
37 or type_c is not null;
P_NO P_NAME TYPE_A TYPE_B TYPE_C
---------- ---------- ------ ------ ------
1 产品1A11B11C11
1 产品1A12B12
2 产品2A21B21C21
2 产品2A22B22
2 产品2
B23
2 产品2
B24C22
3 产品3A31B31C31
3 产品3A32 C32
3 产品3A33
9 rows selected
SQL>
[/PHP]
|