rails 各种分组统计查询

SpecialGroup.group(:special_type).count
select special_type,count(*) from special_groups group by special_type

SpecialGroup.group(:special_type).count(:sno)
select special_type,count(sno) from special_groups group by special_type

SpecialGroup.group(:special_type).count("distinct sno")
select special_type,count(distinct sno) from special_groups group by special_type

SpecialGroup.group(:user_id, :name).sum(:count)
SELECT SUM(`special_groups`.`count`) AS sum_count, `special_groups`.`user_id` AS special_groups_user_id, `special_groups`.`name` AS special_groups_name FROM `special_groups` GROUP BY `special_groups`.`user_id`, `special_groups`.`name
 
posted @ 2018-06-12 11:00  吕兴杰  阅读(1011)  评论(0编辑  收藏  举报