SQL 查询给出“不是 GROUP BY 表达式”错误
SELECT SUM(a.Clicks) AS Clicks, SUM(b.NoOfUsers) Users, c.WEEK_NUM, b2.ALL_TASKS FROM
(SELECT SUM(CLICK_CNT) AS Clicks, TO_CHAR(RQST_DT,'YYYY-MM-DD') AS DATEE FROM PER_DAY_USAGE GROUP BY RQST_DT) a,
(SELECT TO_CHAR(RQST_DT,'YYYY-MM-DD') AS DATEEE, WEEK_NUM FROM TIMEDIM) c,
(SELECT NoOfUsers, accDate FROM (( SELECT COUNT(DISTINCT RECEPIENT_ID) AS NoOfUsers, TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD') AS accDate FROM ALRT_HSTRY WHERE ACTN_TAKE_CD is not null GROUP BY TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD')) UNION ALL ( SELECT COUNT(DISTINCT RECEPIENT_ID) AS NoOfUsers, TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD') AS accDate FROM PLATFORM_ALRT WHERE ACTN_TAKE_CD is not null GROUP BY TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD'))) ) b,
( select sum(TOTL_ALRT_CNT) ALL_TASKS, TO_CHAR(CRTE_ON_DT,'YYYY-MM-DD') AS DATEE from FEED_HSTRY where APPL_CD like '%' group by CRTE_ON_DT)b2
WHERE a.datee = b.accDate AND a.datee=c.dateee AND b2.DATEE = c.dateee GROUP BY c.WEEK_NUM
这是 b2.ALL_TASKS ALL_TASKS
的问题。如果我从 SELECT 中删除它,它就会起作用。
SELECT SUM(a.Clicks) AS Clicks, SUM(b.NoOfUsers) Users, c.WEEK_NUM, b2.ALL_TASKS FROM
(SELECT SUM(CLICK_CNT) AS Clicks, TO_CHAR(RQST_DT,'YYYY-MM-DD') AS DATEE FROM PER_DAY_USAGE GROUP BY RQST_DT) a,
(SELECT TO_CHAR(RQST_DT,'YYYY-MM-DD') AS DATEEE, WEEK_NUM FROM TIMEDIM) c,
(SELECT NoOfUsers, accDate FROM (( SELECT COUNT(DISTINCT RECEPIENT_ID) AS NoOfUsers, TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD') AS accDate FROM ALRT_HSTRY WHERE ACTN_TAKE_CD is not null GROUP BY TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD')) UNION ALL ( SELECT COUNT(DISTINCT RECEPIENT_ID) AS NoOfUsers, TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD') AS accDate FROM PLATFORM_ALRT WHERE ACTN_TAKE_CD is not null GROUP BY TO_CHAR(ACTN_TAKE_DATA_TM,'YYYY-MM-DD'))) ) b,
( select sum(TOTL_ALRT_CNT) ALL_TASKS, TO_CHAR(CRTE_ON_DT,'YYYY-MM-DD') AS DATEE from FEED_HSTRY where APPL_CD like '%' group by CRTE_ON_DT)b2
WHERE a.datee = b.accDate AND a.datee=c.dateee AND b2.DATEE = c.dateee GROUP BY c.WEEK_NUM
its the problem with b2.ALL_TASKS ALL_TASKS
. If I remove that from SELECT its working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将group by 中,但您应该使用现代 JOIN 语法并尝试更好地格式化它:
b2.ALL_TASKS
添加到最终的you got adding
b2.ALL_TASKS
to the finalgroup by
, but you should use contemporary JOIN syntax as well as attempting to formatting it a little better: