0
我有一個「建議」表結構如下:錄取率與SQL語句
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來完成。
使用'HAVING'而不是'WHERE'來過濾聚合。例如:'HAVING count(*)> 10' – podiluska
謝謝!順便說一下,GROUP BY必須在HAVING之前 –