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

sql selecciona 3 columnas y deduplica en dos columnas

Puedes usar un GROUP BY y cualquier función agregada en el dateadded columna para obtener un único author, pubdate resultados.

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]