查询和“s002”号的同学学习的课程完全相同的其他同学的个人信息

select    
    sth.sno,
    sth.sname 
from student sth,
    (select * from sc where sno='s002') a,
    (select * from sc where sno<>'s002') b
where 
    b.sno=sth.sno
having
    sum(case when a.cno=b.cno then 0 else 1 end)    --使用case进行计数
    =
    (select count(cno) from sc where sno='s002')
group by sth.sno,sth.sname

 

                                                                                            
select student.sno,student.sname from student where student.sno in(
  select sc.sno from sc where sc.sno != 's002' 
  and sc.cno in (
      select cno from sc where  sc.sno = 's002'
  ) group by sc.sno 
  having count(sc.cno) = (select count(cno) from sc where sc.sno = 's002' )
  intersect
  select sc.sno  from sc where sc.sno != 's002' group by sc.sno
  having count(sc.cno) = (select count(cno) from sc where sc.sno = 's002')
);

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以给您提供一个简单的Java代码示例来实现在线学习系统程序。以下是代码实现: ``` import java.util.ArrayList; import java.util.List; // 课程类 class Course { private String courseId; // 课程 private String courseName; // 课程名称 private String courseIntro; // 课程介绍 private int selectedNum; // 已选人 public Course(String courseId, String courseName, String courseIntro) { this.courseId = courseId; this.courseName = courseName; this.courseIntro = courseIntro; this.selectedNum = 0; } public String getCourseId() { return courseId; } public void setCourseId(String courseId) { this.courseId = courseId; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public String getCourseIntro() { return courseIntro; } public void setCourseIntro(String courseIntro) { this.courseIntro = courseIntro; } public int getSelectedNum() { return selectedNum; } public void setSelectedNum(int selectedNum) { this.selectedNum = selectedNum; } @Override public String toString() { return "Course{" + "courseId='" + courseId + '\'' + ", courseName='" + courseName + '\'' + ", courseIntro='" + courseIntro + '\'' + ", selectedNum=" + selectedNum + '}'; } } // 学生类 class Student { private String studentId; // 学生 private String studentName; // 学生姓名 private List<Course> selectedCourses; // 已选课程列表 public Student(String studentId, String studentName) { this.studentId = studentId; this.studentName = studentName; this.selectedCourses = new ArrayList<>(); } public String getStudentId() { return studentId; } public void setStudentId(String studentId) { this.studentId = studentId; } public String getStudentName() { return studentName; } public void setStudentName(String studentName) { this.studentName = studentName; } public List<Course> getSelectedCourses() { return selectedCourses; } public void setSelectedCourses(List<Course> selectedCourses) { this.selectedCourses = selectedCourses; } @Override public String toString() { return "Student{" + "studentId='" + studentId + '\'' + ", studentName='" + studentName + '\'' + ", selectedCourses=" + selectedCourses + '}'; } } // 在线学习系统类 class OnlineLearningSystem { private List<Course> courseList; // 课程列表 private List<Student> studentList; // 学生列表 public OnlineLearningSystem() { this.courseList = new ArrayList<>(); this.studentList = new ArrayList<>(); } // 课程加入 public void addCourse(Course course) { courseList.add(course); System.out.println("课程 " + course.getCourseName() + " 添加成功!"); } // 课程撤销 public void removeCourse(String courseId) { Course targetCourse = null; for (Course course : courseList) { if (course.getCourseId().equals(courseId)) { targetCourse = course; break; } } if (targetCourse != null) { courseList.remove(targetCourse); System.out.println("课程 " + targetCourse.getCourseName() + " 撤销成功!"); } else { System.out.println("未找到编为 " + courseId + " 的课程!"); } } // 课程信息修改 public void modifyCourse(String courseId, String courseName, String courseIntro) { Course targetCourse = null; for (Course course : courseList) { if (course.getCourseId().equals(courseId)) { targetCourse = course; break; } } if (targetCourse != null) { targetCourse.setCourseName(courseName); targetCourse.setCourseIntro(courseIntro); System.out.println("课程 " + targetCourse.getCourseName() + " 修改成功!"); } else { System.out.println("未找到编为 " + courseId + " 的课程!"); } } // 课程信息查询 public void queryCourse(String keyword) { List<Course> result = new ArrayList<>(); for (Course course : courseList) { if (course.getCourseId().contains(keyword) || course.getCourseName().contains(keyword)) { result.add(course); } } if (result.size() > 0) { System.out.println("查询结果如下:"); for (Course course : result) { System.out.println(course); } } else { System.out.println("未找到相关课程!"); } } // 学生选课 public void chooseCourse(String studentId, String courseId) { Course targetCourse = null; for (Course course : courseList) { if (course.getCourseId().equals(courseId)) { targetCourse = course; break; } } if (targetCourse != null) { if (targetCourse.getSelectedNum() >= 10) { System.out.println("课程 " + targetCourse.getCourseName() + " 选课人已满!"); } else { Student targetStudent = null; for (Student student : studentList) { if (student.getStudentId().equals(studentId)) { targetStudent = student; break; } } if (targetStudent != null) { if (targetStudent.getSelectedCourses().contains(targetCourse)) { System.out.println("学生 " + targetStudent.getStudentName() + " 已选过该课程!"); } else { targetStudent.getSelectedCourses().add(targetCourse); targetCourse.setSelectedNum(targetCourse.getSelectedNum() + 1); System.out.println("学生 " + targetStudent.getStudentName() + " 选课成功!"); } } else { System.out.println("未找到编为 " + studentId + " 的学生!"); } } } else { System.out.println("未找到编为 " + courseId + " 的课程!"); } } // 学生退课 public void dropCourse(String studentId, String courseId) { Course targetCourse = null; for (Course course : courseList) { if (course.getCourseId().equals(courseId)) { targetCourse = course; break; } } if (targetCourse != null) { Student targetStudent = null; for (Student student : studentList) { if (student.getStudentId().equals(studentId)) { targetStudent = student; break; } } if (targetStudent != null) { if (targetStudent.getSelectedCourses().contains(targetCourse)) { targetStudent.getSelectedCourses().remove(targetCourse); targetCourse.setSelectedNum(targetCourse.getSelectedNum() - 1); System.out.println("学生 " + targetStudent.getStudentName() + " 退课成功!"); } else { System.out.println("学生 " + targetStudent.getStudentName() + " 未选过该课程!"); } } else { System.out.println("未找到编为 " + studentId + " 的学生!"); } } else { System.out.println("未找到编为 " + courseId + " 的课程!"); } } // 学生已选课程查询 public void querySelectedCourse(String studentId) { Student targetStudent = null; for (Student student : studentList) { if (student.getStudentId().equals(studentId)) { targetStudent = student; break; } } if (targetStudent != null) { if (targetStudent.getSelectedCourses().size() > 0) { System.out.println("学生 " + targetStudent.getStudentName() + " 已选课程如下:"); for (Course course : targetStudent.getSelectedCourses()) { System.out.println(course); } } else { System.out.println("学生 " + targetStudent.getStudentName() + " 未选任何课程!"); } } else { System.out.println("未找到编为 " + studentId + " 的学生!"); } } } // 测试类 public class Test { public static void main(String[] args) { OnlineLearningSystem system = new OnlineLearningSystem(); // 添加课程 system.addCourse(new Course("C001", "Java程序设计", "Java基础知识和程序设计")); system.addCourse(new Course("C002", "Web开发技术", "Web开发中的HTML、CSS、JavaScript等技术")); system.addCourse(new Course("C003", "数据库设计", "数据库基础知识和设计技术")); // 查询课程 system.queryCourse("Java"); // 修改课程信息 system.modifyCourse("C001", "Java程序设计(进阶)", "Java高级知识和程序设计"); // 学生选课 system.chooseCourse("S001", "C001"); system.chooseCourse("S001", "C002"); system.chooseCourse("S002", "C001"); system.chooseCourse("S003", "C001"); system.chooseCourse("S004", "C001"); system.chooseCourse("S005", "C001"); system.chooseCourse("S006", "C001"); system.chooseCourse("S007", "C001"); system.chooseCourse("S008", "C001"); system.chooseCourse("S009", "C001"); system.chooseCourse("S010", "C001"); system.chooseCourse("S011", "C001"); // 学生已选课程查询 system.querySelectedCourse("S001"); // 学生退课 system.dropCourse("S001", "C002"); // 课程撤销 system.removeCourse("C003"); } } ``` 以上代码实现了课程加入、撤销、课程信息修改、课程信息查询学生选课、学生退课、学生已选课程查询等功能,您可以根据需要进行修改或完善。同时,需要注意的是,以上代码只是一个简单的实现示例,实际应用中需要考虑到更多的细节问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值