Spanner row_number() OVER ( PARTITION BY.. ORDER BY)

问题描述

我们如何在 Google Spanner 中编写以下内容,以获取一些分析功能。如果这是不可能的任何其他替代方法来编写以下 sql

row_number() OVER ( PARTITION BY c1,c2 ORDER BY c3 DESC )

解决方法

假设 c3 是唯一的,您可以使用子查询:

select t.*,(select count(*)
        from t t2
        where t2.c1 = t.c1 and t2.c2 = t.c1 and t2.c3 >= t.c3
       ) 
from t;

这通常比窗口函数效率低得多,但在不支持它们的数据库中是可能的。