查询学生成绩

本文介绍了一种SQL查询方法,用于查找特定学生在特定课程中获得最高分数的时间。通过使用子查询和连接操作,可以有效地从数据库中检索所需信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `stu_id` int(11) DEFAULT NULL,
  `class_id` int(11) DEFAULT NULL,
  `score` int(11) DEFAULT NULL,
  `time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

查询某个同学某门课获得最高分数的时间:

SELECT
    time
FROM
    (
        SELECT
            stu_id AS stu_id,
            class_id AS class_id,
            max(score) AS score
        FROM
            student1
        WHERE
            stu_id = 1
        AND class_id = 1
        GROUP BY
            stu_id,
            class_id
    ) student2,
    student1
WHERE
    student1.stu_id = student2.stu_id
AND student1.class_id = student2.class_id
AND student1.score = student2.score
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值