如何复制表中的每一行并添加具有2个不同值的新列

问题描述

我有一个看起来像这样的表:

enter image description here

我想把它变成这个:

enter image description here

解决方法

我建议使用固定值列表的cross join

select p.*,p.product || v.val pk
from mytable t
cross join (
    select '20' val from dual
    union all select '50' from dual
) v
,

您可以像这样使用所有联合:

select t.product,t.qty,t.product || '20' pk from the_table t
union all
select t.product,t.product || '50' pk from the_table t;

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...