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 4535876
In Process

The Archive Base Latest Questions

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

I have this table customerDetail, in which there’s a field c_type, in which a

  • 0

I have this table customerDetail, in which there’s a field c_type, in which “a” represents “active” and “d” represents “not-active”. Now I have to find the count of both of them in same query.
I used these but no result.

SELECT Count(c_type) AS Active, Count(c_type) AS Not_Active  
FROM customerDetail  
WHERE c_type="a" OR c_type="d"

of course I know it obviously looks dirty, but I have also tried this, but this didn’t worked either-

SELECT
    Count(customerDetail.c_type) AS Active,
    Count(customerDetail_1.c_type) AS Not_Active  
FROM customerDetail INNER JOIN customerDetail AS customerDetail_1  
ON customerDetail.Id=customerDetail_1.Id  
WHERE (customerDetail.c_type="a") AND (customerDetail_1.c_type="d")

But again it wasn’t helpful either, so can anyone please tell me how am I supposed to know the count of both active and non-active in same query?

  • 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-21T14:27:38+00:00Added an answer on May 21, 2026 at 2:27 pm
    SELECT
      SUM(IIF(c_type = "a", 1, 0)) AS Active,
      SUM(IIF(c_type = "d", 1, 0)) AS Not_Active,
    FROM customerDetail
    WHERE c_type IN ("a", "d")
    

    That was for MS Access.

    Somehow I missed the tsql tag when first saw this question. In Transact-SQL you can employ a CASE construct, which can be said of as a more powerful equivalent of IIF in Access:

    SELECT
      SUM(CASE c_type WHEN 'a' THEN 1 ELSE 0 END) AS Active,
      SUM(CASE c_type WHEN 'd' THEN 1 ELSE 0 END) AS Not_Active,
    FROM customerDetail
    WHERE c_type IN ('a', 'd')
    

    Actually, in T-SQL I would use COUNT instead of SUM, like this:

    SELECT
      COUNT(CASE c_type WHEN 'a' THEN 1 END) AS Active,
      COUNT(CASE c_type WHEN 'd' THEN 1 END) AS Not_Active,
    FROM customerDetail
    WHERE c_type IN ('a', 'd')
    

    Here 1 in each CASE expression can be replaced by anything as long as it is not NULL (NULLs are not counted). If the ELSE part is omitted, like in the query above, ELSE NULL is implied.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table: old_id integer NOT NULL, new_id integer Now I want to
I have this table which contains a field called 'icon_for' which I have been
I have this table in an Oracle DB which has a primary key defined
I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT
I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
I have this table: CREATE TABLE `test` ( `ID` int(11) NOT NULL auto_increment, `text`
I have this table: CREATE TABLE `point` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `siteid`
I have this table CREATE TABLE IF NOT EXISTS `links` ( `link_id` int(20) NOT
I have this table in a SQL Server 2008 R2 instance which I have
I have this table: -id : primary key -code : CHAR(8) unique Is there

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.