아래의 쿼리를 통해 날짜 범위에서 수행 된 서비스를 모니터링 할 수 있습니다. 또한 마지막 "X"일을 표시하도록 수정합니다.날짜 범위 내에서 활동이없는 클라이언트 찾기
여기 내 문제입니다. 날짜 범위에서 활동이없는 모든 고객을 찾아야합니다. 왼쪽 외부 조인을 사용하는 예제를 보았습니다. (http://www.postgresqlforbeginners.com/2010/11/sql-outer-joins.html)을 따르려고했지만 "누락 된"서비스가 표시되지 않습니다. 나는 "Bob"이 과거의 "X"날에는 보이지 않았 음을 알 필요가있었습니다. 클라이언트가 있다고 가정
SELECT groups.name as Office,to_char (notes.date_service,'MM/DD/YY')as DateEntered,
to_char(notes.date_creation,'MM/DD/YY')as DateService,
notes.date_creation - notes.date_service as DateDiff,
services.code, clients.client_id,
clients.name_lastfirst_cs, staff.staff_name_cs, address.addr_county
FROM notes, services, clients, staff, groups, address
WHERE notes.zrud_service = services.zzud_service
AND notes.zrud_client = clients.zzud_client
AND notes.zrud_staff = staff.zzud_staff
AND notes.zrud_group = groups.zzud_group
AND clients.zzud_client = address.zrud_client
AND services.code IN ('10101', '10102', '10201' , '10202','10203','10204','10205','10401','10402','10403','10405') - - <I comment out this line and change it depending on the results I need >
AND groups.name = 'RCE'
AND notes.date_service BETWEEN (now() - '8 days'::interval)::timestamp AND now();
-- this last line is also changed for diferent time spans
감사
Kordirko 대신
join
에 조건을 이동합니다. 마지막 WHERE 문을 사용하여 어떻게 시도했는지, 그리고 제안한대로 주석을 달았습니다. 그런 다음 보고서에 나타난 여러 노트를 클라이언트에 추가하여 다른 쿼리에서 사라지는 지 알아 보았습니다. – Detox