我希望簡化這一令人困惑的左外通過可能使用其中語句轉換左外連接到WHERE語句
Select approved.orderId
From (select distinct orderId from OrderLine where isApproved = 1 and isDismissed = 0) approved
left outer join
(select distinct orderId from OrderLine where isApproved = 0 and isDismissed = 0) unapproved
on approved.orderId = unapproved.orderId
Where unapproved.orderId Is Null
喜歡的東西連接語句到的東西更容易閱讀:
Select orderId
From (select distinct orderId from OrderLine where (isApproved = 1 and isDismissed = 0) OR (isApproved = 0 and isDismissed = 0 and orderId is null))