27,579
社区成员
发帖
与我相关
我的任务
分享
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([dtime] DATETIME,[PLC1] decimal(18,9),[PLC2] decimal(18,9))
Insert #T
select N'2017-06-29 17:03:29.000',1.120,7.715 union all
select N'2017-06-29 17:04:29.000',1.120,7.715 union all
select N'2017-06-29 17:05:29.000',1.120,7.715 union all
select N'2017-06-29 18:03:29.000',1.120,7.715 union all
select N'2017-06-29 18:04:29.000',1.120,7.715 union all
select N'2017-06-29 18:05:29.000',1.120,7.715 union all
select N'2017-06-29 19:03:29.000',1.120,7.715 union all
select N'2017-06-29 19:04:29.000',1.120,7.715 union all
select N'2017-06-29 19:05:29.000',1.120,7.715
Go
--测试数据结束
SELECT * FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY SUBSTRING(CONVERT(NVARCHAR(200), dtime, 120), 0, 14)
ORDER BY dtime
) rn
FROM #T)t
WHERE rn=1