我正在尝试从我们的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时都不会有一个数据点
答案 0 :(得分: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