MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old October 7th, 2003, 08:02 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok- heres 2 from each tbl

scores:
usrid,crsid,comp_id,score,date
usr1,crs1,quiz1,100,1/1/01
usr1,crs1,quiz2,100,1/1/01
usr1,crs1,quiz3,100,1/1/01
usr2,crs1,quiz1,100,1/1/01

score elements:
crs_id,comp_id,comp_lbl
crs1,quiz1,"quiz1"
crs1,quiz2,"quiz2"
crs1,quiz3,"quiz3"

how can i make a qry to check if usr's in scores have completed each component per course, which is defined in scoreelements?

ideal return:
usrid,crsid,complete,avg_score
usr1,crs1,y,100
usr2,crs1,n,100

Reply With Quote
  #17  
Old October 7th, 2003, 08:04 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ps- if the y/n isnt possible- i would like only usr1

i can build a table for the other usr's & append to above record set with 'n' for complete

Reply With Quote
  #18  
Old October 7th, 2003, 09:15 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,956 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 58 m 54 sec
Reputation Power: 1024
okay, create this query and save it as crs_components:

SELECT crs_id, count(*) AS components
FROM tblElements
GROUP BY crs_id;

now create this query and save it as usr_crs_scores:

SELECT usr_id, crs_id
, count(*) AS scores
, avg(score) as avgscore
FROM tblScores
GROUP BY usr_id, crs_id;

now run this query for your report:

select S.usr_id, S.crs_id
, iif(S.scores=C.components,'y','n') as complete
, S.avgscore
from usr_crs_scores S
left outer
join crs_components C
on S.crs_id = C.crs_id

rudy

Reply With Quote
  #19  
Old October 8th, 2003, 08:26 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok- but the issue is 'count(*) ' wont work since you can have multiple records for each component id per course-

ie you can take the quiz in crs 1 unlimited times- so the count would be greater or equal to; i need to check that values in scores.comp_id are equal to score_elements.comp_id for each comp_id per course

further- crs Y has 3 comp id's. if usrY has 3 records in scores for course for quiz1- he will meet the count(*) logic, but its not a desired return. this is the root of my problem

thanks,
duncan

ps- thanks for the IIF; think i get how to use those now

Reply With Quote
  #20  
Old October 8th, 2003, 11:07 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,956 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 58 m 54 sec
Reputation Power: 1024
i see you are beginning to answer your own questions

you need a new query

select usr_id, count(*) as courses
from usr_crs_scores
group by usr_id

this tells how many different courses a user has tried

now join this to crs_components to see if the user has tried all the components of a course

this time the counts should be comparable

Reply With Quote
  #21  
Old October 8th, 2003, 11:33 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok- the cogs are beginning to turn- i guess the join does the check for each component per crs id

thanks again,
duncan

Reply With Quote
  #22  
Old October 10th, 2003, 09:09 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
im spinning in circles here- im still unsure why its a count(*) since i want to compare values in the column

heres my end query- but it doesnt look right

SELECT usr_crs_scores.USERLOGONID, Count(*) AS courses, usr_crs_scores.scores, usr_crs_scores.avgscore, usr_crs_scores.LastOfDATE_TIME
FROM crs_components LEFT JOIN usr_crs_scores ON crs_components.COURSENUMBER = usr_crs_scores.COURSENUMBER
GROUP BY usr_crs_scores.USERLOGONID, usr_crs_scores.scores, usr_crs_scores.avgscore, usr_crs_scores.LastOfDATE_TIME;

Reply With Quote
  #23  
Old October 10th, 2003, 09:53 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok- lets start from step 1 again(sorry but im confused)

i have this query to get crs/comp_id relationship:
SELECT scoreElements.COURSENUMBER, scoreElements.COMPONENTID
FROM scoreElements
GROUP BY scoreElements.COURSENUMBER, scoreElements.COMPONENTID, scoreElements.COURSETYPE
HAVING (((scoreElements.COMPONENTID)<>"00000000") AND ((scoreElements.COURSETYPE)=13));

output:
COURSENUMBER COMPONENTID
13205 031
13205 032
13205 033
13205 034
13205 141
13205 231
13205 331
13205 431

the above is all of the id's for crs 13205 within scoreelements (theres 146 crs's). now i have to join this to a scores query with a where & an and statement(thats what i think)

this query returns about 300 records more than what i think i should get(1792 vs 1413 w/another tool) also, i get a blank row with a count(*) of 511- which is wierd

help?
duncan
SELECT Scores.USERLOGONID, Scores.COURSENUMBER, Avg(Scores.SCORE) AS AvgOfSCORE, Last(Scores.DATE_TIME) AS LastOfDATE_TIME, Count(*) AS Expr1
FROM qryComp_IDS LEFT JOIN Scores ON (qryComp_IDS.COMPONENTID = Scores.COMPONENTID) AND (qryComp_IDS.COURSENUMBER = Scores.COURSENUMBER)
GROUP BY Scores.USERLOGONID, Scores.COURSENUMBER;

Reply With Quote
  #24  
Old October 10th, 2003, 10:00 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
y- that query is bad-

i have a usr with 1 record for a crs/comp where teh crs has 6 comp defined. i think htis is a join prob

Reply With Quote
  #25  
Old October 10th, 2003, 10:05 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
i switched to a right join * i get the field is too small or insert less data err

Reply With Quote
  #26  
Old October 10th, 2003, 11:03 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,956 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 58 m 54 sec
Reputation Power: 1024
i'm having a hard time following what you're doing

start with the two queries that compute a count

that way, you can join the queries rather than trying to do complex joins with GROUP BY and HAVING

Reply With Quote
  #27  
Old October 10th, 2003, 11:06 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
y- this is getting a bit complex- i am trying to avoid counts because a user can have multiple records for each component, but let me try a distinctrow qry-

Reply With Quote
  #28  
Old October 10th, 2003, 11:11 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,956 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 58 m 54 sec
Reputation Power: 1024
when you save the queries that contain counts, they will act like a VIEW in any other database

Reply With Quote
  #29  
Old October 10th, 2003, 11:32 AM
dcb dcb is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 29 dcb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
heres where my inexperience comes in, but cant i have a statement like:
where scoreelements.componentid = scores.componentid for scoreelements.coursenumber EXISTS in scores?

or something to this effect?

Reply With Quote
  #30  
Old October 10th, 2003, 12:44 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,956 r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level)r937 User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 58 m 54 sec
Reputation Power: 1024
the "something to this effect" is a join, possibly a left outer join

do the two count queries, and then take stock of where you are

when you select all the rows from the count queries, they will act just like tables

then join those together!