給定一個表,使用 INNER JOIN 和 EXCEPT 找到最高分。它直接找到標記。Select max(marks) from Students. 但是如何找到最高使用INNER JOINand EXCEPT?
學生表
| 斯諾 | 姓名 | 分數 |
|---|---|---|
| 1 | 一種 | 90 |
| 2 | 乙 | 95 |
| 3 | C | 96 |
| 4 | D | 82 |
| 5 | 乙 | 87 |
uj5u.com熱心網友回復:
您無需撰寫INNER JOIN或EXCEPT(您的問題被標記為不支持該EXCEPT陳述句的 mysql)即可獲得最高分的學生 ID。寫起來要簡單得多:
select sno from students
where marks = (select max(marks) from students)
結果:
3
如果您使用 INNER JOIN,您只會使事情復雜化,并且本質上也是如此。例子:
select s1.sno, s1.marks from students s1
inner join (select max(marks) as max_mark from students) s2
on s1.marks = s2.max_mark
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/445195.html
上一篇:我有一列,其中有varchar資料,我想將該資料轉換為TIMESTAMP
下一篇:將每組的總和除以總計
