查询所有学生至2019-01-01时的年龄(展示形式: XX years XX mons XX days); 查询所有课程中的最高分、最低分、平均分和及格率,按课程id升序输出。MYSQI代码
时间: 2024-03-01 09:53:16 浏览: 184
学生分数查询
查询所有学生至2019-01-01时的年龄(展示形式: XX years XX mons XX days):
```
SELECT CONCAT(
FLOOR(DATEDIFF('2019-01-01', birthday) / 365.25), ' years ',
FLOOR((DATEDIFF('2019-01-01', birthday) % 365.25) / 30.44), ' mons ',
FLOOR((DATEDIFF('2019-01-01', birthday) % 365.25) % 30.44), ' days'
) AS age
FROM students;
```
查询所有课程中的最高分、最低分、平均分和及格率,按课程id升序输出:
```
SELECT
course_id,
MAX(score) AS max_score,
MIN(score) AS min_score,
AVG(score) AS avg_score,
SUM(score >= 60) / COUNT(*) AS pass_rate
FROM scores
GROUP BY course_id
ORDER BY course_id ASC;
```
阅读全文