首页 > 解决方案 > How can I use assignment operations in the having clause?

问题描述

Here is my code.

SELECT BUSEO, SUBSTR(SSN,8,1)
FROM TBLINSA
GROUP BY BUSEO, SUBSTR(SSN,8,1)
HAVING (SUBSTR(SSN,8,1) = 2) >= 5;

What I intended was the condition that substr(ssn,8,1) must have a value of 2 and

substr(ssn, 8, 1)=2 greater than 5.

But the result produced an SQL command not properly ended error.

I am wondering how I can fix this.

标签: sqloracle

解决方案


我想你想要一个WHERE子句中的子字符串限制。然后聚合BUSEO并断言大于或等于 5 的计数。

SELECT BUSEO
FROM TBLINSA
WHERE SUBSTR(SSN, 8, 1) = '2'
GROUP BY BUSEO
HAVING COUNT(*) >= 5;

推荐阅读