Skip navigation links

MySQL Forums :: Newbie :: Time syntax question for calculating a set of values


Advanced Search

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
Time syntax question for calculating a set of values John Smith 04/07/2012 09:08AM
Re: Time syntax question for calculating a set of values laptop alias 04/07/2012 10:10AM
Re: Time syntax question for calculating a set of values Rick James 04/09/2012 06:45AM
Re: Time syntax question for calculating a set of values Peter Brawley 04/09/2012 11:35AM


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.