MySQL Forums
Forum List  »  Newbie

Re: Time syntax question for calculating a set of values
Posted by: Rick James
Date: April 09, 2012 06:45AM

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';
You want rows that are simultaneously in September and in July?
Perhaps you meant OR instead of AND. (The English language is tricky.)

Reade DATE_FORMAT again...
mysql> SELECT DATE_FORMAT(NOW(), '2012-%-%');
+--------------------------------+
| DATE_FORMAT(NOW(), '2012-%-%') |
+--------------------------------+
| 2012--%                        |
+--------------------------------+


mysql> SELECT DATE_FORMAT(NOW(), '2012-%m-%d'), NOW();
+----------------------------------+---------------------+
| DATE_FORMAT(NOW(), '2012-%m-%d') | NOW()               |
+----------------------------------+---------------------+
| 2012-04-09                       | 2012-04-09 05:44:22 |
+----------------------------------+---------------------+

Options: ReplyQuote


Subject
Written By
Posted
Re: Time syntax question for calculating a set of values
April 09, 2012 06:45AM


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.