| Author |
Topic |
|
mjquinno
Starting Member
6 Posts |
Posted - 2004-06-25 : 12:45:16
|
| hi guys im in a world of doo doo i think ok her it is ...I have this sql statementSELECT courseInstance, score, userIdFROM userCoursesWHERE (SUBSTRING(courseInstance, 0, 11) IN (SELECT SUBSTRING(courseInstance, 0, 11) FROM userCourses WHERE courseid = 'PRE002' AND score < 80 AND status IN 'C', 'F'))) AND (courseId = 'PRE002')ORDER BY userIdThis returns PRE00275931 30 7593PRE00278471 77 7847PRE00279231 43 7923PRE00279232 43 7923PRE00279301 0 7930PRE00279302 87 7930PRE00279303 0 7930PRE00280141 7 8014PRE00280142 7 8014PRE00280143 7 8014PRE00280144 7 8014PRE00280145 7 8014PRE00280146 7 8014PRE00281471 60 8147PRE00281472 90 8147PRE00281521 43 8152the courseinstance is made up of the userid So this user took the course twice failed the first time and passed the second.PRE00281471 60 8147PRE00281472 90 8147Ok now i need to run through this returned list and return only 1 score for each user but it still needs to check that the score is under 80. any help much appriated..Thanks for looking |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-25 : 13:05:46
|
| Something like this might do it:select min(a.score) as score, a.useridfrom(SELECT courseInstance, score, userIdFROM userCoursesWHERE (SUBSTRING(courseInstance, 0, 11) IN(SELECT SUBSTRING(courseInstance, 0, 11)FROM userCoursesWHERE courseid = 'PRE002' AND score < 80 AND status IN 'C', 'F'))) AND (courseId = 'PRE002')ORDER BY userId) as agroup by a.useridhaving min(a.score) < 80Hopefully it works :)Duane. |
 |
|
|
mjquinno
Starting Member
6 Posts |
Posted - 2004-06-28 : 07:20:08
|
| Thanks very much mate that working a dream thing is i cant get it to return all the rows in the table that those values returned. Any ideas Thanks againD |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-28 : 07:28:28
|
| Send some example data and what is being returned and what should be returned, maybe then we can help.Duane. |
 |
|
|
mjquinno
Starting Member
6 Posts |
Posted - 2004-06-28 : 07:31:06
|
| (select max(a.score) as score, courseInstance from (SELECT * FROM userCourses WHERE (SUBSTRING(courseInstance, 0, 11) IN (SELECT SUBSTRING(courseInstance, 0, 11) FROM userCourses WHERE courseid = 'PRE002' AND score < 80 AND status IN ('C', 'F'))) AND (courseId = 'PRE002') ) as a group by courseinstance having max (a.score) < 80)returns PRE00275931 77PRE00278471 43PRE00279231 43PRE00279232 0PRE00279301 0PRE00279303 7PRE00280141 7PRE00280142 7PRE00280143 7PRE00280144 7PRE00280145 7PRE00280146 60PRE00281471 43PRE00281521 73PRE00281651 73PRE00281652 63PRE00281821 40PRE00281861 40PRE00281862 40PRE00281863 40PRE00281864 40PRE00281865 43PRE00281911 73PRE00281912 43PRE00282071 43PRE00282072 37PRE00282151 37PRE00282152 37PRE00282153 37PRE00282154 37PRE00282155 53PRE00282161 42PRE00282162 30PRE00282221 30PRE00282222 0PRE00282291 17PRE00282361 67PRE00282362 53PRE00282371 10PRE00282391 10PRE00282401 73PRE00282402 30PRE00282403 30PRE00282404 77PRE00282405 37PRE00282481 0PRE00282621 57PRE00282622 67PRE00282651 78PRE00282652 0PRE00282701 23exactly what i wanted but i need the entire row of data not just the courseinstance and score from the usercources table |
 |
|
|
mjquinno
Starting Member
6 Posts |
Posted - 2004-06-28 : 07:42:12
|
| my apologies the last post was from a while ago testing ..select max(a.score) as score, a.userId from (SELECT courseInstance, score, userId FROM userCourses WHERE (SUBSTRING(courseInstance, 0, 11) IN (SELECT SUBSTRING(courseInstance, 0, 11) FROM userCourses WHERE courseid = 'PRE002' AND score < 80 AND status IN ('C', 'F'))) AND (courseId = 'PRE002') ) as a group by a.userid having max (a.score) < 80 7593 777847 437923 78014 438152 738165 638182 408186 738191 438207 378215 538216 308222 08229 678236 538237 108239 778240 578262 788265 238270 108274 709191 33i want to get the entire row of data back from usercourse only for where they have the above scores. |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-28 : 07:47:26
|
| Does this do it?select c.*from UserCources cjoin(select max(a.score) as score, a.userId from (SELECT courseInstance, score, userId FROM userCourses WHERE (SUBSTRING(courseInstance, 0, 11) IN (SELECT SUBSTRING(courseInstance, 0, 11) FROM userCourses WHERE courseid = 'PRE002' AND score < 80 AND status IN ('C', 'F'))) AND (courseId = 'PRE002') ) as a group by a.userid having max (a.score) < 80) as b on b.courseinstance = c.courseinstance and b.score = c.score Duane. |
 |
|
|
mjquinno
Starting Member
6 Posts |
Posted - 2004-06-28 : 07:55:17
|
| Yes it returns the entire table but if the user has a few entries all failing im getting them all back i just want the highest below 80courseinstace course userid score PRE00295962 PRE002 9596 33PRE00295963 PRE002 9596 13PRE00295964 PRE002 9596 27i only want toget the line with the 33 score back the rest i dont need. Any ideas.Man thanks for the help i would be lost without you thanks again.D |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-06-28 : 08:03:30
|
| Sorry, I made a typo.Does this work?select c.*from UserCources cjoin(select max(a.score) as score, a.userId from (SELECT courseInstance, score, userId FROM userCourses WHERE (SUBSTRING(courseInstance, 0, 11) IN (SELECT SUBSTRING(courseInstance, 0, 11) FROM userCourses WHERE courseid = 'PRE002' AND score < 80 AND status IN ('C', 'F'))) AND (courseId = 'PRE002') ) as a group by a.userid having max (a.score) < 80) as b on b.userid = c.userid and b.score = c.score Duane. |
 |
|
|
mjquinno
Starting Member
6 Posts |
Posted - 2004-06-28 : 08:10:30
|
| hi duane ya thing is im still having the problem with the returning values i only want the one line for each userID. maybe a disinct cause if i have multiple instances with the same score it outputs them all. instance course userid score PRE00280141 PRE002 8014 7 PRE00280142 PRE002 8014 7 PRE00280143 PRE002 8014 7 PRE00280144 PRE002 8014 7Thanks againMike |
 |
|
|
|