view on index pages data from custom SQL statements

I need to show on my index page in one of the collumns data that would
be result of a SQL statment. Is there a universal way to do it? In my
current case I have table A and B, A has many B, B belongs to A. In my
A's index page I need to have data that would be the result of such
SQL statement:
select count(*) from B where A_id=x and B.number > y
The result of this statement is a number and I need to show this
number in one collumn.

I need to show on my index page in one of the collumns data that would
be result of a SQL statment. Is there a universal way to do it? In my
current case I have table A and B, A has many B, B belongs to A. In my
A's index page I need to have data that would be the result of such
SQL statement:
select count(*) from B where A_id=x and B.number > y

Don't use an sql statement, use the ActiveRecord API. Assuming that
you have an A object, an_a, then something like
the_count = an_a.bs.find( :all, :conditions => { :number => x } ).count
should do the trick (untested).

Colin

named scopes

http://railscasts.com/episodes/108-named-scope