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

  • SEARCH
  • Home
  • 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 7518171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:40:51+00:00 2026-05-30T01:40:51+00:00

I am having the table named tbl_sales and this table contains the fields active

  • 0

I am having the table named tbl_sales and this table contains the fields active and is_featured. Now i am trying to get the count of the records where active=0, active=1, is_featured=1 and is_featured=0. How can i get this in a single query. Can somebody show me a query to get this. I am a newbie to programming and in a self learning process. Need solutions. Thanks in advance

  • 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-30T01:40:53+00:00Added an answer on May 30, 2026 at 1:40 am

    Try using SUM:

    SELECT
      SUM(IF(active=0,1,0)) as nonActiveCount,
      SUM(IF(active=1,1,0)) as activeCount,
      SUM(IF(featured=0,1,0)) as nonfeaturedCount,
      SUM(IF(featured=1,1,0)) as featuredCount
    FROM myTable
    

    The IF(active=0,1,0) says “if active is 1, return a 1. otherwise, return a 0”.

    The SUM around it adds up all the numbers, which are 0 if non-active and 1 if active (etc).

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

Sidebar

Related Questions

I have a table named with Sales having the following columns: Sales_ID|Product_Code|Zone|District|State|Distributor|Total_Sales Now i
I have one table having ID and other attributes. How can I get list
I have an SQL Table named samples, defined like this: sampledate (datetime, 24 records
I have the following query: select column_name, count(column_name) from table group by column_name having
I have a table named b having a column j which is varchar(3) where
I have a table named user. This table has a foreign key to a
I have a table named events , which contains in-game events such as construction
I am having trouble with drilling down some data, this is the table structure
i am new to Rails .. i am having a Table named users (id,name)
I have this quick query but since my table is named User (SQL keyword),

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.