MySQL Forums
Forum List  »  Newbie

Time syntax question for calculating a set of values
Posted by: John Smith
Date: April 07, 2012 09:08AM

Hello All,
I have a question about determining average data values for a specific time interval (a month in this case ) , for a given set of data, to create a table.
I started with 1 months data (for September 2012), & it gave me the following result:

mysql> SELECT DATE_FORMAT(PaymentDate, '2012-%-%') AS "Month", AVG(PaymentAmt)
AS "Average Payment" FROM Payments WHERE PaymentDate BETWEEN '2012-09-01' AND
'2012-09-30' ;
+---------+-----------------+
| Month | Average Payment |
+---------+-----------------+
| 2012--% | 100.000000 |
+---------+-----------------+
1 row in set (0.00 sec)

I then proceeded to add an extra payment (BETWEEN) range, but instead of getting another row of values, I got the null set

mysql> SELECT DATE_FORMAT(PaymentDate, '2012-%-%') AS "Month", AVG(PaymentAmt)
AS "Average Payment" FROM Payments WHERE PaymentDate BETWEEN '2012-09-01' AND
'2012-09-30' AND PaymentDate BETWEEN '2012-07-01' AND '2012-07-31';
+-------+-----------------+
| Month | Average Payment |
+-------+-----------------+
| NULL | NULL |
+-------+-----------------+
1 row in set (0.00 sec)

I would greatly appreciate it if you could tell me what I need to do to create a table of average values for each month.
Thanks,
John Smith

Options: ReplyQuote


Subject
Written By
Posted
Time syntax question for calculating a set of values
April 07, 2012 09:08AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.