Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7015305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:38:04+00:00 2026-05-27T22:38:04+00:00

Is there a more efficient or something in better practice to get counts than

  • 0

Is there a more efficient or something in better practice to get counts than what I am doing below?

select
   i.org_id,
   o.Org_Name_1,
   count(*) as 'Total Users',
   SUM(CASE WHEN i.email is NULL THEN 1 ELSE 0 END) as 'No Email'
from
   individu i,
   organiz o
where
   i.org_id = o.org_id
group by
   i.org_id, o.Org_Name_1
order by
   count(*) desc
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:38:05+00:00Added an answer on May 27, 2026 at 10:38 pm
    SUM(CASE WHEN i.email is NULL THEN 1 ELSE 0 END) as 'No Email'
    

    can be replaced with because… Quoted from MSDN Count(Transact SQL)

    COUNT(ALL expression) evaluates expression for each row in a group and returns the number of nonnull values.

    When an expression is place in the parenthesis of the COUNT statement, it will evaluate and count only non-null values in that field. Therefore, if you take Count(*) – Count(field) you get the total of all null fields.

    COUNT(*) - COUNT(i.email) AS 'No Email'
    

    Your Query would then look like this:

    SELECT
       i.org_id,
       o.Org_Name_1,
       COUNT(*) AS 'Total Users',
       COUNT(*) - COUNT(i.email) AS 'No Email'
    FROM
       individu i,
       organiz o
    WHERE
       i.org_id = o.org_id
    GROUP BY
       i.org_id, o.Org_Name_1
    ORDER BY
       COUNT(*) DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a more efficient way to clamp real numbers than using if statements
Is there are more efficient way than the following for selecting the third parent?
Is there any time in which a reference type is more efficient than a
Is there an algorithm that is more time efficient than O(n^2) for detecting cycles
Is there a more efficient way to convert an HTMLCollection to an Array, other
I'm wondering if there is a more efficient method for replacing colors in a
I was wondering if there was a more efficient (efficient as in simpler/cleaner code)
There has got to be a more efficient way to do this in Ruby.
Which of these queries is more efficient, and would a modern DBMS (like SQL
I did some HTTP monitoring with WireShark. Are there more tools like this that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.