首页 > 解决方案 > 交易的最短日期

问题描述

我的要求

在此处输入图像描述

如何获取“提款”后交易的最短交易日期?

我只想要 transactiondate '2/11/2020' 的输出。

标签: sqlsql-servertsql

解决方案


您可以使用lag()和过滤和聚合:

select account, min(tdate)
from (select t.*,
             lag(type) over (partition by account order by tdate) as prev_type
      from t
     ) t
where prev_type = 'Withdrawal'
group by account;

推荐阅读