我有以下select statement:
select dte, wm_concat(issue) as issues
from ((select date_a as dte, issue from t where date_a is not null) union all
(select date_b, issue from t where date_b is not null)
) di
group by dte
order by dte;
返回多个行,例如:
DTE | ISSUES
-----------+---------
01/JUN/91 | EE
01/JUN/03 | EE
01/JAN/06 | HH
01/AUG/06 | EE
01/AUG/08 | EE,HS,HE
我想将这些记录插入表中。
问题
我应该如何编写insert语句?我应该使用游标,因为似乎INSERT可以一次处理一行吗?
答案 0 :(得分:2)
使用选择作为插入的来源:
insert into some_table (dte, issues)
select dte, wm_concat(issue) as issues
from (
select date_a as dte, issue
from t
where date_a is not null
union all
select date_b, issue
from t
where date_b is not null
) di
group by dte;
无需在括号之间放置UNION的各个查询。