SQL 08 Row Rank and Partition Filter by Rank
SQL 08 Row Rank and Partition Filter by Rank
***帮助**** 这可能是重复的,但我已经搜索了一个答案,但找不到任何结果。我做这个只是为了寻求一点帮助...
基本上,我有一个查询可以生成我的行排名并且效果很好,但我无法按地址排名过滤...
正在寻找一排。任何帮助,将不胜感激。
结果:
Andress rank aDDRESS PO.primOffInd pIDKEY
1 100 N WEST Y 1
2 300 N WEST N 1
3 500 N WEST N 1
4 600 WEST N 1
想要:下面的代码为我提供了地址排名和 4 行,我需要下面显示的内容。这是针对第 thds 行,所以我希望能够按地址排名
进行过滤
Address rank Address PO.primOffInd Pikdey
1 100 N WEST Y 1
SELECT *
FROM
(
SELECT DISTINCT RANK() OVER
(PARTITION BY A, PO ORDER BY PO, A, i, c, d, l, UI.UNIQUEID) AS AddressRank /* actual column names were obfuscated for security considerations */
... /* the rest of the query minus the order by clause */
) as T
where AddressRank = 1
order by uniqueId desc /* ui is not a valid alias here so I removed it */
顺便说一句,我假设您需要的其他列在查询中可用。我不认为 DISTINCT 会增加任何值,因为(我收集到)排名列 可能 使所有行都是唯一的。我建议删除它。
如果您只想过滤掉 rank = 1 的记录,您可以将查询包装在另一个查询中并使用 where 子句:
SELECT * FROM (
-- insert your query that generates the ranking here...
) AS t WHERE t.AddressRank = 1
***帮助**** 这可能是重复的,但我已经搜索了一个答案,但找不到任何结果。我做这个只是为了寻求一点帮助...
基本上,我有一个查询可以生成我的行排名并且效果很好,但我无法按地址排名过滤...
正在寻找一排。任何帮助,将不胜感激。 结果:
Andress rank aDDRESS PO.primOffInd pIDKEY
1 100 N WEST Y 1
2 300 N WEST N 1
3 500 N WEST N 1
4 600 WEST N 1
想要:下面的代码为我提供了地址排名和 4 行,我需要下面显示的内容。这是针对第 thds 行,所以我希望能够按地址排名
进行过滤 Address rank Address PO.primOffInd Pikdey
1 100 N WEST Y 1
SELECT *
FROM
(
SELECT DISTINCT RANK() OVER
(PARTITION BY A, PO ORDER BY PO, A, i, c, d, l, UI.UNIQUEID) AS AddressRank /* actual column names were obfuscated for security considerations */
... /* the rest of the query minus the order by clause */
) as T
where AddressRank = 1
order by uniqueId desc /* ui is not a valid alias here so I removed it */
顺便说一句,我假设您需要的其他列在查询中可用。我不认为 DISTINCT 会增加任何值,因为(我收集到)排名列 可能 使所有行都是唯一的。我建议删除它。
如果您只想过滤掉 rank = 1 的记录,您可以将查询包装在另一个查询中并使用 where 子句:
SELECT * FROM (
-- insert your query that generates the ranking here...
) AS t WHERE t.AddressRank = 1