如何在PostgreSQL中生成一系列重复数字? [英] How can I generate a series of repeating numbers in PostgreSQL?

查看:302
本文介绍了如何在PostgreSQL中生成一系列重复数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PostgreSQL中,是否可以生成一系列重复数字?例如,我想生成数字1到10,每个数字重复3次:

In PostgreSQL, is it possible to generate a series of repeating numbers? For example, I want to generate the numbers 1 to 10, with each number repeated 3 times:

1
1
1
2
2
2
3
3
3
.. and so on.


推荐答案

您可以将其交叉加入一系列3:

You could cross join it to a series of 3:

SELECT a.n
from generate_series(1, 100) as a(n), generate_series(1, 3)

这篇关于如何在PostgreSQL中生成一系列重复数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆