【发布时间】:2016-05-03 17:42:18
【问题描述】:
我有一张如下图所示的表格。
我有一张有 10 列的表格,我对其中的 4 列感兴趣。 用 id、name、url、排名说 tableA。
id |name |url |ranking
--------------------------------
1 |apple |a1.com |1
2 |apple |a1.com |2
3 |apple |a1z.com |3
4 |orange |o1.com |1
5 |orange |o1.com |2
6 |apple |a1.com |4
7 |apple |a1z.com |5
8 |orange |o1z.com |6
我想要 id 为 7,6,3,2 8,5,4 的行。即对于每个组(苹果和橙色) - 排名 > max(ranking)-3 且 url 中包含 z 的所有行。
对于苹果,id 7 ,其中包含 z 的 url 的最大排名为 5
所以我想要排名 >5-3 的苹果行,即。排名大于 2。
id 为 7,6,3 的行。
同样适用于橙色组。 (id 为 8,5,4 的行)
【问题讨论】:
标签: sql subquery amazon-redshift sql-like