I have a query as follows
select t.col1,
t.col2,
(select count(col1)
from tab
where col1 = t.col1
and col2 = t.col2
) as col3
from tab t
where col3 > 1
The query gives an 'col3 invalid identifier' error.
I have tried different variations defining the alias which I have given below and the error I get when I use them
select t.col1, t.col2, (select count(col1) from tab where col1 = t.col1 and col2 = t.col2 ) as "col3" from tab t where col3 > 1
Error: col3 invalid identifier
select t.col1, t.col2, (select count(col1) from tab where col1 = t.col1 and col2 = t.col2 ) as 'col3' from tab t where [col3] > 1
Error: Missing expression after where
select t.col1, t.col2, (select count(col1) from tab where col1 = t.col1 and col2 = t.col2 ) "col3" from tab t where [col3] > 1
Error: Missing expression after where
Please explain me what the errors are about
P.S. I don't know why I am unable to mark the query examples as code here. I apologize for the poor readability of those queries
*or#) you need to indent by 8 spaces to make it a "code block" - not with 4 spaces as you do normally.