首页 > 解决方案 > 如何根据 SQL Server 中的条件派生新列?

问题描述

我有下表。

图像

我希望根据这些条件编写一个 SQL 查询:其中阶段是筛选,状态是状态=(选择/拒绝/删除)的数据(实际日期)的最小值作为面试日期

标签: sqlsql-server

解决方案


尝试这个

select 
    t1.stage, t1.status, t2.data 
from 
    table as t1 
inner join
    (select 
         stage, min(data) as data 
     from 
         table 
     group by 
         stage) as t2 on t1.stage = t2.stage and t1.data = t2.data

推荐阅读