SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Compiling results??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jpost
Starting Member

43 Posts

Posted - 08/20/2012 :  14:23:31  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 08/20/2012 :  15:10:53  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48076 Posts

Posted - 08/20/2012 :  16:56:02  Show Profile  Reply with Quote
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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

jpost
Starting Member

43 Posts

Posted - 08/21/2012 :  08:22:53  Show Profile  Reply with Quote
399 is just a mark per test
Here 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,
case
when ts.scaleScore <= 399 then 0
else 1
end as 'Pass/Fail'
from TestScore ts
Inner join Test t on ts.testID = t.testID
Inner join Student s on ts.personID = s.personID
where ts.scaleScore is not null and s.studentNumber ='314207'
order by t.name

Results
StudentNum Last First Date Test Score pass/fail

314207 Genevieve Boateng 2012-03-01 00:00:00 OGT MATHEMATICS 391.000 0
314207 Genevieve Boateng 2012-07-01 00:00:00 OGT MATHEMATICS 389.000 0
314207 Genevieve Boateng 2012-03-01 00:00:00 OGT READING 383.000 0
314207 Genevieve Boateng 2012-07-01 00:00:00 OGT READING 415.000 1
314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SCIENCE 389.000 0
314207 Genevieve Boateng 2012-07-01 00:00:00 OGT SCIENCE 386.000 0
314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SOCIAL STUDIES 403.000 1
314207 Genevieve Boateng 2012-03-01 00:00:00 OGT WRITING 413.000 1


Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 08/21/2012 :  08:33:56  Show Profile  Reply with Quote
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.personID
WHERE
	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.

Edited by - sunitabeck on 08/21/2012 08:34:43
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48076 Posts

Posted - 08/21/2012 :  10:07:26  Show Profile  Reply with Quote
quote:
Originally posted by jpost

399 is just a mark per test
Here 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,
case
when ts.scaleScore <= 399 then 0
else 1
end as 'Pass/Fail'
from TestScore ts
Inner join Test t on ts.testID = t.testID
Inner join Student s on ts.personID = s.personID
where ts.scaleScore is not null and s.studentNumber ='314207'
order by t.name

Results
StudentNum Last First Date Test Score pass/fail

314207 Genevieve Boateng 2012-03-01 00:00:00 OGT MATHEMATICS 391.000 0
314207 Genevieve Boateng 2012-07-01 00:00:00 OGT MATHEMATICS 389.000 0
314207 Genevieve Boateng 2012-03-01 00:00:00 OGT READING 383.000 0
314207 Genevieve Boateng 2012-07-01 00:00:00 OGT READING 415.000 1
314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SCIENCE 389.000 0
314207 Genevieve Boateng 2012-07-01 00:00:00 OGT SCIENCE 386.000 0
314207 Genevieve Boateng 2012-03-01 00:00:00 OGT SOCIAL STUDIES 403.000 1
314207 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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

jpost
Starting Member

43 Posts

Posted - 08/21/2012 :  12:48:12  Show Profile  Reply with Quote
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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48076 Posts

Posted - 08/21/2012 :  12:54:48  Show Profile  Reply with Quote
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 like

SELECT *
TestScore ts
	INNER JOIN Test t
		ON  ts.testID = t.testID
	INNER JOIN Student s
		ON  ts.personID = s.personID
WHERE ts.scalescore < =399
AND NOT EXISTS (SELECT 1
                FROM Testscore
                WHERE testID = ts.testID
                AND personID = ts.personID
                AND Date > ts.Date
                AND scalescore > 399
                )


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000