次のようなテーブルアプリケーションがあるとしましょう
ApplicationId INT,
CustomerId INT,
ApplicationDate DATETIME,
IsNewCustomer BOOL
指定された日のアプリケーションのリストをIsNewCustomerフラグ (指定された CustomerId.
現在、次のように同じテーブルで結合を使用しています
select 
    o.ApplicationId as ApplicationId,
    cast(o.ApplicationDate as date) as ApplicationDate,
    case when n.ApplicationID is not null then 1 else 0 end as IsNewCustomer,
    row_number() over (partition by o.ApplicationId order by o.ApplicationDate desc) as AppSeqNum
from 
    Applications o 
    left join Applications n 
        on n.CustomerId = o.CustomerId
        and n.ApplicationDate < o.ApplicationDate
where
    AppSeqNum = 1
    and ApplicationDate = getdate()
最もエレガントなソリューションのように「感じない」ため、同じテーブルに参加することなく同じことを達成するより良い方法があるかどうか疑問に思っていました。
ありがとう!