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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:52:57+00:00 2026-06-04T03:52:57+00:00

I need a query to Count distinct results… My Table ID | stats |

  • 0

I need a query to Count distinct results…

My Table

ID | stats | name
-----------------
1  | 1     | John
2  | 1     | John
3  | 2     | John
4  | 2     | John
5  | 3     | John

i need query like this….

SELECT if( stats = 2, ADD + 1, 0) as ok, if(stats = 3, ADD + 1, 0) as no_ok

Thanks.

  • 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-06-04T03:52:59+00:00Added an answer on June 4, 2026 at 3:52 am

    If you want to simultaneously count the number of rows with multiple specific criteria in a data set, you can use the pattern COUNT(CASE WHEN criteria THEN 1 END). Here’s an example that counts the number of rows for stats = 2, and for stats = 3:

    SELECT
      count(case when stats = 2 then 1 end) as ok,
      count(case when stats = 3 then 1 end) as not_ok
    from
      Table1
    

    Results:

    OK | NOT_OK
    -----------
    2  | 1
    

    Demo: http://www.sqlfiddle.com/#!2/82414/1

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

Sidebar

Related Questions

My current query looks like this: SELECT DISTINCT (member), count( UID ) AS numUID
I have a working query as SELECT p.id, p.name AS ProductName, count(DISTINcT s.salesid) as
Is there a better way of doing a query like this: SELECT COUNT(*) FROM
Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
I have three table I need to query table 1,2 and 3 and select
I have a fairly complex query that looks something like this: create table Items(SomeOtherTableID
I have the following hive query: select count(distinct id) as total from mytable; which
I have a select SQL query which use parallelism, something like this INSERT/*+ APPEND
I need a query which can do the following operation. I have a table
I need a query that will return a table where each column is the

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.