2017-07-14 29 views
0

我想從我們AspenTech公司的IP 21的服務器查詢數據和現在用的是下面的查詢其他時間SQL查詢實時數據排除如果第一次發現

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點的數據點。一些在兩個5:59有數據,並在6,我想只有拉的每一天,從來沒有一個數據點的一個或兩者在5:59和6

+0

你願意得到0559或0600的值? – JohnHC

回答

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