RAILS是否具有GROUP BY ... WITH ROLLUP查询? [英] Does RAILS have GROUP BY...WITH ROLLUP query?

查看:85
本文介绍了RAILS是否具有GROUP BY ... WITH ROLLUP查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Rails是否支持ROLLUP?

$ b是一个非常酷的功能。

GROUP BY ... WITH ROLLUP
$ b

如何编写查询,如

$ p $ .group('column1,column2 ,. ...')


解决方案

/ b>

  @rollup = People.select(:职业,:状态,'COUNT(`状态`)cnt')
.group(:occupation,'WITH WITH ROLLUP')
.to_a.map(&:attributes)

然后在我看来使用@ rollup.first [state]等。


GROUP BY... WITH ROLLUP is a cool feature in sql.

Does Rails support ROLLUP ?

How can I write the query like,

.group('column1, column2,....')

解决方案

I normally use it like

@rollup = People.select(:occupation, :state, 'COUNT(`state`) as cnt')
             .group(:occupation, 'state WITH ROLLUP')
             .to_a.map(&:attributes)

then in my view use @rollup.first["state"] etc.

这篇关于RAILS是否具有GROUP BY ... WITH ROLLUP查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆