Subject | SQL Error Code -104: What is wrong with this rather simply SQL? |
---|---|
Author | stwizard |
Post date | 2016-04-06T20:03:28Z |
SELECT DISTINCT P.AREA_CODE, P.PHONE_NO,
(SELECT COUNT(*)
FROM PHONE P2
WHERE P2.PHONE_ID = P.PHONE_ID) AS CNT
FROM PHONE P
WHERE P.AREA_CODE IS NOT NULL
GROUP BY 1, 2
HAVING (SELECT COUNT(*)
FROM PHONE P3
WHERE P3.PHONE_ID = P.PHONE_ID
AND P3.AREA_CODE IS NOT NULL) > 1
Dynamic SQL Error SQL error code = -104 Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause)