日期:2014-05-18 浏览次数:20529 次
select distinct b.* from tb a cross apply (select top 1 * from tb where convert(varchar(13),riqi,120)=convert(varchar(13),t.riqi,120) order by riqi)b
------解决方案--------------------
SELECT b.* FROM (SELECT DISTINCT CAST(CONVERT(VARCHAR(14),rigi,121)+'00' AS DATETIME) AS rigi FROM TABLE1 )AS a CROSS APPLY (SELECT TOP 1 * FROM table1 WHERE DATEDIFF(h,a.rigi,rigi)=0 ORDER BY NEWID()) AS b