Solved

Select statement for statistical use

Posted on 2011-09-08
2
276 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 500 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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