I've got some SQL query which returns the sum of certain fields, and there's a flag column associated with these values, either 'Y' or 'N'.
Is there an aggregate function which will return a true/false on this flag column if any one record contains a 'Y'?
You could wrap conditional aggregation inside a CASE expression:
CASE
WHEN COUNT(CASE WHEN column = 'Y' THEN 1 END) > 0 THEN 'true'
ELSE 'false'
END
select nvl(max(1),0) from your_table
where column = 'Y'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With