On Apr 12, 9:06 am, Michael Lang <[email protected]> wrote:
> I'm trying to update a new column added to a table by selecting summed
> amounts from another table.
>
> DB[:aging_history___ah].filter(:month_group => month_group).
> update(:adjustments => DB[:billing_details___bd].filter(:bd__billing
> => :ah__billing).
> filter(:entry_date =>
> (start_date..end_date)).filter(:transaction_class =>
> 'ADJ').sum(:amount))
>
> month_group, start_date, end_dates are variables passed into the
> function, so irrelevant.
>
> Looking to generate:
>
> update aging_history ah
> set adjustments = (select sum(amount)
> from billing_details bd
> where transaction_class = 'ADJ' and bd.billing = ah.billing)
DB[:aging_history___ah].update_sql(:adjustment=>
DB[:billing_details___bd].
select{sum(amount)}.
filter(:transaction_class=>'ADJ', :bd__billing=>:ah__billing))
=> "UPDATE aging_history AS ah SET adjustment = (SELECT sum(amount)
FROM billing_details AS bd WHERE ((transaction_class = 'ADJ') AND
(bd.billing = ah.billing)))"
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.