I have a table as following (using bigquery):
id | year | month | sales | row_number |
---|---|---|---|---|
111 | 2020 | 11 | 1000 | 1 |
111 | 2020 | 12 | 2000 | 2 |
112 | 2020 | 11 | 3000 | 1 |
113 | 2020 | 11 | 1000 | 1 |
Is there a way in which I can select rows that have row numbers more than one?
For example, my desired output is:
id | year | month | sales | row_number |
---|---|---|---|---|
111 | 2020 | 11 | 1000 | 1 |
111 | 2020 | 12 | 2000 | 2 |
I don't want to just exclusively select rows with row_number = 2 but also row_number = 1 as well.
The original code block I used for the first table result is:
SELECT
id,
year,
month,
SUM(sales) AS sales,
ROW_NUMBER() OVER (PARTITIONY BY id ORDER BY id ASC) AS row_number
FROM
table
GROUP BY
id, year, month