Thursday, 15 April 2010

database - MySQL Delete Rows Based Upon Max Value of Column -



database - MySQL Delete Rows Based Upon Max Value of Column -

i have table ('conditions') contains column titled "date" delete of rows not equal current date (as determined max value of date(max(date)). partial table result:

| date | time | observed | temp | heatindex | windchill | relhumidity | wind | 14-06-21 | 19:30 | scattered clouds | 85.9 | 91 | na | 61% | 2 | | 14-06-21 | 20:30 | clear | 83.2 | 88 | na | 67% | 3 | | 14-06-21 | 21:30 | clear | 80.7 | 85 | na | 74% | 5 | | 14-06-21 | 22:30 | clear | 79.5 | 83 | na | 76% | 4 | | 14-06-21 | 23:30 | clear | 78.4 | 81 | na | 79% | 4 | | 14-06-22 | 00:30 | clear | 77.6 | na | na | 82% | 3 | | 14-06-22 | 01:30 | clear | 77.1 | na | na | 83% | 3 | | 14-06-22 | 02:30 | scattered clouds | 77.3 | na | na | 84% | 2 | | 14-06-22 | 03:30 | clear | 77.1 | na | na | 83% | 2 | | 14-06-22 | 04:30 | clear | 76.6 | na | na | 86% | 4 |

so after command, see next only:

| 14-06-22 | 00:30 | clear | 77.6 | na | na | 82% | 3 | | 14-06-22 | 01:30 | clear | 77.1 | na | na | 83% | 3 | | 14-06-22 | 02:30 | scattered clouds | 77.3 | na | na | 84% | 2 | | 14-06-22 | 03:30 | clear | 77.1 | na | na | 83% | 2 | | 14-06-22 | 04:30 | clear | 76.6 | na | na | 86% | 4 |

i tried:

delete conditions date <> max(date);

but received:

error 1111 (hy000): invalid utilize of grouping function

the lastly row current date. have considered adding id column , sorting desc, want lastly row recent entry. every time insert info (python) database, script containing delete executed.

pretty sure can't utilize max same reason can't sub-query current table on delete.

what can utilize curdate()

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_curdate

delete conditions date <> curdate();

mysql database sql-delete

No comments:

Post a Comment