gpt4 book ai didi

xquery - 使用 XQuery 获取序列中重复次数最多的元素

转载 作者:行者123 更新时间:2023-12-03 21:35:37 25 4
gpt4 key购买 nike

我有一系列的值。他们都可以是平等的……或者不是。所以使用 XQuery 我想获得序列中最频繁的项目。

let $counter := 0, $index1 := 0 
for $value in $sequence
if (count(index-of($value, $sequence)))
then
{
$counter := count(index-of($value, $sequence)) $index1 := index-of($value)
} else {}

我无法完成这项工作,所以我想我做错了什么。

在此先感谢您能给我的任何帮助。

最佳答案

使用 :

  for $maxFreq in 
max(for $val in distinct-values($sequence)
return count(index-of($sequence, $val))
)
return
distinct-values($sequence)[count(index-of($sequence, .)) eq $maxFreq]

2015 年 12 月更新 :

这明显更短,但可能效率不高:
$pSeq[index-of($pSeq,.)[max(for $item in $pSeq return count(index-of($pSeq,$item)))]]

可以为 XPath 3.1 构造最短的表达式:

enter image description here

甚至更短且可复制——使用一个字符的名字:
$s[index-of($s,.)[max($s ! count(index-of($s, .)))]]

关于xquery - 使用 XQuery 获取序列中重复次数最多的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3111544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com