sql - How to show the names of non-participants in the all last sending quizzes in each division? -
i developing training management web-based system provides user short quizzes refresh knowledge. anyway, have following database design:
employee table: username, name, divisioncode divisions table: sapcode, divisionshortcut quiz table: quizid, title, issent question table: questionid, question, quizid... userquiz table: userquizid, quizid, username, score. i able come query shows names of non-participants in divisions in last quiz. want show non-participants names in quizzes have been sent users participate in them. results should listed grouping quiz title , divisionshortcut. so how that?
my query:
select d.divisionshortcut, e.name employee e join divisions d on (e.divisioncode = d.sapcode) left join (select a.quizid, a.username userquiz join (select max(quizid) quizid dbo.quiz issent=1) b on a.quizid = b.quizid ) c on e.username = c.username c.quizid null order d.divisionshortcut
you can use cross join combinations of employee , quiz, use not exists eliminate combinations have been completed:
select * employee e inner join divisions d on e.divisioncode = d.sapcode cross join quiz quiz.issent = 1 , not exists ( select 1 userquiz uq uq.quizid = quiz.quizid , uq.username = e.username )
Comments
Post a Comment