0

我正在尝试从我们的 aspentech IP 21 服务器查询数据并使用以下查询

SELECT s.IP_TREND_VALUE AS "Weight", s.IP_TREND_TIME AS TIMES
From "wtTotal" as s

WHERE  s.IP_TREND_TIME like '__________05:59:00.%' AND s.IP_TREND_TIME between '1-JUN-17 05:59:00' and '15-JUN-17 06:00:00' 
OR s.IP_TREND_TIME like '__________06:00:00.%' AND s.IP_TREND_TIME between '1-JUN-17 05:59:00' and '15-JUN-17 06:00:00'

问题是有些日子在 5:59 有一个数据点,而有些日子在 6:00 有一个数据点。有些人在 5:59 和 6 点都有数据。我想每天只提取一个数据点,而不是在 5:59 和 6 点都提取一个

4

1 回答 1

0
with CTE as
(
SELECT s.IP_TREND_VALUE AS "Weight", s.IP_TREND_TIME AS TIMES,  
       row_number() 
         over (partition by to_char(IP_TREND_TIME, 'YYYYMMDD') 
               order by IP_TREND_TIME asc) as rn -- change the order by to change which value to select
From "wtTotal" as s
WHERE  s.IP_TREND_TIME like '__________05:59:00.%' AND s.IP_TREND_TIME between '1-JUN-17 05:59:00' and '15-JUN-17 06:00:00' 
OR s.IP_TREND_TIME like '__________06:00:00.%' AND s.IP_TREND_TIME between '1-JUN-17 05:59:00' and '15-JUN-17 06:00:00'
)
select *
from CTE
where RN = 1
于 2017-07-14T15:37:58.920 回答