Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Aggrega la funzione SQL per acquisire solo la prima da ciascun gruppo

Invece di raggruppare, procedi in questo modo...

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