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?
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 | +----------------------------------+---------------------+
| 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 |
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.