如何在activerecord
中进行查询:
SELECT col1, COUNT(col1) AS count FROM tab1
WHERE col2='sometext'
GROUP BY col1
ORDER BY count DESC
LIMIT 10
预期产出:
col1 count
--------------
name1 247
name5 182
name4 96
答案 0 :(得分:0)
这是:
Model
.select('col1, COUNT(col1) AS count')
.where(col2: 'sometext')
.group(:col1)
.order('count DESC')
.limit(10)