【问题标题】:(or SLV is undefined) Informix data base(或 SLV 未定义) Informix 数据库
【发布时间】:2016-05-19 10:10:14
【问题描述】:

谁能帮我找出这个小查询中的错误。

select count(txno) as c1, rxno  from mrgrxtxt 
where c1>1
group by rxno;

错误:[Error Code: -217, SQL State: IX000] Column (c1) not found in any table in the query (or SLV is undefined).

如果我注释掉 WHERE 子句 (where c1 >1),它执行得很好。

【问题讨论】:

    标签: sql database informix


    【解决方案1】:

    您不能在 where 中使用列别名。真的,你需要一个having 子句。

    试试这个:

    select count(txno) as c1, rxno 
    from mrgrxtxt 
    group by rxno
    having count(txno) > 1;
    

    【讨论】:

      【解决方案2】:

      或者在派生表中执行GROUP BY 部分:

      select c1, rxno
      from
      (
          select count(txno) as c1, rxno 
          from mrgrxtxt 
          group by rxno
      )
      where c1 > 1;
      

      在更复杂的聚合时非常方便。 (在复制或调整表达式时,打字更少,出错的风险也更小。)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多