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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:00:30+00:00 2026-06-03T05:00:30+00:00

I have a table as mysql> select * FROM testa; +———+——-+ | month_x |

  • 0

I have a table as

mysql> select * FROM testa;
+---------+-------+
| month_x | money |
+---------+-------+
| 11101   | 12345 |
| 11105   |   100 |
| 11105   |   100 |
| 11105   |   100 |
| 11105   |   100 |
| 11106   | 12345 |
+---------+-------+
6 rows in set (0.00 sec)

where last two digits in the month_x are months now i want my output as

Month   TOTAL
01  12345
02  0
03  0
04  0
05  400
06  12345
07  0
08  0
09  0
10  0
11  0
12  0

IS possible using the If else or case.

  • 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-03T05:00:31+00:00Added an answer on June 3, 2026 at 5:00 am

    For this you need to create a table first with months’ numeric value in it.

    CREATE TABLE `months` (
      `mon` int(11) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    INSERT INTO `months` VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12);
    

    Then execute this query,

    SELECT m.mon, 
           IF(Sum(t.money) IS NULL, 0, Sum(t.money)) AS `money` 
    FROM   testa t 
           RIGHT OUTER JOIN months m 
             ON ( t.month_x%100 = m.mon ) 
    GROUP  BY m.mon; 
    

    Result is,

    +------+-------+
    | mon  | money |
    +------+-------+
    |    1 | 12345 |
    |    2 |     0 |
    |    3 |     0 |
    |    4 |     0 |
    |    5 |   400 |
    |    6 | 12345 |
    |    7 |     0 |
    |    8 |     0 |
    |    9 |     0 |
    |   10 |     0 |
    |   11 |     0 |
    |   12 |     0 |
    +------+-------+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table: mysql> SELECT * FROM `bright_promotion_earnings`; +----+----------+------------+----------+-------+ | id |
I have a table watchlist containing today almost 3Mil records. mysql> select count(*) from
I have the following MySQL query statement: SELECT * FROM table1 INNER JOIN table2
Currently, I have a table being read from like so: ps = con.prepareStatement(SELECT *
I have encountered a problem when trying to select data from a table in
HI, I have a problem with this query SELECT * FROM table WHERE `name`
Here's a sample table to help illustrate my problem: mysql> select * from test;
I have to return data fetched from MySQL table into a php file as
I have a php file that receives data from mySQL table. The mySQL table
Looking for some ideas here... I have a MySQL table that has 100K rows

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.