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

Retrieve two columns data from one column in MySQL

Suppose a table have a column with values like:

    column
    3
    1
    1
    3
    4
    1
    2

I want to retrieve that how many times there is 1 in column and how many times > 1.
Is there anyway to do this within one query?

I want the data to be fetched like this:

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

one | greater_than_one
 3  |        4

Thanks in advance.

>Solution :

Simple:

select sum(col1=1) as one , 
       sum(col1>1) as greater_than_one
from test_tbl;

https://dbfiddle.uk/348f5YOK

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