下面的查询允许我监控在某个日期范围内执行了哪些服务。我还对其进行了修改以显示最后的“X”天。
这是我的问题。我需要找到在某个日期范围内没有活动的所有客户。我已经看到使用左外连接的示例(http://www.postgresqlforbeginners.com/2010/11/sql-outer-joins.html)并尝试遵循它,但结果不会显示“缺失”服务。我需要看到在过去的“X”天内没有看到“Bob”,而不是确实发生的活动。
所以,如果有人可以看看这个并引导我找到解决方案,我将非常感激
这是查询:
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
谢谢