I have a query that should return a scalar value if an element is referenced in the table more than once.
SELECT
COUNT(*)
FROM
Items
WHERE
FKID = 2003799
GROUP BY
FKID
HAVING
COUNT(*)>1
ORDER BY
COUNT(*)
Why can't I assign aggragate an alias and refer to an alias in the rest of the query instead of repeating the aggragate function?
Sort of:
SELECT
COUNT(*) AS CountById
FROM
Items
WHERE
FKID = 2003799
GROUP BY
FKID
HAVING
CountById>1
ORDER BY
CountById
Change Is there an alternative syntax that allows you to use the same idea?
source
share