[英]Question on SQL Aggregation - error to show data only
I'm trying to aggregate to show the earliest rejected (case #, created_on, status, and amount) and approved rows within the same case#.我正在尝试聚合以显示同一案例中最早被拒绝的行(案例#、created_on、状态和金额)和批准的行。 When I put a min() function to return the earliest rejected transaction, it returns an error.
当我用 min() function 返回最早被拒绝的交易时,它返回一个错误。 Can anyone help?
谁能帮忙?
[raw data] [原始数据]
[expected result] [预期结果]
here is one way:这是一种方法:
select * from (
select * , rank() over (partition by case_num, status order by created_on) as rn
from tablename
) t where t.rn = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.