I'm trying to get the oldest processing date on each product like this:
select prod_id, prod_name, prod_date, min(prod_date) over (partition by prod_id) as min_prod_date
from dim_product
where prod_name in ('xxx', 'yyy', 'zzz')
having prod_date = min_prod_date
This gives me the error:
ORA-00904: "min_prod_date": invalid identifier
So I tried to use the min() function in the having clause which gave me the error:
ORA-30483: window functions are not allowed here
As an alternative I modified my query like this:
with temp as(
select prod_id, prod_name, prod_date, min(prod_date) over (partition by prod_id) as min_prod_date
from dim_product
where prod_name in ('xxx', 'yyy', 'zzz')
having prod_date = min_prod_date))
select * from temp where prod_date = min_prod_date
Is this the right way to do things or Is there any other efficient method?