找文章 / 找答案
精选问答 更多内容

创建数据集自定义SQL语句报错

yhdata_TfOCpjFc新手上路 显示全部楼层 发表于 2024-1-5 20:10:17 |阅读模式 打印 上一主题 下一主题
1
未解决

创建数据集自定义SQL语句报错

1139 0
本帖最后由 yhdata_TfOCpjFc 于 2024-1-5 20:13 编辑

当我把timeWeek标签里的内容删除掉就可以运行查出数据,加上之后就报错,也是很奇怪,sql语句也没啥错误,   
发布问题得时候总是提示不良信息也是醉了,下面有timeDay  和   timeWeek,大家费眼找一下哈
select
CASE WHEN TA1.FACTORY is not null THEN  TA1.FACTORY ELSE T3.FACTORY END AS FACTORY,
  TA1.N_TOTAL AS TOTAL_NUM,
    TA1.N_FAILE AS FAILE_NUM,
    ROUND(TA1.N_RATE*100,2) AS RATE,
    ROUND((1-TA1.N_RATE/TA1.Y_RATE)*100,2) AS YOY,
    ROUND((1-TA1.N_RATE/T3.RATE)*100,2) AS QOQ

from(
select CASE WHEN T1.FACTORY is not null THEN  T1.FACTORY ELSE T2.FACTORY END AS FACTORY,
  T1.TOTAL AS N_TOTAL,
    T1.FAILE AS N_FAILE,
    T1.rate AS N_RATE,
      T2.TOTAL AS Y_TOTAL,
    T2.FAILE AS Y_FAILE,
    T2.rate AS Y_RATE
  from (SELECT
  FACTORY,
  sum( ADS_SC_ZBY01328_V) TOTAL,
  sum( ADS_SC_ZBY01327_V ) FAILE,
sum( ADS_SC_ZBY01327_V ) /sum( ADS_SC_ZBY01328_V) rate
FROM
  EDW_IOCII.ADS_SC_ZBY00453
WHERE

  <timeDay>
    UPDATE_DT = ?{timeDay}
  </timeDay>

  <timeWeek>
    UPDATE_DT >= TO_CHAR(TRUNC(TO_DATE(?{timeWeek}, 'YYYY-MM-DD'), 'IW'),'YYYY-MM-DD')
    AND UPDATE_DT <= TO_CHAR(TRUNC(TO_DATE(?{timeWeek}, 'YYYY-MM-DD'), 'IW') +6,'YYYY-MM-DD')
  </timeWeek>

  GROUP BY FACTORY ORDER BY FACTORY DESC
  ) T1
  FULL OUTER JOIN(

    SELECT
  FACTORY,
  sum( ADS_SC_ZBY01328_V) TOTAL,
  sum( ADS_SC_ZBY01327_V ) FAILE,
  sum( ADS_SC_ZBY01327_V ) /sum( ADS_SC_ZBY01328_V) rate
FROM
  EDW_IOCII.ADS_SC_ZBY00453
WHERE
  <timeDay>
    UPDATE_DT = TO_CHAR(ADD_MONTHS(TO_DATE(?{timeDay}, 'YYYY-MM-DD'), -12),'YYYY-MM-DD')
  </timeDay>

  GROUP BY FACTORY
  )  T2 ON T1.FACTORY = T2.FACTORY ) TA1
   FULL OUTER JOIN
(
    SELECT
  FACTORY,
  sum( ADS_SC_ZBY01328_V) TOTAL,
  sum( ADS_SC_ZBY01327_V ) FAILE,
  sum( ADS_SC_ZBY01327_V ) /sum( ADS_SC_ZBY01328_V) rate
FROM
  EDW_IOCII.ADS_SC_ZBY00453
WHERE
  <timeDay>
    UPDATE_DT = TO_CHAR(TO_DATE(?{timeDay}, 'YYYY-MM-DD') - 1, 'YYYY-MM-DD')
  </timeDay>

  GROUP BY FACTORY) T3 ON TA1.FACTORY = T3.FACTORY

回复

使用道具 举报

高级模式
您需要登录后才可以回帖 登录 | 免费注册

  • 官方微信

    欢迎关注永洪服务号!收费为0,价值无限

    扫码关注
  • 新浪微博

    让每位用户轻松挖掘数据价值!

    访问新浪微博
  • 智能客服
50W

会员等你来哦

Copyright   ©2012-2024  北京永洪商智科技有限公司  (京ICP备12050607) 京公网安备110110802011451号 |《永洪社区协议》
返回顶部