数据表department(系部)中数据如下
id · class person year
1 · A班 · 37 · 2008
2 · B班 · 35 · 2008
3 · A班 · 36 · 2009
4 · B班 · 37 · 2009
怎样检索出该系人数最多的那一年有多少人?
也就是检索出A班+B班最多一年有73人
id · class person year
1 · A班 · 37 · 2008
2 · B班 · 35 · 2008
3 · A班 · 36 · 2009
4 · B班 · 37 · 2009
怎样检索出该系人数最多的那一年有多少人?
也就是检索出A班+B班最多一年有73人
From (Select year,sum(person) as k from department group by year) t
或者
SELECT c FROM (SELECT SUM(pcount) c FROM cls GROUP BY YEAR) temp ORDER BY c DESC LIMIT 1;
From (Select year,sum(person) as rs from department group by year) a在MYSQL中可以运行
select year,sum(person) from department group by year order by sum(person) desc limit 1;