Select record based on multi-row criteria
SELECT * 
FROM [Table_A]
WHERE [ID] IN
(
    SELECT [ID]
    FROM [Table_A]
    GROUP BY [ID]
    HAVING (
            COUNT(*)=1 AND 
            MAX(CASE WHEN CODE IN ('AR', 'RT') 
                AND BAL &lt;= 0 THEN 1 ELSE 0 END)=1
            ) 
            OR 
            (
            COUNT(*)&gt;1 AND MAX(BAL)&lt;=0
            )
)