试图找到一种简单的方法在表的两列中插入一些重复值,类似于rep
-中的R
函数
例如,我需要插入两个值(巧克力和香草,每个4次),并且我需要插入4种重复两次的值,例如-
flavor_type schedule_type
chocolate weekly
chocolate monthly
chocolate quarterly
chocolate yearly
vanilla weekly
vanilla monthly
vanilla quarterly
vanilla yearly
答案 0 :(得分:4)
您可以使用cross join
:
select *
from (values('chocolate'), ('vanilla')) flavor(flavor_type)
cross join (values('weekly'), ('monthly'), ('quarterly'), ('yearly')) schedule(schedule_type)
输出:
flavor_type schedule_type
----------- -------------
chocolate weekly
chocolate monthly
chocolate quarterly
chocolate yearly
vanilla weekly
vanilla monthly
vanilla quarterly
vanilla yearly