表1:
+------------+--------------+-----------------+
| product_id | product_name | product_type_id |
+------------+--------------+-----------------+
| 1 | 產品A | 1,2 |
| 2 | 產品B | 2,3 |
+------------+--------------+-----------------+
表2:
+-----------------+-------------------+
| product_type_id | product_type_name |
+-----------------+-------------------+
| 1 | 類別1 |
| 2 | 類別2 |
| 3 | 類別3 |
+-----------------+-------------------+:
生成以下效果:
+------------+--------------+-----------------+
| product_id | product_name | type |
+------------+--------------+-----------------+
| 1 | 產品A | 類別1,類別2 |
| 2 | 產品B | 類別2,類別3 |
+------------+--------------+-----------------+
在網上查了都是關於mysql的語句如:select product_id,product_name,group_concat(product_type_name) as type from ab,ac where instr(ab.product_type_id,ac.product_type_id) group by product_id,product_name;
可是在oracle上不能用求大神幫忙呀!
select product_id,product_name,listagg(product_type_name,',')
within group(order by product_id,product_name) as "type"
from table1,table2 group by product_id,product_name
11g方可使用
如果版本過低,使用wm_concact函數代替