我正在尝试同时做一个select
和count
。
这是我的代码:
@count = Policy.find(:all,:conditions=>['state= 0 AND deleted = 0']
####i want to count all the policies that has 1 client by document
@count = Policy.count(:joins => :client,:conditions => ['doc_jur LIKE ? OR doc_nat LIKE ?', "%#{params[:doc]}%","%#{params[:doc]}%" ])
我怎样才能在一行(一个动作)中做到这一点?
我想:
SELECT count(*) AS count_all FROM `policies`
where state= 0 AND deleted = 0
INNER JOIN `clients` ON `clients`.id = `policies`.client_id
WHERE (doc_jur LIKE '%20535920746%' OR doc_nat LIKE '%20535920746%')