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

CALCULATE HOW MANY 1 IN A GIVEN TABLE

Hello all in SQL we have to used a query to get a desired output as we want. sometimes we have to write a small and large query to get a same output.

i have a problem statement where i want to calculate a count of 1 in following table:

enter image description here

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

i want to calculate a count of sum.

>Solution :

With sample data you posted, one option is

SQL> with test (a, b, c, d) as
  2    (select 1, 0, 0, 0 from dual union all
  3     select 0, 1, 0, 0 from dual union all
  4     select 0, 0, 1, 0 from dual union all
  5     select 0, 0, 0, 1 from dual
  6    )
  7  select sum(a + b + c + d) result
  8  from test;

    RESULT
----------
         4

SQL>
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