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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:15:53+00:00 2026-05-30T21:15:53+00:00

im sure this is easy but im having a block I am trying to

  • 0

im sure this is easy but im having a block I am trying to write some sql against a single table that has (simplified for example)

RunName, Result
foo,     pass
foo,     pass
foo,     fail 
foo,     pass
boo,     pass
boo,     fail
boo,     fail
soo,     pass

I was a query that will return a count of pass or fail for each name

something like for fail

foo, 1
boo, 2
soo, 0

and for pass

foo, 3
boo, 1
soo, 1
  • 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-30T21:15:54+00:00Added an answer on May 30, 2026 at 9:15 pm

    Normally you’d do a simple COUNT and GROUP BY RunName, but that will not show “zero results” like soo’s fails.

    This should work even for zero results (on MySQL)

    SELECT RunName, SUM(Result='fail')
    FROM TableA
    GROUP BY RunName;
    

    Demo here.

    Edit: As Aaron points out, that only works on MySQL, this works on SQL Server also;

    SELECT  RunName, SUM(CASE WHEN Result = 'fail' THEN 1 ELSE 0 END) as fails
    FROM   TableA
    GROUP BY RunName
    

    Demo here.

    Edit2: As Marcus points out, it’s may not be a very index friendly way of doing the query, so if you have a primary key you may be better off doing a self join with a count/group to get the correct result;

    SELECT a.RunName, COUNT(b.Result)
    FROM TableA a LEFT JOIN TableA b ON a.id=b.id AND b.Result='fail'
    GROUP BY RunName
    

    Demo here.

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

Sidebar

Related Questions

I am sure this is an easy question, but one that has escaped me
I'm having a 'blonde moment' here - I'm sure this is easy but I
I'm sure this is relatively easy and straightforward, but I'm having no success figuring
I'm sure this is easy for you guys, but I'm having a hard time
I'm sure this is an easy command in R, but for some reason, I'm
I'm sure this has been asked before in some other way that I just
I am sure this is easy - but I can't figure it out right
New to javascript, but I'm sure this is easy. Unfortunately, most of the google
I'm sure this is an easy question, but I don't have an answer for.
Im sure this question is so easy for all you experts, but I am

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.