조인 사용하여 쿼리를 최적화SQL은 내가 테이블 productHistory이
productHistory (id_H , id_product , name , tsInsert);
나는 테이블에서 가져가 (끝 시작)를 제공하는 기간의 마지막 제품을 productHistory 싶어 : tsInsert가 시작 사이이어야하며, 끝.
I는 다음과 같이 수행 할 수 있습니다
select max(id_H)
from productHistory
where tsInsert>=:start and tsInsert <=:end
group by id_product;
다음 productHistory에서 모두 선택 위치를 이전 선택에 id_H.
이 쿼리는 예를 들어 가입 권리를 사용하는 다른 솔루션이 매우 무거운 편이다?
SELECT * FROM productHistory x
INNER JOIN
(
SELECT MAX(id_H) as maxId
FROM productHistory
GROUP id_product
) y
ON x.id_H = y.maxId
and x.TSINSERT >=:start and x.TSINSERT <=:end
귀하의 문이수록 좋은 것입니다 : –
"매우 무겁다"는 것은 실행 시간이 길다는 의미입니까? – athabaska