I have the following data in my Teradata tables and I am trying to get the number of rows as 'TENURE' based on some conditions
Have
Id MONTH ORDERNO STATUS
101 2022-01-31 105 00
101 2022-02-28 105 00
101 2022-03-31 106 00
101 2022-04-30 106 07
101 2022-05-31 106 07
102 2022-01-01 105 00
102 2022-02-28 105 00
102 2022-03-31 105 07
102 2022-04-28 105 07
Want
Id TENURE
101 4
102 3
I have to exclude the 2nd appearance of STATUS='07' and count the number of months
I am using the following window function to get the number of rows but I don't know how to add status='07' filter
SELECT id,
COUNT(*) OVER (PARTITION BY id ORDER BY MONTH ROWS BETWEEN UNBOUNDED PRECEDING AND
UNBOUNDED FOLLOWING) AS TENURE FROM Have;
I got the following instead of 4 and 3 respectively
Id TENURE
101 5
102 4