2020-10-28

Range Of Dates Over Conditional Attributes

I have a table of startDates and EndDates where three YES/NO attributes exist:

Table

I need a range from the minimum startDate to the maximum endDate when any attribute (1,2, or 3) is equal to 'Y'. There also needs to be a range for the startDate to endDate when all attributes are equal to 'N'. So, the results would be something like the table below: Query Results

I've tried a common table expression that failed miserably and something like the following:

select 

case
when ATTR1 = 'Y' or ATTR2 = 'Y' or ATTR3 = 'Y'<br>
then 'Y'<br>
ELSE 'WAIVE' END AS ATTR<br>
, min(startDate)    , max(endDate)<br>
from attribute_table_view<br>
group by ATTR, startDate


from Recent Questions - Stack Overflow https://ift.tt/37ZUI2n
https://ift.tt/3oyOSLa

No comments:

Post a Comment