如何在MYSQL中选择多个也是重复值的最大值?
为此,请使用联接概念。让我们首先创建一个-
create table DemoTable1389-> (
-> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> StudentMarks int
-> );
使用insert命令在表中插入一些记录。在这里,我们还插入了重复值-
insert into DemoTable1389(StudentMarks) values(40);insert into DemoTable1389(StudentMarks) values(40);
insert into DemoTable1389(StudentMarks) values(68);
insert into DemoTable1389(StudentMarks) values(78);
insert into DemoTable1389(StudentMarks) values(97);
insert into DemoTable1389(StudentMarks) values(97);
insert into DemoTable1389(StudentMarks) values(97);
使用select语句显示表中的所有记录-
select * from DemoTable1389;
这将产生以下输出-
+-----------+--------------+| StudentId | StudentMarks |
+-----------+--------------+
| 1 | 40 |
| 2 | 40 |
| 3 | 68 |
| 4 | 78 |
| 5 | 97 |
| 6 | 97 |
| 7 | 97 |
+-----------+--------------+
7 rows in set (0.00 sec)
以下是选择多个最大值的查询-
select tbl.StudentId,tbl.StudentMarks from DemoTable1389 tbl-> join ( select max(StudentMarks) as MaxMarks from DemoTable1389) tbl1
-> on tbl1.MaxMarks=tbl.StudentMarks;
这将产生以下显示最大值的输出,以及重复项-
+-----------+--------------+| StudentId | StudentMarks |
+-----------+--------------+
| 5 | 97 |
| 6 | 97 |
| 7 | 97 |
+-----------+--------------+
3 rows in set (0.00 sec)
以上是 如何在MYSQL中选择多个也是重复值的最大值? 的全部内容, 来源链接: utcz.com/z/327250.html