我有一张桌子:法官(jname char(25),法学院char(25))。
我试图在一次sql调用中检索哈佛大学的评委人数和耶鲁大学的评委人数。我知道我能做到
SQL调用1)
select LawSchool, count(*) as cnt from Judges where LawSchool = 'Harvard'
SQL调用2)
select LawSchool, count(*) as cnt from Judges where LawSchool = 'Yale'
但是,有没有一种方法可以在一次sql调用中检索上耶鲁大学的评委人数和上哈佛大学的评委人数,但将它们存储在两个变量(如cnt和cnt2)中?
最佳答案
select LawSchool, count(*) as cnt
from Judges
where LawSchool in ('Harvard','Yale')
Group By LawSchool