0

I have the following queries:

SELECT count(id) from table_1 WHERE field_1 = 1

SELECT count(id) from table_1 WHERE field_2 = 1

SELECT count(id) from table_1 WHERE field_2 = 1

Can this be done in a Single Query.. only one table is use but 3 outputs like:

    count(id) | count(id) | count(id)<br>
    12        | 44        | 55

2 Answers 2

2

Yes you can use get the result by using an aggregate function with a CASE expression similar to the following:

select
  sum(case when field_1 = 1 then 1 else 0 end) field1Total,
  sum(case when field_2 = 1 then 1 else 0 end) field2Total
from table_1

You will add more sum(case...) expression for the remaining items that you want to total.

Sign up to request clarification or add additional context in comments.

Comments

0
Select Distinct (Select Count(id) from table_1 where field1=1)as id1, (Select Count(id) from table_1 where field2=1)as id2  from table_1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.