Is there a query for this? - mysql

Im making a system for a school and I have this mySQL tables. The names are self explanatory:
student: id name course_id
course: id name
subject: id name
subject_course: id subject_id course_id
grade: id type grade
grade_type: id name
I need to check if every student of a certain course has a grade of type X on every subject that is related with that course.
Let's say grade_type = 'written test'. So I need to check if every student of 1st grade has a grade on the written test on EVERY subject related to first grade (example: math, spanish, history, etc). If yes, I do some stuff. If not, another.
Is there a query that can check that? I was thinking on check student by student but I think is less efficient.

This schema doesn't seem to make sense.
Why would course_id be field on student table? My guess is you need a student_course table to represent a many-to-many relationship between students and courses here.
Also, the grade_type table seems kind of trivial and extra overhead with little value. Could type not just be an enum on grade table?

Related

How to model "participation in container and child"

Considering this ER diagram
we have Students who are admitted to participate in an Exam, and each Exam can be split up into multiple Runs (for example, to split up large groups across multiple rooms or to have two Runs for the same Exam in direct succession).
Is it possible to ensure (via database constraints) that Students participate only in Runs that belong to Exams they are admitted to?
I couldn't find a way on my own and also don't know how to phrase this for an internet search.
You have these tables and columns:
exam: id, name
student: id, name
run: id, exam_id (foreign key to exam.id), when (timestamp), room
You need a new intersection table to keep track of what exam is being taken by which student:
int_exam_to_student: exam_id, student_id - both foreign keys
Now, you can query this to determine what runs a student is allowed to be in:
select run.* from run join int_exam_to_student i on (run.exam_id = i.exam_id) where i.student_id = 123;

Best technique to implement skill matrix

Recently I was asked to design a portal where students can upload their technical skills like: HTML, PHP, C++ etc. and college can search the students based on the mandatory and optional skills.
Initially I thought of storing the student and their related skills details using a two columned table where first column represents the student and second column consists of all the skills related to that student separated by comma. For example,
001 HTML,C,C++,JAVA
002 C,JAVA
003 HTML,.NET
...
...
But now I'm facing problems in querying and searching for the student who have relevant skills. I tried a lot but end up with no clue on how this can be achieve.
Any pointers on storing techniques and searching algorithms etc. would be helpful. Help is much appreciated.
Thanks
A simple way to handle this is to have three tables. The first table contains students and includes a unique ID for each student. The second table contains skills and has a unique ID for each skill. The third table is for cross-referencing the first two and has two columns: "Student ID" and "Skill ID".
E.G. Let's say the skill table has an entry for "C" with ID 1, and for "C++" with an ID of 2. We have a student with an ID of 1 who knows both C and C++. We put two entries in cross-reference, the first entry has a student ID of 1 and a skill ID of 1, the second entry has a student ID of 1 and a skill ID of 2.
When you need to find out what skills a student has you just find all the rows in the cross reference table for that student ID. Conversely, if you want to find out what students have a certain skill you just find all the rows with that skill ID.

What could be the right SQL query for this? I am using MS Access dbms

I have three tables names are Courses, EnrolledCourses and Student.
Courses table has fields namely coursenumber, coursedescription, courseunits, courseprerequisite, yearlevel (yearlevels of students who are supposed to take the course), and semester (semester in which a course is to be offered).
Students table has fields namely studID, studName, studStatus (or the year level), and studCourse.
EnrolledCourses table on the other hand has fields namely studID, courseNumber, remarks, and yearEnrolled.
QUESTION:
Suppose one of the courses or subjects taken by a student in the first semester is English101 but the student wasn't able to pass it. For this matter, English102 is to be offered for the second semester and English101 is its prerequisite course. What if i want to view all the courses for the second semester that this particular student should enroll EXCEPT the course for the second semester having a prerequisite courses that this student didn't pass. The remarks attribute from the EnrolledCourses table contains values as to whether course/prerequisite course is "Passed" or the otherwise.
I seriously need an answer to this question. If you really wanna help on this, email me at markydspark#gmail.com. THANKS!

Database: Tables design/structure

I am new to database structure and design. Currently, I am in the process of creating a course catalog that will match course description according to course name and date. I have sketched one table describing the courses, which include course_code, name and every other relevant information. Then I sketched another table linking those courses to when they will be taught.
I am missing classes that are classified as all_year. Also I am missing a way how to label the courses under a major. Since hypothetically a course can belong to several majors, putting the data from one into the other would force you to duplicate data. Any ideas how I would implement this two things to my tables design? Or suggestion in how to restructure my design. If possible please show me a query to execute in my phpmyadmin DB.
Example of table courses
id serial
course_code text
description text
Example of table course_dates
id serial
course_id serial
year date
semester
Example of table majors
major_id int
course_id int
So a populated database could contain the following:
Table courses
id course_code description
1 INF1000 "Basic programming"
2 INF1001 "More basic programming"
Table course_dates (0 for spring 1 for fall)
id course_id year semester
1 1 2012 0
2 1 2013 1
3 2 2013 1
To link courses to majors - this is a one to many relationship (one course to many majors) - you want to use a linking table that has this type of structure:
table courses_majors
major_id int
course_id int
Remember to index this table as well - its very important. Then you can populate it and have one course even go to many majors and many course to one major (many to many relationship).
Then you can run a join on the tables across this table:
select * from courses left join courses_majors on courses.id = courses_majors.course_id left join majors on courses_majors.majors_id = majors.id
Of course you can add a where clause, etc.
The other way is to create a table of majors:
majors
id int
name varchar
Then add a major_id to your courses table - this will just give you a one to one relationship from courses to majors, but many courses can join a major.
As for Yearly, I would just add a field in the database to account for this, probably a tiny int and just make it 0 or 1.

Dealing with a curriculum database

Okay, I have 3 tables:
Students
Offered_subjects
Enrollees_list
Students will contain all the information of the students of the school
Offered_subjects will contain all the subjects offered by the school
Enrollees_list will contain all information about what subject a students is enrolled in and will also contain remarks for that subject (pass or fail).
Now, the subjects in offered_subjects contain courses that have prerequisites (ie. before qualifying for MySQL101, the student mas have a passing remark in DBMS101)
The categories of prerequisites are:
Academic Year
Semester
Subject
Note that not all the subjects listed in offered_subjects have all the categories for its prerequisite. Some require to finish a certain subject, some require that the student must be in a certain academic year (ie, 3rd year), and some have all three.
What's required for the program is to display all the students that are qualified for a selected subject.
Let's say: MySQL101 has prerequisite of 2nd year, 2nd sem, DBMS101
I need to list all the students that are on their 2nd year, 2nd sem, and have a passing remark in DBMS101.
This would be easy if all the subjects have same categories for its prerequisites where I can put the same queries in the where clause, but my problem is that, again, not all the subjects listed in offered_subjects have all the categories for its prerequisite.
I'm new to MySQL and it's kind of confusing to me at the moment.
How do I do it?
I'm guessing you have the following columns on the Offered_subjects table:
Req_year
Req_semester
Req_subject
If one of your subjects don't have values on this column, you can ignore this check for this column. Something like:
Select ... where (Subject.req_year is null OR Student.year >= Subject.req_year) ...
This way, required year will not be taken into account if it's null.
(note: I'm not completely sure of syntax right now, but that's the idea).