2

I have the following query:

SELECT COUNT(package) as advanced_count FROM users WHERE package = '2' AND site_url is     NOT NULL;

What I want to do is have 2 more queries to get the basic_count and then the total_count which is basic + advanced.

My other basic query is:

SELECT count(package) as basic_count FROM users WHERE package = '1' AND site_url is NOT NULL

But I'm not sure how to combine the two so it is just one query, and then plus adding the total number in there as well.

I hope someone can point me in the right directions.

Thank you!

1 Answer 1

4
SELECT SUM(CASE WHEN package = '2' THEN 1 ELSE 0 END) AS advanced_count,
       SUM(CASE WHEN package = '1' THEN 1 ELSE 0 END) AS basic_count,
       COUNT(*) AS total_count
    FROM users
    WHERE site_url IS NOT NULL
        AND package IN ('1', '2');
Sign up to request clarification or add additional context in comments.

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.