【问题标题】:How do I figure out this comma error in my SQL code?如何在我的 SQL 代码中找出这个逗号错误?
【发布时间】:2021-01-06 14:22:01
【问题描述】:

我正在尝试运行一组子查询,但不确定问题出在哪里。

select 
    can, 
    sum(case when tax_year = 2018 then qty_req else 0 end) as TY18_esig,
    (select sum(case when tax_year = 2018 then qty_req else 0 end) as TY18_esig_unltd 
     from RPT_PCG_CART_CUR 
     where PRODUCT in ('eSignature Unlimited for ProSeries'),
    sum(case when tax_year = 2019 then qty_req else 0 end) as TY19_esig
from 
    RPT_PCG_CART_CUR
where 
    product IN ('eSignature Bank Jan 1 - Dec 31 2020', 'eSignature Unlimited for Lacerte')
    and cart_type = 'TRANSACTED'
group by 1
order by 1

我得到的错误是:

[代码:4856,SQL 状态:42601] [Vertica]VJDBC 错误:“,”或附近的语法错误

[代码:4818,SQL 状态:0A000] [Vertica]VJDBC 错误:如果子查询不属于 GROUP BY,则不支持 SELECT 或 ORDER BY 中的子查询

【问题讨论】:

  • 第三个“列”是一个(select .....,它缺少一个结束圆括号:in 条件在括号中列出了一个值 - 但它应该以两个括号(也用于关闭(select ...... 部分)。
  • 谢谢我纠正了这个。对按问题分组的任何想法?
  • group by 1 什么都不做
  • 不按CAN分组,因为有聚合
  • 你需要表别名

标签: sql vertica


【解决方案1】:

如评论中所述,您在标量子查询中缺少右括号/圆括号。

您应该在此行的逗号前有两个右括号:

where PRODUCT in ('eSignature Unlimited for ProSeries')),

【讨论】:

  • 谢谢。我仍然收到以下错误:[代码:4818,SQL 状态:0A000] [Vertica][VJDBC](4818) 错误:如果子查询不是 GROUP BY 的一部分,则不支持 SELECT 或 ORDER BY 中的子查询
猜你喜欢
  • 2014-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-08
  • 1970-01-01
  • 2019-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多