我有一个具有以下结构的“建议”表:
id(suggest_id) | author_id | accepted(true/false)
我想按最大接受率订购,例如:
Jack had 10 suggests and he accepted 5 (50% acceptance rate)
John had 20 suggests and he accepted 5 (25% acceptance rate)
Steve had 10 suggests and he accepted 8 (80% acceptance rate)
这将返回:史蒂夫、杰克和约翰。
我认为可能必须使用两个 SQL 查询,一个用于建议数量,第二个用于accepted=true
.
也许可以通过一个查询来完成?
我正在使用rails,所以它也可以通过rails来完成。