OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
how to write a query to return records has the closest date to end of month

jackltynetzero.com
Date: Fri Jul 02 2004 - 14:34:52 CDT


Hi, guys

I would like to write a query to return all records which has the closest date to the end of month. (Assume that date will be 6/30/2004)

| id | product_id | price | snapshot_date |
+----+------------+--------+---------------+
| 1 | 1 | 99.95 | 2004-06-23 |
| 2 | 1 | 99.74 | 2004-06-27 | *
| 3 | 2 | 101.52 | 2004-06-25 |
| 4 | 2 | 101.85 | 2004-07-01 | *
| 5 | 3 | 100.00 | 2004-06-29 |
| 6 | 3 | 100.50 | 2004-07-01 | *
+----+------------+--------+---------------+

*if there is a tie, it always pick the one after the end of month
The 2, 4, 6 entries shall be return by the query.

Is this possible to write this in pure sql?

Thanks in advance.

Lam

________________________________________________________________
The best thing to hit the Internet in years - NetZero HiSpeed!
Surf the Web up to FIVE TIMES FASTER!
Only $14.95/ month -visit www.netzero.com to sign up today!

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql