Jump to content

Trouble Combining Two Tables with Comparisons


kts

Recommended Posts

Hi,

 

In simple, I have two tables.

Table One: CreditDetails

holds a students information, including mark, department, etc)

 

Second table: OnTrackReq

holds the requirements the student must meet. (ontrack, grade, type, taken will be filled to 1 if its required 0 if not)

 

So ultimately, I am looping through each student and comparing their mark (based on department and grade) to the ontrackreq tables which also has grade, ontrack(the number they need to meet) and o.taken i would consider to be passed.

 

o.taken works in the sense of it there is a 1 it is passed.

 

What I forsee the problem is, it will only work if I have the department, grade and type in my where outside the case. Where I need each row to just show me taken if the Department = 'English' and Grade = '11' in OnTrackReq has a 1.

 

Hopefully I explained this properly.. I am just trying to make sure this is possible.

 

SELECT c.StudentID StudentID,c.LastName, c.FirstName, c.Grade Grade, c.Title, c.Department, c.Mark,
(case when c.Grade = o.Grade AND c.Mark > o.Ontrack AND c.Department = o.Department AND c.Type = o.Type then o.taken end) as Passed

FROM CreditDetails c JOIN OnTrackReq o ON (c.Grade = o.Grade AND c.Type = o.Type) WHERE c.Type = 'Regents' AND c.Grade = '12' GROUP BY c.StudentID, c.Department, c.Type ORDER BY c.LastName ASC  

 

Thanks,

K

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.