Monday, 26 August 2013

Can I add a column with a value calculated from joined table?

Can I add a column with a value calculated from joined table?

I am trying to populate a column on my transactions table using the
difference between a timestamp in the transaction table and a timestamp in
the user table. The idea is to normalize the dates to reflect at what
point of a user experience the transactions happened (i.e. how many days
after a user joined was the transaction processed), as such:
update transactions
set days = ceil(extract(days from T.tdate - U.created_at)) +1
from transactions T join users U on T.user_id=U.id
For some reason, all the rows get the same number (262) in the "days"
field after running the query.

No comments:

Post a Comment