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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:11:00+00:00 2026-06-04T14:11:00+00:00

I am using a MySQL database and I have a big mysql_query that works

  • 0

I am using a MySQL database and I have a big mysql_query that works completely fine except for this one line.

SELECT game_id, 
COALESCE(
SUM(CASE WHEN game_score = 1 THEN 1 ELSE 0 END) 
- 
SUM(CASE WHEN game_score = 0 THEN 1 ELSE 0 END), 0) AS score 
FROM .... 
WHERE .... 
GROUP BY ....

This line returns me almost all of the numbers that I want, yet they are the same numbers as when I wasn’t using the COALESCE function.
I would like this statement to return me 0 when there is a game_id that has an emptygame_score` field.
Where is my code going wrong?

  • 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-04T14:11:01+00:00Added an answer on June 4, 2026 at 2:11 pm

    you can also use decode function like this —

    SELECT game_id, 
    SUM(DECODE(game_score, null, 0, 0, -1, 1, 0)) AS score 
    FROM .... 
    WHERE .... 
    GROUP BY ....
    

    I have checked this query for working, its fine
    hope it helps you….

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

Sidebar

Related Questions

I am having this big database on one MSSQL server that contains data indexed
I have two databases, one's MySql, one's MSSQL, I'm using php::pdo on both, except
We have a MySQL database that is set up on one of our servers.
I have created a MySQL database using MySQL Workbench. It has about 20 tables.
I am using Mysql database. I have 3 table-: table Column tier_price customer_id,sku(Unique),price,website catalog_product
I'm using a MySQL database. I have a products database where users can search
I am using CakePHP framework with MySQL database and I have problem in saving
I am using MySQL for my database. I have a requirement to store a
I have to store long strings in MySQL database using spring roo. I assumed
I have an SQLite database, eventually will be a MySQL database and I'm using

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.