1

我有一个简单的查询,我用它来尝试理解 SQL max() over() 功能,如下所示:

select *, max(mt.version) over (partition by mt.version)
from myTable mt
where mt.id = 'some uuid';

编辑: 这个概念对我来说是新的,所以我不确定它应该做什么。我没有特定的数据集,我只是想通过提出自己的示例来了解代码在做什么。

我不明白的是我的数据集有多行。我认为 max() over(partition by x) 功能应该基于 max 函数返回单个结果。有人请解释为什么我会得到超过 1 个结果。我在另一张桌子上试过这个,它工作正常,但在另一张桌子上它不起作用。

4

1 回答 1

2

I was taking the max of mt.version and partitioning it by mt.version so I wasn't getting any new data. A correct version of what I previously wrote could be:

select *, max(mt.version) over (partition by mt.partitiongroup)
from mytable mt
where mt.id = 'some uuid';

I wasn't realizing while trying out this new concept that the partition group had to be different than the max aggregation.

于 2013-07-29T23:01:30.710 回答