我有一个非常复杂的查询。部分内容是使用where语句分隔,并排除排放日期大于90天前的结果
原始表格中的日期格式为2017-09-22
选择值如下所示
to_char("public".visit.visit_admit_date, 'MMDDYYYY') AS "Visit or Admit Date",
to_char("public".visit.visit_disch_date, 'MMDDYYYY') AS "Discharge Date",
WHERE
exists ( SELECT distinct on ("public".visit.visit_id) "public".procedure_group_cpt_code.pgrpcpt_code::text
FROM "public".visit
FULL OUTER JOIN "public".patient_procedure
ON "public".visit.visit_id = "public".patient_procedure.pproc_visit_num
FULL OUTER JOIN "public".procedure_desc_master_codes
ON "public".patient_procedure.pproc_cpcode = "public".procedure_desc_master_codes.pdescm_id
FULL OUTER JOIN "public".procedure_group_cpt_code
ON "public".procedure_group_cpt_code.pgrpcpt_pdescm_id = "public".procedure_desc_master_codes.pdescm_id
GROUP BY "public".visit.visit_id, "public".procedure_group_cpt_code.pgrpcpt_code
ORDER BY "public".visit.visit_id )
AND "public".visit.visit_stay_type = '1' OR "public".visit.visit_stay_type ='2'
这最后一行是我通过日期划分的正确方法。
AND "public".visit.visit_disch_date > (now() - interval '90 day' )
我的日期远远超出了几年的范围
如果有人需要查看更多的整个查询,我会发布它。它很大 也很乐意提供任何人可能要求的更多信息。
答案 0 :(得分:2)
问题是-keep @interface com.example.android.MyRetrofitService$*
。请改用or
:
in
其他一些建议:
"public".visit.visit_stay_type IN ('1', '2') AND
"public".visit.visit_disch_date > (now() - interval '90 day' )
子查询中不需要select distinct on
。exists
几乎从不适用于子查询。order by
很少需要。答案 1 :(得分:1)
同意IN
比OR
更好的风格,但是如果您想在将来的查询中使用OR
(例如,IN
不合适,因为您的OR
将在不同的列上运行),您应该使用括号对条件进行分组,如下所示:
AND (
"public".visit.visit_stay_type = '1'
OR "public".visit.visit_stay_type ='2')
AND "public".visit.visit_disch_date > (now() - interval '90 day' )