打印参加最多课程的学生的姓名和 sid(s)
注册
sid class number
1 23
2 54
1 54
3 43
1 43
2 43
学生 sid 的名字
1 sagar
2 kiran
3 ravi
4 vishal
输出
sid sname
1 sagar
打印参加最多课程的学生的姓名和 sid(s)
注册
sid class number
1 23
2 54
1 54
3 43
1 43
2 43
学生 sid 的名字
1 sagar
2 kiran
3 ravi
4 vishal
输出
sid sname
1 sagar
按学生分组注册,按人数排序和使用限制1:
select s.id, s.name
from student s
join enroll e on e.sid = s.id
group by s.id, s.name
order by count(*) desc
limit 1
请注意您不需要选择 count(*)
- 您可以简单地参考它。
我想这会对你有所帮助
SELECT <column_name> FROM <table_name> WHERE <column_name>=
(SELECT <column_name>
FROM (SELECT <column_name>, count(*) as cnt FROM <table_name> GROUP BY <column_name>) AS foo
WHERE foo.cnt=(SELECT MAX(c) FROM (SELECT <column_name>,count(*) AS c FROM <column_name> GROUP BY <column_name>) AS bar)) limit 1