-----unionQuery-----
SELECT COUNT(ID) AS count, '已完成' AS event FROM EVENT_RECEIVE_ENTITY WHERE tenant_id = 'ff8080817592c76a017592d380f00081' AND account_id = 'ff8080817592c76a017592d380f10082' AND (EVENT_STATUS IN ('14', '15') AND ACCOUNT_ID = ? AND system_id IN (?)) UNION ALL SELECT COUNT(ID) AS count, '处理中' AS event FROM EVENT_RECEIVE_ENTITY WHERE tenant_id = 'ff8080817592c76a017592d380f00081' AND account_id = 'ff8080817592c76a017592d380f10082' AND (EVENT_STATUS NOT IN ('1', '14', '15', '17') AND ACCOUNT_ID = ? AND system_id IN (?)) UNION ALL SELECT COUNT(ID) AS count, '预警故障' AS event FROM EVENT_RECEIVE_ENTITY WHERE tenant_id = 'ff8080817592c76a017592d380f00081' AND account_id = 'ff8080817592c76a017592d380f10082' AND (event_status NOT IN ( '1', '2', '3', '14', '15', '17' ) AND system_id IN (?) AND ACCOUNT_ID = ? AND >= CREATED + 0 + (WARNING_TIME - 5) / 24 / 60)
-----left-----
SELECT COUNT(ID) AS count, '已完成' AS event FROM EVENT_RECEIVE_ENTITY WHERE tenant_id = 'ff8080817592c76a017592d380f00081' AND account_id = 'ff8080817592c76a017592d380f10082' AND (EVENT_STATUS IN ('14', '15') AND ACCOUNT_ID = ? AND system_id IN (?)) UNION ALL SELECT COUNT(ID) AS count, '处理中' AS event FROM EVENT_RECEIVE_ENTITY WHERE tenant_id = 'ff8080817592c76a017592d380f00081' AND account_id = 'ff8080817592c76a017592d380f10082' AND (EVENT_STATUS NOT IN ('1', '14', '15', '17') AND ACCOUNT_ID = ? AND system_id IN (?))
-----right-----
SELECT COUNT(ID) AS count, '预警故障' AS event FROM EVENT_RECEIVE_ENTITY WHERE tenant_id = 'ff8080817592c76a017592d380f00081' AND account_id = 'ff8080817592c76a017592d380f10082' AND (event_status NOT IN ( '1', '2', '3', '14', '15', '17' ) AND system_id IN (?) AND ACCOUNT_ID = ? AND SYSDATE >= CREATED + 0 + (WARNING_TIME - 5) / 24 / 60)
为什么在unionQuery.toString()后,right中最后一个过滤条件中的SYSDATE消失了?
原提问者GitHub用户DarylYeung
在 Oracle 数据库中,如果在 SQL UNION 查询中使用 SYSDATE 函数,可能会出现该函数的结果消失的情况。这是因为 SQL UNION 操作会对结果进行合并和去重,而 SYSDATE 函数的返回值是动态的,每次查询时都会重新计算。因此,在 SQL UNION 查询中,SYSDATE 函数的结果可能会因为去重操作而消失。
为了解决这个问题,您可以通过以下几种方式之一进行处理:
1.在每个 SELECT 查询中都使用 SYSDATE 函数。这样,每个 SELECT 查询都会计算 SYSDATE 函数的结果,并将其包括在结果集中。但是,这种方法可能会导致查询效率较低,因为每个查询都需要计算 SYSDATE 函数。
2.在 SQL UNION 查询中使用一个子查询来计算 SYSDATE 函数。
SQLUtils.toOracleString(unionQuery) 这样试试看
原回答者GitHub用户wenshao
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。