[Solved] How to write a query [closed]


Assuming only nesting questions one deep:

SELECT Count(*)
FROM tbl a
WHERE DependentId = 0
AND (
    a.[Active Flag] = 'Y'
        OR EXISTS (
        SELECT 1 
        FROM tbl b 
        WHERE b.BaseQuestionID = a.ID 
       AND b.[Active Flag] = 'Y' 
    )
)

If nesting deeper need to use iteration and loops which depends on what database you are using.

solved How to write a query [closed]