0

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
vvv
  • 337
  • 3
  • 8
  • 1
    it would help if you could tag the dbms being used. – Vamsi Prabhala Oct 21 '16 at 23:28
  • 2
    I think you're making it way more complicated than it needs to be, this sounds like something along the lines of `select company, min(quarter) from sales_table group by company` – Julia Leder Oct 22 '16 at 00:50
  • except I want to add other aggregated fields like sales by quarter, etc, in the same query. so for now I have what you are describing, joined to the other table with sales data, but I just wondered if there's a way to do this all in one – vvv Oct 22 '16 at 18:46

0 Answers0