From: | jeffrey <johjeffrey(at)hotmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Filling null values |
Date: | 2011-08-05 16:32:47 |
Message-ID: | fbcfd7db-d83b-4e8b-b5b9-ce1e5d58a2f6@y39g2000prd.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I have a table that looks like this:
homeid city date measurement pre/post
123 san francisco 1/2/2003 1458 pre
123 san francisco NULL 1932 post
124 los angeles 2/4/2005 938 pre
124 NULL NULL 266 pre
124 los angeles 7/4/2006 777 post
I'd like to write a query so that I get the following result:
homeid city date measurement pre/post
123 san francisco 1/2/2003 1458 pre
123 san francisco 1/2/2003 1932 post
124 los angeles 2/4/2005 938 pre
124 los angeles 2/4/2005 266 pre
124 los angeles 7/4/2006 777 post
If a city or date is null, then it will fill from other not null
values with the same homeid. If given the choice, it will
preferentially fill from a row where homeid AND pre/post match. But
if that doesn't match, then it will still fill from the same homeid.
Does anyone have ideas for this?
Thanks,
Jeff
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2011-08-05 17:22:59 | Re: Filling null values |
Previous Message | Merlin Moncure | 2011-08-05 16:09:55 | Re: Is there a better way to unnest an entire row? |