2017-10-20 2 views
0

차량이 하루에 여러 번 장소를 방문하더라도 최대 하루 방문수가 1 인 것을 고려하여 차량이 두 날짜 사이에 장소를 방문한 횟수를 계산해야합니다.PostgreSQL/PostGIS 방문 횟수

SELECT DISTINCT id_vehicle, datehour::date as dt, COUNT(id_vehicle) AS times 
FROM history 
WHERE datehour between '2017-01-01' AND CURRENT_TIMESTAMP AND 
     ST_Contains('POLYGON((x1 y1, x2 y2, x3 y3, x4 y4, x1 y1))',ST_MakePoint(longitude,latitude)) 
GROUP BY datehour::date, id_vehicle; 

내가 필요 결과 : 만약 내가 제대로 이해하고

enter image description here

답변

2

, 당신이 원하는 :

SELECT id_vehicle, COUNT(DISTINCT datehour::date) AS times 
FROM history 
WHERE datehour between '2017-01-01' AND CURRENT_TIMESTAMP AND 
     ST_Contains('POLYGON((x1 y1, x2 y2, x3 y3, x4 y4, x1 y1))', ST_MakePoint(longitude, latitude)) 
GROUP BY id_vehicle; 
여기

enter image description here

내가 쓴 것입니다