我正在尝试使用条件计算一列
表
select* from policies
|policies|
|id| |client_id| |expiration_date
1 1 2013-10-10
2 1 2013-10-10
3 2 2013-10-10
|clients|
|id| |name|
1 ABC
2 CDE
3 EFG
我想要
select *,count(number_expirations) from policies where(client=1)
select *,count(number_expirations) from policies where(client=2)
|policies|
|id| |client_id| |number_of_expirations|
1 1 2
3 2 1
这是咨询
@count = Policy.count('expiration_date',:joins=> :client,:conditions=>['name =?',params[:name])
但我正在尝试按 client_id 计算 expire_date
我将非常感谢帮助。