SQL using N-1 Dense Rank to filter out rows in dense rank N Mysql(SQL使用N-1 Dense Rank过滤掉密集秩N中的行 Mysql)
问题描述
如果我的标题不清楚,这里是我所说的一个例子.
If my title isn't clear here's an example of what I am talking about.
假设我有一张如下所示的表格:
Let's say I have a table that looks like this:
如果我将此查询应用于表:
If I apply this query to the table:
我明白了:
现在我要做的是过滤掉 X 在 X_START - X_END 范围内且 Y 在 Y_START - Y_END 范围内且 DENSE_RANK 为 n-1 的任何行
Now what I want to do is filter out any rows where X is within the range X_START - X_END AND Y is within the range Y_START - Y_END AND DENSE_RANK is n-1
所以我想要一个看起来像这样的结果:
so I'd like a result that looks like this:
我对 SQL 很陌生,所以我不太确定如何去做.提前感谢您的所有帮助!
I am pretty new to SQL so I am not too sure on how to go about this. Thank you for all help in advance!
推荐答案
使用MIN()
窗口函数来识别每个Time
的最小ID
代码> 以便在所有其他条件也满足的情况下排除该行:
Use MIN()
window function to identify the minimum ID
for each Time
so that you can exclude that row if all the other conditions are satisfied too:
请参阅演示.
这篇关于SQL使用N-1 Dense Rank过滤掉密集秩N中的行 Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!