I am trying to calculalate maximum of column values with common id.
I have following table as input
TABLE 1:
| id | seq | score |
| ----- | ------ | ----- |
| UA502 | qrst | 8.2 |
| UA502 | abcdef | 2.2 |
| UA504 | yzab | 8.8 |
| UA504 | lmnop | 2.8 |
| UA503 | uvwx | 8.6 |
| UA503 | ghijk | 2.6 |
The desired output is:
| id | seq | score |
| ----- | ------ | ----- |
| UA502 | qrst | 8.2 |
| UA504 | yzab | 8.8 |
| UA503 | uvwx | 8.6 |
I am running following WITH query (max_calc) with groupby and max function on the output of another WITH query (union_data; TABLE 1).
max_calc as(
select id, seq, max(score)
from union_data
GROUP BY id
)
select * from max_calc
;
The error I am getting is:
Query Error: error: column "union_data.seq" must appear in the GROUP BY clause or be used in an aggregate function
I do not understand this error. I am grouping the data based on common id not seq. Why I should include column "union_data.seq" in GROUPBY.
Thanks