On 9 November 2010 14:48, Marnen Laibow-Koser <[email protected]> wrote:
>> Mercedes     CL63 why in two times is there any factor to distinguish in
>> between than type and Brand?
>
> Good catch.  I was too focused on the proximate question.

I'd assume (and happy to be proved wrong if the OP wants to confirm)
that the "cars" table has other fields that identify different
instances of physical cars (say, for a vehicle dealership tracking its
sales), and there are fields other than *just* make and model in the
row (such as colour, engine size, fuel, etc)


On 9 November 2010 13:37, Marnen Laibow-Koser <[email protected]> wrote:
>> How can I generate such an output? I have really no clue how to start.
>
> You would do this by using SQL aggregate functions (in this case,
> COUNT(*) ).  If you don't know about those, then your friendly local SQL
> reference is your first stop.

In addition to using the SQL functions, Ruby and Rails both include
functions for grouping (and sort, if you wish) enumerable objects.
Have a look at:
http://api.rubyonrails.org/classes/Enumerable.html#method-i-group_by
http://ruby-doc.org/core/classes/Enumerable.html

The choice as to whether to do the same thing in code or in the DB is
down to you, and your evaluation of the efficiency/benefit one may
give you over the other (personal preference comes into it a lot too!
:-)

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to