SELECT *
FROM (
SELECT ROW_NUMBER() OVER(
PARTITION BY CONVERT(CHAR(10), DataTime, 120) ORDER BY DataTime DESC
) AS rid,
*
FROM Hour_4684807221950341358
) AS t
WHERE rid = 1select
--沉降監測1im
select * from (
SELECT * FROM
(SELECT *,ROW_NUMBER() OVER (PARTITION BY CONVERT(VARCHAR(10),DataTime,23),HFCodeID ORDER BY DataTime DESC) AS RN FROM Hour_4684807221950341358
where DataTime BETWEEN '2019-06-03 00:00:00' and '2019-06-04 23:00:00'
) AS A WHERE RN=1
UNION ALL
--沉降監測2
SELECT * FROM
(SELECT *,ROW_NUMBER() OVER (PARTITION BY CONVERT(VARCHAR(10),DataTime,23),HFCodeID ORDER BY DataTime DESC) AS RN FROM Hour_4964749819094058863
where DataTime BETWEEN '2019-06-03 00:00:00' and '2019-06-04 23:00:00'
) AS A WHERE RN=1
UNION ALL
--滲壓監測
SELECT * FROM
(SELECT *,ROW_NUMBER() OVER (PARTITION BY CONVERT(VARCHAR(10),DataTime,23),HFCodeID ORDER BY DataTime DESC) AS RN FROM Hour_5157124432278248782
where DataTime BETWEEN '2019-06-03 00:00:00' and '2019-06-04 23:00:00'
) AS A WHERE RN=1
) xx order by DataTime asc
--沉降監測SELECT * FROM (SELECT *,ROW_NUMBER() OVER (PARTITION BY CONVERT(VARCHAR(10),DataTime,23),HFCodeID ORDER BY DataTime DESC) AS RN FROM Hour_4884202820057099879where DataTime BETWEEN '2019-06-04 00:00:00' and '2019-06-04 23:00:00' ) AS A WHERE RN=1UNION ALL--滲壓監測SELECT * FROM (SELECT *,ROW_NUMBER() OVER (PARTITION BY CONVERT(VARCHAR(10),DataTime,23),HFCodeID ORDER BY DataTime DESC) AS RN FROM Hour_4909605008448672773where DataTime BETWEEN '2019-06-04 00:00:00' and '2019-06-04 23:00:00' ) AS A WHERE RN=1UNION ALL--傾斜監測SELECT * FROM (SELECT *,ROW_NUMBER() OVER (PARTITION BY CONVERT(VARCHAR(10),DataTime,23),HFCodeID ORDER BY DataTime DESC) AS RN FROM Hour_5030118834484935845where DataTime BETWEEN '2019-06-04 00:00:00' and '2019-06-04 23:00:00' ) AS A WHERE RN=1