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

ottieni i primi 10 post e 10 commenti per ogni post sql

Qualcosa del genere funzionerebbe.

with a as 
(
    SELECt TOP 10  Score
    , Post.ID as PostID 
    FROM Post 
    order by Score desc 
), b as
(
    select PostID
    , ID as CommentID 
    , ROW_NUMBER() over (partition by PostID order by ID) as RowNum
    from PostComment
) 
select * 
from a
left join b
on b.PostID = a.PostID
where b.RowNum <= 10