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

sql seleziona 3 colonne e deduplica su due colonne

Puoi usare un GROUP BY e qualsiasi funzione aggregata su dateadded colonna per ottenere author, pubdate univoco risultati.

SELECT  [author]
        ,[pubDate]
        ,MAX([dateadded])
 FROM   [Feeds].[dbo].[socialPosts]
 WHERE  CAST(FLOOR(CAST(dateadded AS float)) AS datetime) >  dateadd(day,datediff(day, 0, getdate()-2), 0)  
        AND CAST(FLOOR(CAST(dateadded AS float)) AS datetime) < dateadd(day,datediff(day, 0, getDate()), 0)
 GROUP BY 
        [author]
        , [pubdate]