两个选择上的 UNION 给出“SQL 错误:ORA-00907:缺少右括号”;

发布于 2024-08-23 09:48:37 字数 1031 浏览 7 评论 0原文

我正在尝试合并两个查询的结果。但我收到以下错误:

Error at Command Line:9 Column:81
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"

这是我的查询:

SELECT application_id, clicks, datee, client_id FROM(
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT_HSTRY
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID order by datee) 
UNION ALL
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID order by datee )
)

I'm trying to UNION the results of two queries. But I'm getting the following error:

Error at Command Line:9 Column:81
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 -  "missing right parenthesis"

Here's my query:

SELECT application_id, clicks, datee, client_id FROM(
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT_HSTRY
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID order by datee) 
UNION ALL
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID order by datee )
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼角的笑意。 2024-08-30 09:48:37

从嵌套查询中删除 ORDER BY

SELECT application_id, clicks, datee, client_id FROM(
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT_HSTRY
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID) 
UNION ALL
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID )
)

Remove the ORDER BY from the nested queries:

SELECT application_id, clicks, datee, client_id FROM(
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT_HSTRY
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID) 
UNION ALL
(select 
    APPL_CD AS application_id, 
    count(*) as clicks, 
    to_date((to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy')), 'dd-mm-yyyy') as datee, 
    ALRT_RSPNS_FROM_CLIENT_ID AS client_id 
from  ALRT_PLATFORM_ALRT
    where  ACTN_TAKE_CD is not null 
    group by to_char(ACTN_TAKE_DATA_TM, 'dd-mm-yyyy'), APPL_CD, ALRT_RSPNS_FROM_CLIENT_ID )
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文