返回首页

gbase数据、南大通用产品文档:GBase8aNTH_VALUE

更新日期:2024年09月11日

函数说明
nth_value 函数区别于first_value 和last_value,nth_value 函数可以指定取值的偏
移量。
nth_value 函数支持两个参数,第一个参数与first_value 和last_value 完全相同;
第二个参数为偏移量,要求一个大于0 的常量参数,不支持NULL 值和字段。
示例
gbase> SELECT *, nth_value(totalamount, 2) over (partition by uname order
by dt) as nth_value from tt;
+----+------------+-------+-------------+-----------+
| id | dt
| uname | totalamount | nth_value |
+----+------------+-------+-------------+-----------+
|
2 | 2016-06-05 | A
|
148 |
135 |
|
1 | 2016-06-05 | A
|
135 |
135 |
|
4 | 2016-06-02 | B
|
153 |
120 |
|
3 | 2016-06-02 | B
|
120 |
120 |
|
5 | 2016-06-10 | B
|
198 |
120 |
|
8 | 2016-02-05 | C
|
NULL |
NULL |
|
6 | 2016-08-05 | C
|
201 |
201 |
|
9 | 2016-08-06 | C
|
NULL |
201 |
|
7 | 2016-08-09 | C
|
129 |
201 |
| 14 | 2016-07-02 | D
|
172 |
NULL |
| 13 | 2016-09-01 | D
|
165 |
165 |
| 15 | NULL
| D
|
149 |
165 |
| 10 | 2016-06-01 | NULL
|
125 |
NULL |
| 11 | 2016-07-02 | NULL
|
131 |
131 |
| 12 | 2016-08-03 | NULL
|
152 |
131 |
+----+------------+-------+-------------+-----------+
gbase> SELECT *, nth_value(totalamount, NULL) over (partition by uname
order by dt) as nth_value from tt;
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: argument[2] of
nth_value is out of range
gbase> SELECT *, nth_value(totalamount, 0) over (partition by uname order
by dt) as nth_value from tt;
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: argument[2] of
nth_value is out of range
gbase> SELECT *, nth_value('const', 2) over (partition by uname order by dt)
as nth_value from tt;
+----+------------+-------+-------------+-----------+

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
882
gbase> SELECT *, nth_value(totalamount, 2) over (partition by uname order
by dt) as nth_value from tt;
+----+------------+-------+-------------+-----------+
| id | dt
| uname | totalamount | nth_value |
+----+------------+-------+-------------+-----------+
|
2 | 2016-06-05 | A
|
148 |
135 |
|
1 | 2016-06-05 | A
|
135 |
135 |
|
4 | 2016-06-02 | B
|
153 |
120 |
|
3 | 2016-06-02 | B
|
120 |
120 |
|
5 | 2016-06-10 | B
|
198 |
120 |
|
8 | 2016-02-05 | C
|
NULL |
NULL |
|
6 | 2016-08-05 | C
|
201 |
201 |
|
9 | 2016-08-06 | C
|
NULL |
201 |
|
7 | 2016-08-09 | C
|
129 |
201 |
| 14 | 2016-07-02 | D
|
172 |
NULL |
| 13 | 2016-09-01 | D
|
165 |
165 |
| 15 | NULL
| D
|
149 |
165 |
| 10 | 2016-06-01 | NULL
|
125 |
NULL |
| 11 | 2016-07-02 | NULL
|
131 |
131 |
| 12 | 2016-08-03 | NULL
|
152 |
131 |
+----+------------+-------+-------------+-----------+
gbase> SELECT *, nth_value(totalamount, NULL) over (partition by uname
order by dt) as nth_value from tt;
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: argument[2] of
nth_value is out of range
gbase> SELECT *, nth_value(totalamount, 0) over (partition by uname order
by dt) as nth_value from tt;
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: argument[2] of
nth_value is out of range
| id | dt
| uname | totalamount | nth_value |
+----+------------+-------+-------------+-----------+
|
2 | 2016-06-05 | A
|
148 | const
|
|
1 | 2016-06-05 | A
|
135 | const
|
|
4 | 2016-06-02 | B
|
153 | const
|
|
3 | 2016-06-02 | B
|
120 | const
|
|
5 | 2016-06-10 | B
|
198 | const
|
|
8 | 2016-02-05 | C
|
NULL | NULL
|
|
6 | 2016-08-05 | C
|
201 | const
|
|
9 | 2016-08-06 | C
|
NULL | const
|
|
7 | 2016-08-09 | C
|
129 | const
|
| 14 | 2016-07-02 | D
|
172 | NULL
|
| 13 | 2016-09-01 | D
|
165 | const
|
| 15 | NULL
| D
|
149 | const
|
| 10 | 2016-06-01 | NULL
|
125 | NULL
|

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
883
gbase> SELECT *, nth_value(totalamount, 2) over (partition by uname order
by dt) as nth_value from tt;
+----+------------+-------+-------------+-----------+
| id | dt
| uname | totalamount | nth_value |
+----+------------+-------+-------------+-----------+
|
2 | 2016-06-05 | A
|
148 |
135 |
|
1 | 2016-06-05 | A
|
135 |
135 |
|
4 | 2016-06-02 | B
|
153 |
120 |
|
3 | 2016-06-02 | B
|
120 |
120 |
|
5 | 2016-06-10 | B
|
198 |
120 |
|
8 | 2016-02-05 | C
|
NULL |
NULL |
|
6 | 2016-08-05 | C
|
201 |
201 |
|
9 | 2016-08-06 | C
|
NULL |
201 |
|
7 | 2016-08-09 | C
|
129 |
201 |
| 14 | 2016-07-02 | D
|
172 |
NULL |
| 13 | 2016-09-01 | D
|
165 |
165 |
| 15 | NULL
| D
|
149 |
165 |
| 10 | 2016-06-01 | NULL
|
125 |
NULL |
| 11 | 2016-07-02 | NULL
|
131 |
131 |
| 12 | 2016-08-03 | NULL
|
152 |
131 |
+----+------------+-------+-------------+-----------+
gbase> SELECT *, nth_value(totalamount, NULL) over (partition by uname
order by dt) as nth_value from tt;
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: argument[2] of
nth_value is out of range
gbase> SELECT *, nth_value(totalamount, 0) over (partition by uname order
by dt) as nth_value from tt;
ERROR 1733 (HY000): (GBA-01EX-700) Gbase general error: argument[2] of
nth_value is out of range
| 11 | 2016-07-02 | NULL
|
131 | const
|
| 12 | 2016-08-03 | NULL
|
152 | const
|
+----+------------+-------+-------------+-----------+

TERMCAP 环境变量用于终端处理。它告诉 DB-Access(和其他基于字符的应用程序)
与 termcap 文件通信而不是与 terminfo 目录通信。

pathname 指定 termcap 文件的位置。

GBase 8s SQL 指南:参考
南大通用数据技术股份有限公司 - 196 -

termcap 文件包含各种类型的终端以及它们的特征的列表。例如,要提供 DB-Access
终端处理信息(该信息是在 /usr/gbasedbt/etc/termcap 文件中指定的),请输入以下命
令:
setenv TERMCAP /usr/gbasedbt/etc/termcap
可以下列任一方式设置 TERMCAP:如果存在若干个 termcap 文件,那么它们具有以下
优先级顺序(降序):
1.
您创建的 termcap 文件
2.
数据库服务器提供的 termcap 文件(即 $GBASEDBTDIR/etc/termcap)
3.
操作系统 termcap 文件(即,/etc/termcap)
如果设置 TERMCAP 环境变量,
应确保 GBASEDBTTERM 环境变量设置为 termcap。

如果不设置 TERMCAP 环境变量,那么在缺省情况下使用 terminfo 目录。

当 TAPEDEV 和 LTAPEDEV 指定目录时,使用 IFX_ONTAPE_FILE_PREFIX 环
境变量来指定备份文件名的前缀(替换 hostname_servernum 格式)。如果没有设置值,
那么各个等级的文件名为 hostname_servernum_Ln,而日志文件的文件名为
hostname_servernum_Log nnnnnnnnnn。
如果将 IFX_ONTAPE_FILE_PREFIX 的值设置为 My_Backup,那么备份文件名具有以下
名称:

My_Backup_L0

My_Backup_L1

My_Backup_L2

My_Backup_Log0000000001

My_Backup_Log0000000002


GBase 8s SQL 指南:参考
南大通用数据技术股份有限公司 - 176 -
string 用于备份文件名的前缀。