有以下三个表:(共10分,每题5分) student(student_id,student_name,student_age) 分别代表:学号,学生姓名,所属单位,学习年龄 course(course_id,course_name) 分别代表:课程编号,课程名称 stu_cour(student_id,course_id,grade) 分别代表:学号,所选课程编号,学习成绩 请写出相应的sql语句: 1.统计选修了课程的人数(选修多门时,只计算一次) 2.查询选课在3门以上(包括3门)的学生,要求显示学号,姓名,平均分,选课门数,按平均分降序排序 2、给一个不多于 5 位的正整数, 要求: 一、 求它是几位数, 二、 逆序打印出各位数字。
时间: 2023-03-14 07:03:58 浏览: 140
1SELECT COUNT(DISTINCT student_id) FROM stu_cour;
2.SELECT student_id, student_name, AVG(grade) AS avg_grade, COUNT(*) AS course_num FROM student LEFT JOIN stu_cour ON student.student_id=stu_cour.student_id GROUP BY student_id HAVING COUNT(*)>=3 ORDER BY avg_grade DESC;
3.请输入一个不多于5位的正整数:
相关问题
有以下三个表:(共10分,每题5分) student(student_id,student_name,student_age) 分别代表:学号,学生姓名,所属单位,学习年龄 course(course_id,course_name) 分别代表:课程编号,课程名称 stu_cour(student_id,course_id,grade) 分别代表:学号,所选课程编号,学习成绩 请写出相应的sql语句: 1.统计选修了课程的人数(选修多门时,只计算一次) 2.查询选课在3门以上(包括3门)的学生,要求显示学号,姓名,平均分,选课门数,按平均分降序排序
1 SELECT COUNT(DISTINCT student_id) FROM stu_cour; 2. SELECT student_id,student_name,AVG(grade) AS avg_grade,COUNT(*) AS course_nums FROM student JOIN stu_cour USING(student_id) GROUP BY student_id HAVING COUNT(*) >= 3 ORDER BY avg_grade DESC;
改错#include<iostream> #include<string.h> using namespace std; class Teacher{ public: string teacher_name; int teacher_age; string teacher_duty; teacher(string teacher_name,int teacher_age){ this->teacher_name=teacher_name; this->teacher_age=teacher_age; teacher_duty="教学"; } }; class Student{ public: string student_name; int student_id; string student_duty; student(string student_name,int student_id){ this->student_name=student_name; this->student_id=student_id; student_duty="学习"; } }; class Graduate{ public: string graduate_name; int graduate_age; int graduate_id; string graduate_duty; graduate(string graduate_name,int graduate_age,int graduate_id){ this->graduate_name=graduate_name; this->graduate_age=graduate_age; this->graduate_id=graduate_id; graduate_duty="教学和学习"; } }; int main(){ Teacher teacher("Tom", 35); Student student("John", 2021000); Graduate graduate("Mary", 25, 20210002); cout << teacher.teacher_name << " " << teacher.teacher_age<< " " << teacher.teacher_duty<< endl; cout << student.student_name<< " " << student.student_id << " " << student.student_duty<< endl; cout << graduate.graduate_name<< " " << graduate.graduate_age << " " << graduate.graduate_id<< " " << graduate.graduate_duty<< endl; return 0; }
在类的定义中,构造函数的名称应该与类名完全相同,而你的代码中构造函数的名称与类名不一致,需要修改为以下代码:
```c++
#include<iostream>
#include<string.h>
using namespace std;
class Teacher{
public:
string teacher_name;
int teacher_age;
string teacher_duty;
Teacher(string teacher_name,int teacher_age){
this->teacher_name=teacher_name;
this->teacher_age=teacher_age;
teacher_duty="教学";
}
};
class Student{
public:
string student_name;
int student_id;
string student_duty;
Student(string student_name,int student_id){
this->student_name=student_name;
this->student_id=student_id;
student_duty="学习";
}
};
class Graduate{
public:
string graduate_name;
int graduate_age;
int graduate_id;
string graduate_duty;
Graduate(string graduate_name,int graduate_age,int graduate_id){
this->graduate_name=graduate_name;
this->graduate_age=graduate_age;
this->graduate_id=graduate_id;
graduate_duty="教学和学习";
}
};
int main(){
Teacher teacher("Tom", 35);
Student student("John", 2021000);
Graduate graduate("Mary", 25, 20210002);
cout << teacher.teacher_name << " " << teacher.teacher_age<< " " << teacher.teacher_duty<< endl;
cout << student.student_name<< " " << student.student_id << " " << student.student_duty<< endl;
cout << graduate.graduate_name<< " " << graduate.graduate_age << " " << graduate.graduate_id<< " " << graduate.graduate_duty<< endl;
return 0;
}
```
阅读全文