在 SQL 中插入重复值

INSERT repeating values in SQL

试图找到一种简单的方法在我的 table 的两列中插入一些重复值,类似于 R-

中的 rep 函数

例如,我需要插入两个值(巧克力和香草,各 4 次)并且我需要插入 4 种重复两次的值,例如 --

flavor_type schedule_type
chocolate   weekly
chocolate   monthly
chocolate   quarterly
chocolate   yearly
vanilla     weekly
vanilla     monthly
vanilla     quarterly
vanilla     yearly

您可以使用 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