查询存在有85分以上成绩的课程名称,学时,学分。
时间: 2024-03-03 13:50:57 浏览: 138
好的,您可以通过以下 SQL 语句来查询存在有85分以上成绩的课程名称,学时,学分:
```
SELECT DISTINCT CourseName, CourseHour, CourseCredit
FROM Score, Course
WHERE Score.CourseId = Course.CourseId AND Score.Score >= 85;
```
这个 SQL 语句使用了 JOIN 操作将成绩表 Score 和课程表 Course 进行关联,并使用 WHERE 子句筛选出成绩大于等于 85 分的记录。最后使用 DISTINCT 关键字去重,以展示每个不同的课程名称、学时和学分组合的结果。
相关问题
c语言学生管理系统,可以在原有学生表增删查改学生,列表显示所有学生,学生表包括学号姓名性别出生日期电话号码,已修课程门数,已获得学分,缴费总额。 可以在原有缴费表增删查改缴费记录,缴费表包括缴费编号学号缴费时间金额工作人员。 对原有的课程表进行增删查改,课程表包括课程代码课程名称学时学分 对原有的成绩表增删查改,成绩表包括课程学号学期平时成绩考试成绩及派生的总评成绩已获得学分,总评成绩大于等于60才能获得学分,否则为0。总评成绩=平时成绩*0.4+考试成绩*0.6。
这是一个C语言学生管理系统的示例代码,可以在原有的学生表、缴费表、课程表和成绩表上进行增删查改操作。请注意,此示例代码仅提供了基本的操作功能,您可以根据实际需求进行修改和扩展。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
char studentID[10];
char name[20];
char gender[10];
char birthdate[15];
char phoneNumber[15];
int completedCourses;
float earnedCredits;
float totalPayment;
} Student;
typedef struct {
int paymentID;
char studentID[10];
char paymentDate[15];
float amount;
char staff[20];
} Payment;
typedef struct {
char courseCode[10];
char courseName[20];
int hours;
float credits;
} Course;
typedef struct {
char courseCode[10];
char studentID[10];
int semester;
float regularGrade;
float examGrade;
float totalGrade;
float earnedCredits;
} Grade;
void addStudent(FILE *file) {
Student newStudent;
printf("Enter student ID: ");
scanf("%s", newStudent.studentID);
printf("Enter student name: ");
scanf("%s", newStudent.name);
printf("Enter student gender: ");
scanf("%s", newStudent.gender);
printf("Enter student birthdate: ");
scanf("%s", newStudent.birthdate);
printf("Enter student phone number: ");
scanf("%s", newStudent.phoneNumber);
printf("Enter completed courses: ");
scanf("%d", &newStudent.completedCourses);
printf("Enter earned credits: ");
scanf("%f", &newStudent.earnedCredits);
printf("Enter total payment: ");
scanf("%f", &newStudent.totalPayment);
fprintf(file, "%s %s %s %s %s %d %.2f %.2f\n", newStudent.studentID, newStudent.name, newStudent.gender, newStudent.birthdate, newStudent.phoneNumber, newStudent.completedCourses, newStudent.earnedCredits, newStudent.totalPayment);
printf("Student added successfully.\n");
}
void deleteStudent(FILE *file) {
char studentID[10];
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter student ID to delete: ");
scanf("%s", studentID);
while (fgets(line, sizeof(line), file)) {
if (strncmp(line, studentID, strlen(studentID)) != 0) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("students.txt");
rename("temp.txt", "students.txt");
printf("Student deleted successfully.\n");
}
void displayStudents(FILE *file) {
char line[200];
printf("---------- Student List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("-----------------------------------\n");
}
void addPayment(FILE *file) {
Payment newPayment;
printf("Enter payment ID: ");
scanf("%d", &newPayment.paymentID);
printf("Enter student ID: ");
scanf("%s", newPayment.studentID);
printf("Enter payment date: ");
scanf("%s", newPayment.paymentDate);
printf("Enter amount: ");
scanf("%f", &newPayment.amount);
printf("Enter staff name: ");
scanf("%s", newPayment.staff);
fprintf(file, "%d %s %s %.2f %s\n", newPayment.paymentID, newPayment.studentID, newPayment.paymentDate, newPayment.amount, newPayment.staff);
printf("Payment added successfully.\n");
}
void deletePayment(FILE *file) {
int paymentID;
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter payment ID to delete: ");
scanf("%d", &paymentID);
while (fgets(line, sizeof(line), file)) {
int currentPaymentID;
sscanf(line, "%d", ¤tPaymentID);
if (currentPaymentID != paymentID) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("payments.txt");
rename("temp.txt", "payments.txt");
printf("Payment deleted successfully.\n");
}
void displayPayments(FILE *file) {
char line[200];
printf("---------- Payment List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("-----------------------------------\n");
}
void addCourse(FILE *file) {
Course newCourse;
printf("Enter course code: ");
scanf("%s", newCourse.courseCode);
printf("Enter course name: ");
scanf("%s", newCourse.courseName);
printf("Enter course hours: ");
scanf("%d", &newCourse.hours);
printf("Enter course credits: ");
scanf("%f", &newCourse.credits);
fprintf(file, "%s %s %d %.2f\n", newCourse.courseCode, newCourse.courseName, newCourse.hours, newCourse.credits);
printf("Course added successfully.\n");
}
void deleteCourse(FILE *file) {
char courseCode[10];
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter course code to delete: ");
scanf("%s", courseCode);
while (fgets(line, sizeof(line), file)) {
if (strncmp(line, courseCode, strlen(courseCode)) != 0) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("courses.txt");
rename("temp.txt", "courses.txt");
printf("Course deleted successfully.\n");
}
void displayCourses(FILE *file) {
char line[200];
printf("---------- Course List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("----------------------------------\n");
}
void addGrade(FILE *file) {
Grade newGrade;
printf("Enter course code: ");
scanf("%s", newGrade.courseCode);
printf("Enter student ID: ");
scanf("%s", newGrade.studentID);
printf("Enter semester: ");
scanf("%d", &newGrade.semester);
printf("Enter regular grade: ");
scanf("%f", &newGrade.regularGrade);
printf("Enter exam grade: ");
scanf("%f", &newGrade.examGrade);
newGrade.totalGrade = newGrade.regularGrade * 0.4 + newGrade.examGrade * 0.6;
newGrade.earnedCredits = (newGrade.totalGrade >= 60) ? 1.0 : 0.0;
fprintf(file, "%s %s %d %.2f %.2f %.2f %.2f\n", newGrade.courseCode, newGrade.studentID, newGrade.semester, newGrade.regularGrade, newGrade.examGrade, newGrade.totalGrade, newGrade.earnedCredits);
printf("Grade added successfully.\n");
}
void deleteGrade(FILE *file) {
char courseCode[10];
char studentID[10];
char line[200];
FILE *tempFile = fopen("temp.txt", "w");
printf("Enter course code to delete: ");
scanf("%s", courseCode);
printf("Enter student ID to delete: ");
scanf("%s", studentID);
while (fgets(line, sizeof(line), file)) {
char currentCourseCode[10];
char currentStudentID[10];
sscanf(line, "%s %s", currentCourseCode, currentStudentID);
if (strcmp(currentCourseCode, courseCode) != 0 || strcmp(currentStudentID, studentID) != 0) {
fputs(line, tempFile);
}
}
fclose(file);
fclose(tempFile);
remove("grades.txt");
rename("temp.txt", "grades.txt");
printf("Grade deleted successfully.\n");
}
void displayGrades(FILE *file) {
char line[200];
printf("---------- Grade List ----------\n");
while (fgets(line, sizeof(line), file)) {
printf("%s", line);
}
printf("---------------------------------\n");
}
int main() {
FILE *studentsFile = fopen("students.txt", "a+");
FILE *paymentsFile = fopen("payments.txt", "a+");
FILE *coursesFile = fopen("courses.txt", "a+");
FILE *gradesFile = fopen("grades.txt", "a+");
int choice;
if (studentsFile == NULL || paymentsFile == NULL || coursesFile == NULL || gradesFile == NULL) {
printf("Error opening file.\n");
return 1;
}
while (1) {
printf("\n----- Student Management System -----\n");
printf("1. Add student\n");
printf("2. Delete student\n");
printf("3. Display all students\n");
printf("4. Add payment\n");
printf("5. Delete payment\n");
printf("6. Display all payments\n");
printf("7. Add course\n");
printf("8. Delete course\n");
printf("9. Display all courses\n");
printf("10. Add grade\n");
printf("11. Delete grade\n");
printf("12. Display all grades\n");
printf("0. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent(studentsFile);
break;
case 2:
deleteStudent(studentsFile);
break;
case 3:
displayStudents(studentsFile);
break;
case 4:
addPayment(paymentsFile);
break;
case 5:
deletePayment(paymentsFile);
break;
case 6:
displayPayments(paymentsFile);
break;
case 7:
addCourse(coursesFile);
break;
case 8:
deleteCourse(coursesFile);
break;
case 9:
displayCourses(coursesFile);
break;
case 10:
addGrade(gradesFile);
break;
case 11:
deleteGrade(gradesFile);
break;
case 12:
displayGrades(gradesFile);
break;
case 0:
fclose(studentsFile);
fclose(paymentsFile);
fclose(coursesFile);
fclose(gradesFile);
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}
```
请注意,此示例代码使用了文本文件来存储学生、缴费、课程和成绩信息。每个实体信息在文件中占据一行,以空格分隔。您可以根据需要进行修改和扩展,以适应实际的学生管理系统需求。
查询 存在考试 不及格 的 必修 课程信息,包括:课程代号、课程名称、课程类型、学时和学分。 注意: 1、父查询从t_course中查询,在WHERE中使用 IN 匹配不及格的 课程id; 2、子查询从t_score中查询满足条件的课程id
在数据库查询中,要获取存在考试不及格的必修课程信息,你需要编写一个包含两个关联表(假设t_course 表表示课程信息,t_score 表表示成绩记录)的SQL查询。这个查询通常会涉及联接操作和嵌套的 WHERE 条件。以下是一个可能的示例:
```sql
SELECT t_course.course_code, t_course.course_name, t_course.course_type, t_course.credit_hours, t_course.credit_points
FROM t_course
INNER JOIN (
SELECT course_id
FROM t_score
WHERE score < 60 -- 及格线设置为60分
) AS failed_courses ON t_course.course_id = failed_courses.course_id
WHERE t_course.is_required = 1 -- 确保是必修课程
```
在这个查询中:
1. 主查询(外部查询)从`t_course`表中选择必修课程的信息。
2. 子查询(内部查询)从`t_score`表中筛选出所有分数低于60分的课程id。
3. 使用`INNER JOIN`将主查询和子查询连接起来,只保留那些课程ID在子查询结果中的必修课程。
阅读全文