我在构建查询时遇到了一些麻烦,我需要从 FamilyAccountDetails 表中返回 AccountID,其中家庭帐户至少有一个孩子(一个孩子是 AccountDetails.AccountID 等于 FamilyAccountDetails.AccountID),其 HoldFlag = 0。
AccountDetails
EntID |HoldFlag|AccountID|StatusFlag
FamilyAccountDetails
EntID|FamilyAccountID|AccountID|StatusFlag
SQL:
Select FD.AccountID, FD.FamilyAccountId
from Test2TMAdvisor5.dbo.FamilyAccountDetails FD
where FD.EnterpriseId = 'TestDan'
and AccountId in (Select AccountId from Test2TMAdvisor5.dbo.AccountDetails AD where Ad.AccountID = FD.AccountId and ad.HoldFlag =0)