Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ewade
Starting Member
36 Posts |
Posted - 2002-10-11 : 14:26:02
|
| I'm facing an interesting challenge at work- the school I consult for has adopted a model for personalizing a student's graduation goals.The Scenario: Some students are assigned to one of 12 individualized graduation plans (IGP). Each IGP has certain course requirments. The administration needed a way to track a student's progress towards completion of their IGP. A query is needed that will supply values to a report template.Here are the tables, which have been simplified for the purposes of the challenge:DEPARTMENTS # id * nameCOURSES # number * title * department (fk: DEPARTMENTS.id)GRADPLANS # id o descriptionPLAN_REQUIRMENTS # number * plan (fk: GRADPLANS.id) * course (fk: COURSES.number) * credits_neededSTUDENTS # id * last_name * first_name * mi * telephone * plan (fk: GRADPLANS.id)TEACHERS # id * nameGRADES # code o descriptionTRANSCRIPTS # id * student (fk: STUDENTS.id) * course (fk: COURSES.number) * grade (fk: GRADES.code) * credits_earned * date_completedTHE CHALLENGE: Write a query that will be used to report a student's progress toward their assigned IGP. The query should include basic student demographic information from STUDENTS, all of the plan requirements for the selected student, the courses the student has passed (TRANSCRIPTS.grade cannot equal "F", "W", or "I"), and report the number of credits needed for each of the plan requirments (in other words, subtract credits earned for a particular course from the course requirement). A student may take a single course more than one time, and earn a different grade and number of credits each time. Courses need to be grouped by department.Can I do this in a single query, and if so, will performance be severely affected?Never stop learning! |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-10-11 : 14:46:22
|
| Just out of curiosity, how far have you gotten with this query? Can you give an example of what the output should look like?I can say pretty confidently that it can be done in a single SELECT statement, but it depends on the exact ouput desired. LEFT JOINs and some CASE statements will allow it to list all of the requirements and adjust the credits attained depending on the grade. Grouping by department simply requires the correct ORDER BY clause; if you need department summaries you can use ROLLUP to generate them.I'd like to see more because, frankly, and no offense intended, the way this is worded sounds like you're giving us an assignment to do FOR you. Since none of us are being paid to help I'd prefer to think you're asking for advice and assistance after making some effort to solve it yourself. |
 |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2002-10-11 : 17:11:55
|
| I agree with Rob give it a try and tell us how the performance is and where the problems are.Are you trying to do a real time system? |
 |
|
|
ewade
Starting Member
36 Posts |
Posted - 2002-11-21 : 11:53:25
|
| Sorry for the long delay in replying... No, I wasn't looking for a solution, I was asking a question about performance. And yes, my goal is for a real-time system. I've just managed to close out a year-long SQL project, so I'll be playing with this problem in the coming weeks. Thanks for the information!Never stop learning! |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-11-21 : 12:49:57
|
| You need to create your main query which is the "driving" record, and everything else will be an outer join off of that.So, for the Driving Record:Start with the Students table CROSS JOINED with all courses. (That's right, no relationship).Join courses to the descriptions and info.Join courses to the department to get the dept name.Do NOT filter the above query at all. Just do all of the joins. Include as many fields from the tables as possible in the result set. Call the above subquery "AllStudentsAlLCourses".From the that subquery, do left outer joins to:Transcripts (joined to grades if you like)Plan_Requirements (joined by Student and plan#)Again, include all key fields you need. The final result set will have lots of NULL records. Filter to only show records where there is a match in either the transcripts or the plan requirements. Encapsulate the entire thing in a subquery again, call it "Everything".Then, you are done. Remember to compare a group by value of credits_needed with SUM(ISNULL(CreditsEarned,0)) for each student.I just gave the alogorithm, it may not make sense and seem tricky, but try it out.- Jeff |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-11-21 : 13:16:15
|
In case it makes no sense what I proposed, above:WE need to consider EVERY student and EVERY course (the cross join).From there, we want to see only courses the student took (LEFT OUTER JOIN to transcripts) and/or courses that are required by the student's plan (LEFT OUTER JOIN TO Plan_Requirments, based on that student's plan).Show only records in which the student took the course or it is included in the students plan.The above will show repeated courses multiple times as well.May have sounded complex but it is quite straightforward !How you use the results of this query in your report design is the key to presenting this info well. For example, you might have something like:Student <student header info> <graduation plan for the student> Department <dept header info> Course <course info> <indicate if it is required by grad plan> (Detail) Grades and credits earned in the course Deparment subtotals (i.e., required vs taken)Student subtotals<page break before next student> - JeffEdited by - jsmith8858 on 11/21/2002 13:40:43 |
 |
|
|
ewade
Starting Member
36 Posts |
Posted - 2003-02-12 : 13:36:45
|
Hmnn... well I have made some progress, but I must confess that I still can't seem to solve the basic problem of courses appearing twice in the final view. I tried to follow jsmith8858's suggestions, here's what I was able to achieve:I created a view called AllStudentsAllCourses:SELECT student.stu_num, student.last_name, student.first_name, student.middle_initial, student.date_of_birth, student.ged_wri, student.ged_rdg, student.ged_math, student.ged_ss, student.ged_sci, student.exit_math, student.exit_rdg, student.exit_wri, student.gradplan, student.concurrent_site, student.evetel, student.daytel, course.title, department.deptnameFROM department INNER JOIN course ON department.deptname = dbo.course.deptnameCROSS JOIN student Sidebar- I suppose that if I'd been more dilligent with the initial design I would not have used an information-bearing primary key for DEPARTMENTS (pk: deptname). Since I did, I realize it's kind of pointless to join COURSE to DEPARTMENT, since COURSE.deptname can be used to group output. However, I've left it in this example in case I'm missing something from the explanation.I then went on to create another view (and yes, I realize that I misspelled requirement when I created the table, but now I'm stuck with it):SELECT AllStudentsAllCourses.*, transcript.grade, transcript.credits_earned, transcript.completion_date, transcript.title AS CourseTaken, plan_requirment.title AS RequiredCourse, plan_requirment.credits_reqFROM AllStudentsAllCourses LEFT JOIN plan_requirment ON AllStudentsAllCourses.gradplan = plan_requirment.gradplan LEFT JOIN transcript ON AllStudentsAllCourses.stu_num = transcript.stu_num AND dbo.transcript.verified IS NOT NULL Did I interpret this correctly?P.S.- thanks again to everyone who responded. I wanted to point out that "school I consult for" may have given the mistaken impression that I'm paid for doing this work for them. I'm not, it's strictly volunteer.Never stop learning! |
 |
|
|
|
|
|
|
|