sql >> Base de Datos >  >> RDS >> Sqlserver

Agregue la función SQL para tomar solo el primero de cada grupo

En lugar de agrupar, hazlo así...

select
    *

from account a

join (
    select 
        account_id, 
        row_number() over (order by account_id, id) - 
            rank() over (order by account_id) as row_num from user
     ) first on first.account_id = a.id and first.row_num = 0