I am trying to get the first row of each group in the individual_id
column, but I keep getting errors.
In the first section of the query I am just trying to SELECT
the individual_id
, pics
, and species
from my Train
table and GROUP BY
the individual_id
:
SELECT individual_id, pics, species
FROM Train
GROUP BY individual_id
This alone throws an error saying that pics doesn't have an aggregate function, but I don't want to use an aggregate function on the data I want it to be the same table just grouped.
In the second part of the query I get an error in the WITH OWNERSHIP ACCESS declaration which I don't even have.
WITH added_row_number AS
(
SELECT
*,
ROW_NUMBER() OVER (PARTITION BY individual_id ORDER BY pics DESC) AS row_number
FROM
Train
)
SELECT
*
FROM
added_row_number
WHERE
row_number = 1;