2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
2022-08-26 19:07:59 +00:00
|
|
|
|
slug: /zh/sql-reference/table-functions/numbers
|
2022-04-10 23:08:18 +00:00
|
|
|
|
sidebar_position: 39
|
|
|
|
|
sidebar_label: numbers
|
2020-04-08 14:22:25 +00:00
|
|
|
|
---
|
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
# numbers {#numbers}
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
`numbers(N)` – 返回一个包含单个 ‘number’ 列(UInt64)的表,其中包含从0到N-1的整数。
|
|
|
|
|
`numbers(N, M)` - 返回一个包含单个 ‘number’ 列(UInt64)的表,其中包含从N到(N+M-1)的整数。
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
类似于 `system.numbers` 表,它可以用于测试和生成连续的值, `numbers(N, M)` 比 `system.numbers`更有效。
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
以下查询是等价的:
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
|
|
|
|
SELECT * FROM numbers(10);
|
|
|
|
|
SELECT * FROM numbers(0, 10);
|
|
|
|
|
SELECT * FROM system.numbers LIMIT 10;
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-19 02:32:20 +00:00
|
|
|
|
示例:
|
2020-04-08 14:22:25 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
2021-03-19 02:32:20 +00:00
|
|
|
|
-- 生成2010-01-01至2010-12-31的日期序列
|
2020-04-08 14:22:25 +00:00
|
|
|
|
select toDate('2010-01-01') + number as d FROM numbers(365);
|
|
|
|
|
```
|