And I guess the real question is, with the code below, should this
retireve the last 2 records in the table (I think I should use ASC)?
On Jan 26, 1:57 pm, pete
<peterbattag...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi-
>
> I have a situation where I would like to get the difference of the
> last 2 records in each column in my DB.
>
> So, lets say I have col1 and col2, with values below.
>
> col1 = 1, 2
> col2 = 3, 4
>
> What I would like to do is iterate through each column name (col1,
> col2) and get the difference of the last 2 records in each. Since it
> doesn''t look like there is a .diff command for active record,
I''d like
> to just store them in a variable and take the difference manually.
>
> I have tried this, but it doesn''t work, what am I doing wrong
here?
>
> # Give me the last 2 rows from col1?
>
> result = Object.find(:all,:limit => 2, :select col1, :order =>
> ''enterdate DESC'')
> diffof_rows = result[0] - result[1]
>
> Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---