count_by_sql(sql)
Instance Public methods
Returns the result of an SQL statement that should only include a COUNT(*)
in the SELECT part. The use of this method should be restricted to
complicated SQL queries that can't be executed using the ActiveRecord::Calculations class methods. Look
into those before using this.
Parameters
sql - An SQL statement which should return a count query from
the database, see the example below.
Product.count_by_sql âSELECT COUNT(*) FROM sales s, cust