mysql query help please
March 13, 2008 10:43 AM Subscribe
MySQL question: Given a table with a datetime column and several additional columns which may or may not be null, is there an easy way to select the most recent previous non-null value of each column given a specific date?
posted by Nothing to computers & internet (10 answers total)
Given the following table:
| 10/10 | ___3 | NULL | NULL |
| 10/09 | NULL | NULL | NULL |
| 10/08 | NULL | ___2 | NULL |
| 10/07 | NULL | ___5 | NULL |
| 10/06 | ___4 | NULL | ___7 |
given the input "10/08" I would like to retrieve the following row:
| 10/08 | ___4 | ___2 | ___7 |
given the input "10/10" I would like to retrieve the following row:
| 10/08 | ___3 | ___2 | ___7 |
That is, looking backwards from the given date, the most recent non-null value from each column. Is this doable? I hacked something together with nested subqueries, but it is super slow.