Phi*_*hil 1 postgresql postgresql-9.6
我有一张Policies桌子。
现在我需要在10 月份获得所有待处理Policies的 a和所有已发出的a 。pendDateOctoberPoliciesissueDate
我在用着postgreSQL 9.6。这些日期可以为空,所以我不能使用简单的AND. 那个月我只需要 和pending,issued所以 OR 不起作用。
我解决了两个查询,但现在正在添加更多状态,我想以某种方式进行整合。可能的?
如果我理解正确的话,您可以通过在 WHERE 子句中使用 OR 条件来获取它:
\n\n\n\n\n\n\n\n\nRun Code Online (Sandbox Code Playgroud)\n\ncreate table Policies \n(\n policyId int,\n status varchar(100),\n pendDate date,\n issueDate date\n);\n\ninsert into Policies values\n(1, \'Pending\', \'20171001\', null),\n(2, \'Pending\', \'20171002\', null),\n(3, \'Pending\', \'20171003\', null),\n(4, \'Pending\', \'20171101\', null),\n(5, \'Pending\', \'20171102\', null),\n(6, \'Issue\', null, \'20171002\'),\n(7, \'Issue\', null, \'20171003\'),\n(8, \'Isuue\', null, \'20171101\');\n\n\xe2\x9c\x93\n\n受影响的 8 行\n\n
\n\n\nRun Code Online (Sandbox Code Playgroud)\n\nselect policyId,\n status,\n pendDate,\n issueDate\nfrom Policies\nwhere (status = \'Pending\' and extract(year from pendDate) = 2017 and extract(month from pendDate) = 10)\nor (status = \'Issue\' and extract(year from issueDate) = 2017 and extract(month from issueDate) = 10)\n\n政策 ID | 状态 | 待定日期 | 发布 \n-----: | :------ | :--------- | :---------\n 1 | 待定 | 2017-10-01 | 空 \n 2 | 待定 | 2017-10-02 | 空 \n 3 | 待定 | 2017-10-03 | 空 \n 6 | 问题 | 空 | 2017-10-02\n 7 | 问题 | 空 | 2017-10-03\n\n
dbfiddle在这里
\n| 归档时间: |
|
| 查看次数: |
17430 次 |
| 最近记录: |