I have a table with company sales by quarter. The table only registers transactions that occurred, so if there are no sales in a given quarter, it won't appear at all in the table. I would like to find the first quarter that the company has any sales.
If I include group by 1, I get error: 'quarter' is not present in the GROUP BY list. If I don't include it, I get duplicate rows. What is the correct syntax to get just one row associated with each company?
select
company,
first_value(quarter) over (partition by company order by year_quarter) as first_quarter
from
sales_table
group by 1