如何检查表中的列是否严格单调递增?

huangapple go评论70阅读模式
英文:

How to check whether a column in a table is strictly monotonically increasing?

问题

我想检查表中的一列是否严格单调递增。如何做到这一点?在DolphinDB中,表达式a>=prev(a)有效吗?是否有人知道为此目的而内置的函数?如果是的话,能否分享一些最佳实践?提前感谢。

英文:

I want to check whether a column in a table is strictly monotonically increasing. How can I do this? Is the expression a>=prev(a) valid in DolphinDB? Does anyone know a built-in function for this purpose? If so, can you share some best practices? Thanks in advance.

答案1

得分: 2

你可以尝试使用 isSorted,例如:

t = table(`a`b`c`a`d`e as sym, 1 3 3 5 6 7 as id)
select isSorted(id) from t // true

t = table(`a`b`c`a`d`e as sym, 4 3 3 5 6 7 as id)
select isSorted(id) from t // false
英文:

You can try isSorted, for example:

t = table(`a`b`c`a`d`e as sym, 1 3 3 5 6 7 as id)
select isSorted(id) from t // true

t = table(`a`b`c`a`d`e as sym, 4 3 3 5 6 7 as id)
select isSorted(id) from t // false

答案2

得分: 0

你的表达是正确的。为了得到最终结果:

all(a >= prev(a))

如果a中有任何NULL要小心。

英文:

You expression is OK. To get the final result:

all(a >= prev(a))

Be careful if any NULL in a.

huangapple
  • 本文由 发表于 2023年6月8日 14:15:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429068.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定