Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Select statement for statistical use

Posted on 2011-09-08
2
Medium Priority
?
286 Views
Last Modified: 2012-05-12
I have a table with two rows, a date and a number:

2011-01-01, 45
2011-03-01, 50
2011-03-01, 55

The output I need is:

January, 45
February, 0
Mars, 105

Closest i get is with this select:
SELECT MONTHNAME(date), SUM(number) FROM tableA

GROUP BY MONTH(date)

This gives me:

January, 45
Mars, 105

February is missing - and i need it to feed a diagram.
0
Comment
Question by:Sunsales
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Minh Võ Công earned 2000 total points
ID: 36507808
CREATE PROCEDURE DateList()
BEGIN
  DECLARE v1 INT DEFAULT 1;
 WHILE v1 <13 DO
 SELECT MONTHNAME(date), SUM(number) FROM tableA
 where MONTH(data) = v1
 GROUP BY MONTH(date)
 v1 = v1 +1;
  END WHILE;
END;
0
 
LVL 10

Expert Comment

by:OnALearningCurve
ID: 36509454
Hi Sunsales,,

I might be missing something here but the examples you give seem to be correct.

In your sample table data you have two entries for the month of March

2011-03-01, 50
2011-03-01, 55

and your result set shows a total of 105 for March.

Surely the fix would be to edit the source data?

Hope this make sense,

Mark.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question