【发布时间】:2020-11-26 12:58:26
【问题描述】:
我有这样的疑问:
SELECT s_name, count(Mark)
FROM specialty
join interns_specialty on specialty.specialty_id = interns_specialty.specialty_id
join practice_result on practice_result.Intern_id = interns_specialty.intern_id
where Mark=5
group by specialty.specialty_id
ORDER by count(Mark) DESC;
That is what i get from my quire, i need to take the row with the max count of excellent marks, if there is two or more such rows, i must to get it all
我需要得到一个带有专业名称的字符串,它的分数比其他字符串高。
但是我可以t understand how to do this. I tried to use "Limit", but if i have two or more specialties - it will be work incorrect. I couldnt 将 MAX 与另一个聚合函数一起使用,所以我需要一个建议。
【问题讨论】:
-
您通常
GROUP BY与您SELECT相同的列,除了那些是设置函数的参数的列。 -
如果不同的
s_name(取自哪个表?)值可能匹配相同的specialty.specialty_id,那么您的查询没有意义。 -
@Akina 我不明白,你说这个查询没有意义,但它有效。它给了我特殊的标记。所以我只需要选择5个以上的专业或专业。我做错了什么?
-
@jarlh 这是什么意思?我需要做什么?
-
条件“多个
s_name匹配同一个specialty.specialty_id”是否为真?如果是这样 - 你从所有可能的值中只获得一个值......那有什么意义?