任何人都可以帮我解决这个小问题中的错误。
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
),它执行正常。
答案 0 :(得分:5)
您无法在where
中使用列别名。真的,你需要一个having
条款。
试试这个:
select count(txno) as c1, rxno
from mrgrxtxt
group by rxno
having count(txno) > 1;
答案 1 :(得分:1)
或者在派生表中执行GROUP BY
部分:
select c1, rxno
from
(
select count(txno) as c1, rxno
from mrgrxtxt
group by rxno
)
where c1 > 1;
更复杂的聚合时非常方便。 (减少输入,减少复制或调整表达式时出错的风险。)