[英]INSERT repeating values in SQL
试图找到一种简单的方法在表的两列中插入一些重复值,类似于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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.