新手问题 怎么实现对查询结果计数

jenny0219 · May 14, 2019 · Last by ruby_p replied at May 17, 2019 · 1299 hits

在 rails 中怎么实现 sql 语句 SELECT test.result,count(test.result) FROM testWHERE id=100 GROUP BY test.result

试试这个

Test
  .select(
    :result,
    'COUNT(result) AS results_count'
  )
  .where(id: 100)
  .group(:result)
Test.where(id: 100).group(:result).count
Reply to gakki

这个计数明显不对吧

You need to Sign in before reply, if you don't have an account, please Sign up first.