I want to count total rows of particular condition and use that value in case condition.
What am i doing wrong here?
Please help…
select count(*) as total
CASE
when total > 3
Then
'true'
else
'false'
end as result
from friendship where userId = '1'
>Solution :
You cannot refer to column aliases within the same select
statement, the expressions are not evaluated in a "left to right" order.
Simply repeat the expression:
select Count(*) as total,
case when Count(*) > 3 then 'true' else 'false' end as result
from friendship
where userId = 1;