在Databricks中使用MAX命令时遇到问题

时间:2020-08-03 10:44:59

标签: sql window-functions azure-databricks

只需运行一个简单的查询

select COL1
from ( 
    select *
    , monotonically_increasing_id() as row_id 
    from db00sparkmigration_landingzone_template.tbl_Ingestion_note_load_errors_pipes 
    ) aa
where row_id > 1 and row_id < max(row_id)

但是出现以下错误,有什么想法吗?

SQL语句中的错误:UnsupportedOperationException:无法评估表达式:max(input [1,bigint,false])

1 个答案:

答案 0 :(得分:0)

我会在这里推荐row_number()-但是您需要一列来定义行的顺序:

select col1
from ( 
    select 
        t.*,
        row_number() over(order by <ordering_col> asc)  rn_asc,
        row_number() over(order by <ordering_col> desc) rn_desc
    from db00sparkmigration_landingzone_template.tbl_Ingestion_note_load_errors_pipes t
) aa
where 1 not in (rn_asc, rn_desc)