これを行う簡単な方法はありますか?6 年のうち少なくとも 2 年分の料金コードを持つ世帯のみが必要です - (cy= 今年 ly = 昨年など) ??
Exists (SELECT * FROM ac_ViewMultiHouseholdChargeCodeYearCode AS VMH
WHERE
aa_Households.HouseholdID = VMH.HouseholdiD and
VMH.ChargeCode = 'Dinner' and
(VMH.ChargeCount_CY > 0 and
(VMH.ChargeCount_LY > 0 or
VMH.ChargeCount_2Y > 0 or
VMH.ChargeCount_3Y > 0 or
VMH.ChargeCount_4Y > 0 or
VMH.ChargeCount_5Y > 0)) or
(VMH.ChargeCount_LY > 0 and
(VMH.ChargeCount_CY > 0 or
VMH.ChargeCount_2Y > 0 or
VMH.ChargeCount_3Y > 0 or
VMH.ChargeCount_4Y > 0 or
VMH.ChargeCount_5Y > 0)) or
(VMH.ChargeCount_2Y > 0 and
(VMH.ChargeCount_LY > 0 or
VMH.ChargeCount_CY > 0 or
VMH.ChargeCount_3Y > 0 or
VMH.ChargeCount_4Y > 0 or
VMH.ChargeCount_5Y > 0)) or
(VMH.ChargeCount_3Y > 0 and
(VMH.ChargeCount_LY > 0 or
VMH.ChargeCount_2Y > 0 or
VMH.ChargeCount_CY > 0 or
VMH.ChargeCount_4Y > 0 or
VMH.ChargeCount_5Y > 0)) or
(VMH.ChargeCount_4Y > 0 and
(VMH.ChargeCount_LY > 0 or
ChargeCount_2Y > 0 or
VMH.ChargeCount_3Y > 0 or
VMH.ChargeCount_CY > 0)))