我有一个480个值的序列。我想一次求和8个值并返回总和。对于前。可以说我有一个值序列-
let $values := ( "0.847","0.106","0.015","0.02","0.048","0.052","0.065","0.146","0.039","0.025","0.14","0.084","0.075","1.049","0.108","0.022","0.235","0.061","0.278","0.072","0.152","0.046","1.025","0.285","0.157","0.048","0.913","0.135","0.02","0.038","0.043","0.127","0.014","0.069","1.05","0.072","0.053","0.028","0.006","0.158","0.048","1.095","0.033","0.064","0.035","0.047","0.003","0.018","0.081","0.045","0.051","0.027","0.048","0.284","0.097","0.969","0.032","0.062","0.18","0.02","0.875","0.05","0.043","0.127","0.012","0.121","0.145","0.148","0.047","0.033","1.01","0.016","0.909","0.073","0.115","0.14","0.047","0.079","0.135","0.038","0.866","0.156","0.079","0.151","0.008","0.136","0.037","0.041","1.033","0.396","0.108","0.059","0.139","0.084","0.136","0.038","0.08","0.111","0.023","0.035","0.123","0.997","0.094","0.279","0.077","0.116","0.12","0.048","0.235","0.944","0.015","0.109","0.053","0.254","0.833","0.048","0.141","0.208","0.041","0.274","0.039","0.267","0.088","1.044","0.05","0.087","0.198","0.159","0.142","0.209","0.012","0.033","0.051","0.231","0.803","0.025","0.108","0.084","0.221","1.317","0.092","0.054","0.035","0.12","0.399","0.028","1.152","0.203","0.043","0.135","0.046","0.038","1.017","0.114","0.215","1.326","0.067","0.217","0.136","0.239","0.051","0.03","0.061","0.044","0.119","1.154","0.053","0.063","0.331","0.196","0.076","0.191","0.073","0.074","1.084","0.331","0.053","0.074","0.106","0.05","0.226","0.874","0.144","0.046","0.146","0.149","0.032","0.078","0.031","1.009","0.09","0.051","0.083","0.041","0.095","0.198","0.06","1.266","0.171","0.068","0.233","0.063","0.079","0.207","1.303","0.148","0.126","0.074","0.32","0.188","0.153","0.408","0.078","1.122","0.144","0.212","0.029","0.06","0.136","1.15","0.077","0.045","0.209","0.331","1.371","0.035","0.204","0.088","0.07","0.331","0.053","0.204","0.265","0.038","0.12","0.199","1.104","0.179","0.031","0.079","0.132","0.046","0.168","0.028","1.171","0.103","0.023","0.036","0.048","0.827","0.249","0.176","0.054","0.092","0.131","0.028","0.076","0.199","0.091","0.285","0.176","0.031","0.961","0.104","0.122","0.023","0.286","0.201","0.05","0.059","1.191","0.025","0.041","0.855","0.167","0.035","0.113","0.057","0.222","0.194","0.041","0.03","0.107","0.05","0.924","0.346","0.039","0.135","1.096","0.029","0.289","0.031","0.149","0.129","0.053","0.132","0.165","0.085","0.164","0.177","0.041","0.062","0.326","0.14","0.2","0.074","0.411","1.337","0.106","0.2","0.152","0.024","0.118","0.043","1.249","0.289","0.19","0.054","0.064","0.025","1.183","0.208","0.021","0.061","0.203","0.07","0.042","0.024","0.158","0.123","0.011","0.043","0.119","0.903","0.152","0.032","1.093","0.026","0.107","0.092","0.443","0.111","0.123","0.016","0.05","1.134","0.151","0.175","0.056","0.098","0.045","0.126","0.145","0.015","0.093","0.066","0.049","0.989","0.054","0.125","0.088","0.04","1.134","0.114","0.065","0.092","0.15","0.144","0.129","0.085","0.211","0.134","1.181","0.174","0.173","0.275","0.903","0.193","0.081","0.039","0.135","0.116","0.133","0.217","0.237","1.123","0.032","0.236","0.061","0.014","0.066","0.043","0.119","0.262","0.048","0.052","0.027","0.2","0.956","0.127","0.892","0.077","0.216","0.07","0.131","0.062","0.029","0.085","0.02","0.145","0.058","0.193","0.039","0.022","0.911","0.102","0.14","0.981","0.305","0.116","0.172","0.057","0.148","0.076","0.208","0.066","0.074","0.982","0.182","0.118","0.061","0.214","0.206","0.103","0.333","1.034","0.095","0.252","0.05","0.166","1.163","0.053","0.07","0.077","0.158","0.038","0.188","0.495","0.04","0.181","0.167","0.104","0.922","0.044","0.078","0.043","0.058","0.274","0.256","0.052","0.144","0.985","0.03","0.039","0.178","0.06","0.224","0.145","0.177","0.933","0.063","0.04","0.042","0.129","0.053","0.989","0.038","0.301","0.037","0.165")
我希望查询返回1到8个值的和,然后返回9到16个值,依此类推。
答案 0 :(得分:6)
MarkLogic仅部分支持XQuery 3,但是您也可以使用老式方法来实现:
let $values := ( "0.847","0.106","0.015","0.02","0.048","0.052","0.065","0.146","0.039","0.025","0.14","0.084","0.075","1.049","0.108","0.022","0.235","0.061","0.278","0.072","0.152","0.046","1.025","0.285","0.157","0.048","0.913","0.135","0.02","0.038","0.043","0.127","0.014","0.069","1.05","0.072","0.053","0.028","0.006","0.158","0.048","1.095","0.033","0.064","0.035","0.047","0.003","0.018","0.081","0.045","0.051","0.027","0.048","0.284","0.097","0.969","0.032","0.062","0.18","0.02","0.875","0.05","0.043","0.127","0.012","0.121","0.145","0.148","0.047","0.033","1.01","0.016","0.909","0.073","0.115","0.14","0.047","0.079","0.135","0.038","0.866","0.156","0.079","0.151","0.008","0.136","0.037","0.041","1.033","0.396","0.108","0.059","0.139","0.084","0.136","0.038","0.08","0.111","0.023","0.035","0.123","0.997","0.094","0.279","0.077","0.116","0.12","0.048","0.235","0.944","0.015","0.109","0.053","0.254","0.833","0.048","0.141","0.208","0.041","0.274","0.039","0.267","0.088","1.044","0.05","0.087","0.198","0.159","0.142","0.209","0.012","0.033","0.051","0.231","0.803","0.025","0.108","0.084","0.221","1.317","0.092","0.054","0.035","0.12","0.399","0.028","1.152","0.203","0.043","0.135","0.046","0.038","1.017","0.114","0.215","1.326","0.067","0.217","0.136","0.239","0.051","0.03","0.061","0.044","0.119","1.154","0.053","0.063","0.331","0.196","0.076","0.191","0.073","0.074","1.084","0.331","0.053","0.074","0.106","0.05","0.226","0.874","0.144","0.046","0.146","0.149","0.032","0.078","0.031","1.009","0.09","0.051","0.083","0.041","0.095","0.198","0.06","1.266","0.171","0.068","0.233","0.063","0.079","0.207","1.303","0.148","0.126","0.074","0.32","0.188","0.153","0.408","0.078","1.122","0.144","0.212","0.029","0.06","0.136","1.15","0.077","0.045","0.209","0.331","1.371","0.035","0.204","0.088","0.07","0.331","0.053","0.204","0.265","0.038","0.12","0.199","1.104","0.179","0.031","0.079","0.132","0.046","0.168","0.028","1.171","0.103","0.023","0.036","0.048","0.827","0.249","0.176","0.054","0.092","0.131","0.028","0.076","0.199","0.091","0.285","0.176","0.031","0.961","0.104","0.122","0.023","0.286","0.201","0.05","0.059","1.191","0.025","0.041","0.855","0.167","0.035","0.113","0.057","0.222","0.194","0.041","0.03","0.107","0.05","0.924","0.346","0.039","0.135","1.096","0.029","0.289","0.031","0.149","0.129","0.053","0.132","0.165","0.085","0.164","0.177","0.041","0.062","0.326","0.14","0.2","0.074","0.411","1.337","0.106","0.2","0.152","0.024","0.118","0.043","1.249","0.289","0.19","0.054","0.064","0.025","1.183","0.208","0.021","0.061","0.203","0.07","0.042","0.024","0.158","0.123","0.011","0.043","0.119","0.903","0.152","0.032","1.093","0.026","0.107","0.092","0.443","0.111","0.123","0.016","0.05","1.134","0.151","0.175","0.056","0.098","0.045","0.126","0.145","0.015","0.093","0.066","0.049","0.989","0.054","0.125","0.088","0.04","1.134","0.114","0.065","0.092","0.15","0.144","0.129","0.085","0.211","0.134","1.181","0.174","0.173","0.275","0.903","0.193","0.081","0.039","0.135","0.116","0.133","0.217","0.237","1.123","0.032","0.236","0.061","0.014","0.066","0.043","0.119","0.262","0.048","0.052","0.027","0.2","0.956","0.127","0.892","0.077","0.216","0.07","0.131","0.062","0.029","0.085","0.02","0.145","0.058","0.193","0.039","0.022","0.911","0.102","0.14","0.981","0.305","0.116","0.172","0.057","0.148","0.076","0.208","0.066","0.074","0.982","0.182","0.118","0.061","0.214","0.206","0.103","0.333","1.034","0.095","0.252","0.05","0.166","1.163","0.053","0.07","0.077","0.158","0.038","0.188","0.495","0.04","0.181","0.167","0.104","0.922","0.044","0.078","0.043","0.058","0.274","0.256","0.052","0.144","0.985","0.03","0.039","0.178","0.06","0.224","0.145","0.177","0.933","0.063","0.04","0.042","0.129","0.053","0.989","0.038","0.301","0.037","0.165")
let $window-size := 8
let $nr-windows := ceiling(count($values) div 8)
for $w in (1 to $nr-windows)
let $start := $window-size * ($w - 1) + 1
return sum(subsequence($values, $start, $window-size) ! xs:decimal(.))
HTH!
答案 1 :(得分:2)
在XQuery 3中,您还可以使用tumbling window
子句:
let $values := ( "0.847","0.106","0.015","0.02","0.048","0.052","0.065","0.146","0.039","0.025","0.14","0.084","0.075","1.049","0.108","0.022","0.235","0.061","0.278","0.072","0.152","0.046","1.025","0.285","0.157","0.048","0.913","0.135","0.02","0.038","0.043","0.127","0.014","0.069","1.05","0.072","0.053","0.028","0.006","0.158","0.048","1.095","0.033","0.064","0.035","0.047","0.003","0.018","0.081","0.045","0.051","0.027","0.048","0.284","0.097","0.969","0.032","0.062","0.18","0.02","0.875","0.05","0.043","0.127","0.012","0.121","0.145","0.148","0.047","0.033","1.01","0.016","0.909","0.073","0.115","0.14","0.047","0.079","0.135","0.038","0.866","0.156","0.079","0.151","0.008","0.136","0.037","0.041","1.033","0.396","0.108","0.059","0.139","0.084","0.136","0.038","0.08","0.111","0.023","0.035","0.123","0.997","0.094","0.279","0.077","0.116","0.12","0.048","0.235","0.944","0.015","0.109","0.053","0.254","0.833","0.048","0.141","0.208","0.041","0.274","0.039","0.267","0.088","1.044","0.05","0.087","0.198","0.159","0.142","0.209","0.012","0.033","0.051","0.231","0.803","0.025","0.108","0.084","0.221","1.317","0.092","0.054","0.035","0.12","0.399","0.028","1.152","0.203","0.043","0.135","0.046","0.038","1.017","0.114","0.215","1.326","0.067","0.217","0.136","0.239","0.051","0.03","0.061","0.044","0.119","1.154","0.053","0.063","0.331","0.196","0.076","0.191","0.073","0.074","1.084","0.331","0.053","0.074","0.106","0.05","0.226","0.874","0.144","0.046","0.146","0.149","0.032","0.078","0.031","1.009","0.09","0.051","0.083","0.041","0.095","0.198","0.06","1.266","0.171","0.068","0.233","0.063","0.079","0.207","1.303","0.148","0.126","0.074","0.32","0.188","0.153","0.408","0.078","1.122","0.144","0.212","0.029","0.06","0.136","1.15","0.077","0.045","0.209","0.331","1.371","0.035","0.204","0.088","0.07","0.331","0.053","0.204","0.265","0.038","0.12","0.199","1.104","0.179","0.031","0.079","0.132","0.046","0.168","0.028","1.171","0.103","0.023","0.036","0.048","0.827","0.249","0.176","0.054","0.092","0.131","0.028","0.076","0.199","0.091","0.285","0.176","0.031","0.961","0.104","0.122","0.023","0.286","0.201","0.05","0.059","1.191","0.025","0.041","0.855","0.167","0.035","0.113","0.057","0.222","0.194","0.041","0.03","0.107","0.05","0.924","0.346","0.039","0.135","1.096","0.029","0.289","0.031","0.149","0.129","0.053","0.132","0.165","0.085","0.164","0.177","0.041","0.062","0.326","0.14","0.2","0.074","0.411","1.337","0.106","0.2","0.152","0.024","0.118","0.043","1.249","0.289","0.19","0.054","0.064","0.025","1.183","0.208","0.021","0.061","0.203","0.07","0.042","0.024","0.158","0.123","0.011","0.043","0.119","0.903","0.152","0.032","1.093","0.026","0.107","0.092","0.443","0.111","0.123","0.016","0.05","1.134","0.151","0.175","0.056","0.098","0.045","0.126","0.145","0.015","0.093","0.066","0.049","0.989","0.054","0.125","0.088","0.04","1.134","0.114","0.065","0.092","0.15","0.144","0.129","0.085","0.211","0.134","1.181","0.174","0.173","0.275","0.903","0.193","0.081","0.039","0.135","0.116","0.133","0.217","0.237","1.123","0.032","0.236","0.061","0.014","0.066","0.043","0.119","0.262","0.048","0.052","0.027","0.2","0.956","0.127","0.892","0.077","0.216","0.07","0.131","0.062","0.029","0.085","0.02","0.145","0.058","0.193","0.039","0.022","0.911","0.102","0.14","0.981","0.305","0.116","0.172","0.057","0.148","0.076","0.208","0.066","0.074","0.982","0.182","0.118","0.061","0.214","0.206","0.103","0.333","1.034","0.095","0.252","0.05","0.166","1.163","0.053","0.07","0.077","0.158","0.038","0.188","0.495","0.04","0.181","0.167","0.104","0.922","0.044","0.078","0.043","0.058","0.274","0.256","0.052","0.144","0.985","0.03","0.039","0.178","0.06","0.224","0.145","0.177","0.933","0.063","0.04","0.042","0.129","0.053","0.989","0.038","0.301","0.037","0.165")
return
for tumbling window $w in $values
start at $s when $s mod 8 = 1
return sum($w!xs:decimal(.))
答案 2 :(得分:1)
添加此内容:
index.html
应该可以解决问题!