zoukankan      html  css  js  c++  java
  • sql 获取某一时段中每一天中最大的时间的一条记录

    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 = 1

    --沉降监测1

    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_4884202820057099879
    where DataTime BETWEEN '2019-06-04 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_4909605008448672773
    where DataTime BETWEEN '2019-06-04 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_5030118834484935845
    where DataTime BETWEEN '2019-06-04 00:00:00' and '2019-06-04 23:00:00'
    ) AS A WHERE RN=1

  • 相关阅读:
    HTML元素解释
    Java命名规范
    HDU 1058 Humble Numbers(DP,数)
    HDU 2845 Beans(DP,最大不连续和)
    HDU 2830 Matrix Swapping II (DP,最大全1矩阵)
    HDU 2870 Largest Submatrix(DP)
    HDU 1421 搬寝室(DP)
    HDU 2844 Coins (组合背包)
    HDU 2577 How to Type(模拟)
    HDU 2159 FATE(二维完全背包)
  • 原文地址:https://www.cnblogs.com/yelanggu/p/10968613.html
Copyright © 2011-2022 走看看