Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use count value for case in MYSQL

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading