日期:2014-05-18 浏览次数:20734 次
select * from tb t where not exists(select 1 from tb where datediff(dd,dtdatetime,t.dtdatetime)=0 and suserid=t.suserid and dtdatetime>t.dtdatetime)
------解决方案--------------------
select * from tb t where not exists(select 1 from tb where datediff (dd,dtdatetime,t.dtdatetime)=0 and suserid=t.suserid and dtdatetime>t.dtdatetime)
------解决方案--------------------
IF OBJECT_ID('tempdb..#temp', 'u') IS NOT NULL
DROP TABLE #temp
GO
CREATE TABLE #temp
(
dtDateTime DATETIME,
sUserID VARCHAR(10)
)
INSERT #temp
select '2011-06-04 08:19:10.210', 'A' UNION ALL
select '2011-06-04 08:19:10.143', 'A'
GO
--SQL:
SELECT DISTINCT *
FROM #temp T
WHERE NOT EXISTS(
SELECT 1 FROM #temp
WHERE CONVERT(VARCHAR(23), dtDateTime, 120) = CONVERT(VARCHAR(23), T.dtDateTime, 120)
AND dtDateTime < T.dtDateTime
)
--RESULT:
/*
dtDateTime sUserID
2011-06-04 08:19:10.143 A
*/
------解决方案--------------------
select distinct convert(varchar(100),dtDateTime,120) as dtDateTime,sUserID
------解决方案--------------------
select distinct convert(varchar(19),dtDatetime,120) as dtDatetime,sUserID
from Log_Schedule