rails常用数据库查询操作、方法浅析

2019-09-25 09:50:31于丽

#没有参数时,则:表是空的 ? false : true
Client.exists?
10、计算


#求结果集条数
Client.count(:conditons => "first_name = 'Ryan'")
#求某个字段非空白的条数
Client.count(:age)
#平均值
Client.average("orders_count")
#求最小值
Client.minimum("age")
#求最大值
Client.maximum("age")
#求和
Client.sum("orders_count")