This topic requires writing SQL statements,
Retrieve the student number, name and grade of the two students with the highest grades in course C002
Table Structure:
Please write the SQL statement that defines the table structure here. For example:
CREATE TABLE `stu` (
`sno` char(4) NOT NULL,
`sname` char(8) NOT NULL,
`sex` tinyint(1) DEFAULT NULL,
`mno` char(2) DEFAULT NULL,
`birdate` datetime DEFAULT NULL,
`memo` text,
PRIMARY KEY (`sno`),
);
CREATE TABLE `sc` (
`sno` char(4) NOT NULL,
`cno` char(4) NOT NULL,
`grade` decimal(6,1) DEFAULT NULL,
PRIMARY KEY (`sno`,`cno`),
CONSTRAINT `fk_sc_sno` FOREIGN KEY (`sno`) REFERENCES `stu` (`sno`)
);
table sample
Please give a table sample corresponding to the above table structure here. For example
Stu table:
![](https://img-blog.csdnimg.cn/img_convert/f20fc1db8f494549b644cd147326df3e.jpeg)
sc table:
![](https://img-blog.csdnimg.cn/img_convert/40d49d3cd7174ac7840957641d35dd79.jpeg)
Sample output:
Please give a sample output here. For example:
![](https://img-blog.csdnimg.cn/img_convert/0e04c11bf1bd49539e5ba268f5b2db2c.jpeg)
Code length limit 16 KB
Time limit 400 ms
DatabaseMySQL
The result output requires a strict comparison of the order and data
select stu.sno,stu.sname,sc.grade from stu
join sc on
stu.sno=sc.sno
and sc.cno='C002'
group by sno
order by grade desc
limit 2
![](https://img-blog.csdnimg.cn/img_convert/2c7232d4a8d9444cbf66268b4ea01ee0.png)