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 |
|
jpost
Starting Member
43 Posts |
Posted - 2012-08-20 : 14:23:31
|
| I am trying to pull results for test scores where if the student failed a state mandated test, that I can create a column that list "still needs test Name" The first credential that I pull is if they scored less than or = to 399. If I get multiple results for the same test, then I need to have them marked as needing to take this test to graduate. Hope this makes sense? Any suggestions would be great.Thanks |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-20 : 15:10:53
|
| It only makes sense to me in a general sense - not specific enough to be able to write a query or even a psuedo query that would be useful to you. If you can post some sample data along with the table schema, and expected results, that would help someone on the forum to offer more useful suggestions.Brett's blog here might be useful: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-20 : 16:56:02
|
quote: Originally posted by jpost I am trying to pull results for test scores where if the student failed a state mandated test, that I can create a column that list "still needs test Name" The first credential that I pull is if they scored less than or = to 399. If I get multiple results for the same test, then I need to have them marked as needing to take this test to graduate. Hope this makes sense? Any suggestions would be great.Thanks
is 399 accumulated total for all tests or is it mark per test?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jpost
Starting Member
43 Posts |
Posted - 2012-08-21 : 08:22:53
|
| 399 is just a mark per testHere is some of the code I am using, I thought if I could have the sum of the last column to be less the 1, then they would have to retake the test. select distinct s.studentNumber,s.firstName,s.lastName,ts.date, t.name, ts.scaleScore,casewhen ts.scaleScore <= 399 then 0else 1end as 'Pass/Fail'from TestScore tsInner join Test t on ts.testID = t.testIDInner join Student s on ts.personID = s.personIDwhere ts.scaleScore is not null and s.studentNumber ='314207'order by t.nameResultsStudentNum Last First Date Test Score pass/fail314207 Genevieve Boateng 2012-03-01 00:00:00 OGT MATHEMATICS 391.000 0314207 Genevieve Boateng 2012-07-01 00:00:00 OGT MATHEMATICS 389.000 0314207 Genevieve Boateng 2012-03-01 00:00:00 OGT READING 383.000 0314207 Genevieve Boateng 2012-07-01 00:00:00 OGT READING 415.000 1314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SCIENCE 389.000 0314207 Genevieve Boateng 2012-07-01 00:00:00 OGT SCIENCE 386.000 0314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SOCIAL STUDIES 403.000 1314207 Genevieve Boateng 2012-03-01 00:00:00 OGT WRITING 413.000 1 |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-21 : 08:33:56
|
What is the desired output? I can see that this student needs to retake MATHEMATICS and SCIENCE. Is that what you are trying to get?SELECT s.studentNumber, s.firstName, s.lastname, t.name, MAX(ts.scaleScore), CASE WHEN MAX(ts.scaleScore) <= 399 THEN 'RETAKE' ELSE 'PASS' END AS [Pass/Fail]FROM TestScore ts INNER JOIN Test t ON ts.testID = t.testID INNER JOIN Student s ON ts.personID = s.personIDWHERE ts.scaleScore IS NOT NULL AND s.studentNumber = '314207'GROUP BY s.studentNumber, s.firstName, s.lastname, t.name,--HAVING-- MAX(ts.scaleScore) <= 399; If you want only failed courses, uncomment the last two lines.This assumes that they wouldn't retake a course the passed in and end up failing when they do. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-21 : 10:07:26
|
quote: Originally posted by jpost 399 is just a mark per testHere is some of the code I am using, I thought if I could have the sum of the last column to be less the 1, then they would have to retake the test. select distinct s.studentNumber,s.firstName,s.lastName,ts.date, t.name, ts.scaleScore,casewhen ts.scaleScore <= 399 then 0else 1end as 'Pass/Fail'from TestScore tsInner join Test t on ts.testID = t.testIDInner join Student s on ts.personID = s.personIDwhere ts.scaleScore is not null and s.studentNumber ='314207'order by t.nameResultsStudentNum Last First Date Test Score pass/fail314207 Genevieve Boateng 2012-03-01 00:00:00 OGT MATHEMATICS 391.000 0314207 Genevieve Boateng 2012-07-01 00:00:00 OGT MATHEMATICS 389.000 0314207 Genevieve Boateng 2012-03-01 00:00:00 OGT READING 383.000 0314207 Genevieve Boateng 2012-07-01 00:00:00 OGT READING 415.000 1314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SCIENCE 389.000 0314207 Genevieve Boateng 2012-07-01 00:00:00 OGT SCIENCE 386.000 0314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SOCIAL STUDIES 403.000 1314207 Genevieve Boateng 2012-03-01 00:00:00 OGT WRITING 413.000 1
in that case if student has already done multiple attempts would you take average score or last obtained score for comparison?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jpost
Starting Member
43 Posts |
Posted - 2012-08-21 : 12:48:12
|
| sunitabeck, I thought that what you provided would be adequate for the people requesting the report, however, they want to be able to pull info for test per student that would still need to be taken. So they would get a student number name, and a list of tests still needed.visakh16- I thought about the sum as a possibility for needing a retake. But with a wide range of possible results, not sure how this would work. Example, lets say student received a 300 on Math the first time and a 410 the second time. The sum would be 710, but I could have a student that had 350 and 360 and still get the same sum, so I am not sure what I would need to do |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-08-21 : 12:54:48
|
quote: Originally posted by jpost sunitabeck, I thought that what you provided would be adequate for the people requesting the report, however, they want to be able to pull info for test per student that would still need to be taken. So they would get a student number name, and a list of tests still needed.visakh16- I thought about the sum as a possibility for needing a retake. But with a wide range of possible results, not sure how this would work. Example, lets say student received a 300 on Math the first time and a 410 the second time. The sum would be 710, but I could have a student that had 350 and 360 and still get the same sum, so I am not sure what I would need to do
ideally i would assume latter to be pass condition, but anyways you should be confirming it.so that being case you can do likeSELECT *TestScore ts INNER JOIN Test t ON ts.testID = t.testID INNER JOIN Student s ON ts.personID = s.personIDWHERE ts.scalescore < =399AND NOT EXISTS (SELECT 1 FROM Testscore WHERE testID = ts.testID AND personID = ts.personID AND Date > ts.Date AND scalescore > 399 ) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|