2016-08-13 10 views
-1

저는 여러 도시에서 오늘날의 높은 온도와 낮은 온도를 얻기 위해 YQL을 사용하고 있습니다. 다음 쿼리는 불필요하게 return a 10-day forecast for each city입니다.쿼리 결과를 각 그룹의 첫 번째 그룹으로 제한

select item.forecast.high, item.forecast.low from weather.forecast 
where woeid in (select woeid from geo.places(1) where text in ("ushuaia, ag", "dallas, tx")) 

결과가 채널 0과 10 (즉 각 도시의 첫 번째 채널)에 필요한 것은 무엇입니까? 결과를이 두 가지로 어떻게 제한 할 수 있습니까?

답변

0

다음 쿼리는 내가 원하는 것을 제공합니다. (질문에 연결된) 야후의 주요 YQL 콘솔이 순간의 같은 날씨 쿼리 작동하지 않는 이유

select item.forecast.high, item.forecast.low from weather.forecast 
where woeid in (select woeid from geo.places(1) where text in ("ushuaia, ag", "dallas, tx")) 
and item.forecast.date="14 Aug 2016" 

는 나도 몰라,하지만 당신은 여전히 ​​weather API page에 쿼리를 시도 할 수 있습니다.

결과 :

{ 
"query": { 
    "count": 2, 
    "created": "2016-08-14T20:13:35Z", 
    "lang": "en-US", 
    "results": { 
    "channel": [ 
    { 
    "item": { 
     "forecast": { 
     "high": "25", 
     "low": "15" 
     } 
    } 
    }, 
    { 
    "item": { 
     "forecast": { 
     "high": "88", 
     "low": "75" 
     } 
    } 
    } 
    ] 
    } 
} 
} 
1

일치하는 도시 코드의 내림차순으로 마지막 두 날짜를 반환하는 하위 쿼리를 조인 할 수 있습니다. 도시 코드와 예측 ID에 가입해야합니다.

아래의 SQL은 T-SQL이지만 YQL과 비슷한 점이 있다고 생각합니다.

select item.forecast.high, 
    item.forecast.low 
from weather.forecast forecast 
JOIN (SELECT TOP 2 id, woeid, date 
    FROM weather.forecast 
    ORDER BY date DESC) dates ON dates.woeid = forecast.woeid 
          AND dates.id = forecast.id 
where woeid in (select woeid 
       from geo.places(1) 
       where text in ("ushuaia, ag", "dallas, tx")) 
+0

이 도우려고 주셔서 감사합니다. 데이터베이스에 새로운 브랜드이므로, 나는 당신의 대답을 이해하지 못했습니다. 언젠가는 다시 돌아올 것이지만 운 좋게도 지금은 더 간단한 방법을 찾았습니다. – bongbang

관련 문제