【问题标题】:SQL syntax error on group by having max组上的 SQL 语法错误,具有最大值
【发布时间】:2015-03-19 08:01:39
【问题描述】:

我有以下查询,我想在其中返回一些发送给用户的有关事件的信息通知。在这种情况下,我只想从通知表中返回最近的事件日期。

select ntcf.emp_first_name, ntcf.emp_last_name, ntcf.emp_id, evt.evt_num, ntcf.ntcf_dte, ntcf.ntcf_id
from    evt_t evt, 
        ntcf_t ntcf
where 
    ntcf.ntcf_id = evt.ntcf_id and
group by evt.evt_num
having max(ntcf.evt_dte)

但是,Sybase 告诉我“')' 附近的语法不正确”我在分组/选择 MAX 方面做错了吗?我通常看不到语法错误,如果我的分组/聚合有问题,错误消息也不是很有帮助。

【问题讨论】:

    标签: sql database grouping aggregate-functions sybase


    【解决方案1】:

    在查询中没有生成表达式 max(ntcf.evt_dte),因此 HAVING 没有任何要检查的内容。

    HAVING 子句用于对结果进行额外过滤。它不用于额外的计算。

    【讨论】:

    • 好的,我明白你的意思了。它应该写成一个子查询,比如“where blah and ntcf.evt_dte = (select max(evt_dte) from blah where blah'
    猜你喜欢
    • 1970-01-01
    • 2021-01-03
    • 2011-01-25
    • 1970-01-01
    • 2011-11-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    相关资源
    最近更新 更多