示例:顶部取值
显示前 10 个收盘价及对应的成交量值:
SELECT symbol,
seq_top_pos_max(close, 10) as top_pos,
close@top_pos as "top-10-close",
volume@top_pos as "top-10-volume"
FROM Quote WHERE symbol='IBM';
symbol
top_pos{}
top-10-close{}
top-10-volume{}
------------------------------------------------------------------------------
IBM
{49, 53, 50, 52, 59,
51, 57, 54, 55, 48}
{215.800003, 215.059998, 214.919998, 213.440002, 213.300003,
213.210007, 212.360001, 212.259995, 212.080002, 212.059998}
{5505584, 3020648, 7936544, 3198577, 3752999,
3006125, 2300240, 5830566, 3031457, 3356946}
请注意,函数 seq_top_pos_max() 会返回序列 close 中 10 个最大值(前 10 大)的位置索引。要分析此输出:
- 序列 top_pos 包含了 close 序列中前 10 个值的位置索引。
- 此索引序列被投影到 close 和 volume 序列上,从而生成相应的 top-10-close 和 top-10-volume 序列。
要使用 xSQL 演示此选择语句,可以从 samples/xsql/scripts/financial 目录中运行以下命令来执行示例脚本:
x 13