exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 158 discussion

Actual exam question from Microsoft's 70-761
Question #: 158
Topic #: 1
[All 70-761 Questions]

HOTSPOT -
You are developing a training management application. You run the following Transact-SQL statement:

You must create a report that returns course identifiers and the average evaluation score for each course. The result set must include only one score for each employee for each course.
How should you complete the Transact-SQL statement? To answer, select the appropriate Transact-SQL segments in the answer area.
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
M4x
Highly Voted 5 years, 9 months ago
The first box should be DISTINCT CourseId, EmployeeId, EvalScore
upvoted 14 times
anonimdom
5 years, 4 months ago
But, if there are duplicates like (1,1,1),(1,1,1) the avg value will be 1 anyway. So it looks like the result with and without distinct will be the same because we calculate avg (not sum) values.
upvoted 3 times
ovsg2
5 years, 4 months ago
no, since AVG(1, 1, 1, 2) =/= AVG(1, 2)
upvoted 5 times
Anette
5 years ago
yes, but it means without distinct
upvoted 2 times
...
...
...
...
Bert_Bisschop
Highly Voted 5 years, 7 months ago
I think to meet the condition: "The result set must include only one score for each employee for each course", EmployeeId must also be included in the group by clause. Now you only get one score for each course.
upvoted 6 times
Jiacheng
5 years, 4 months ago
I agree, otherwise we will only get courseID and AvgCourseScore, which score is for all employe
upvoted 2 times
...
Anette
5 years ago
Totally agree
upvoted 1 times
...
AlaskanBumblebee
4 years, 11 months ago
I just came across that as well. Even before looking at the CTE, I saw that we were only grouping by courseid so there had to be a flaw in the question. As it stands, an aggregate function perform is based on all individuals who have taken the course
upvoted 1 times
...
BabyBee
4 years, 7 months ago
What the question asks to return in your report is only: "You must create a report that returns course identifiers and the average evaluation score for each course." Nowhere it is asking to return avg evaluation score by course id and by employee. And you need to previously select 1 score for 1 course for 1 employee.
upvoted 2 times
...
...
Billybob0604
Most Recent 4 years, 5 months ago
drop table evaluations create table evaluations ( evaluationID int not null, employeeID int null, courseID int null, evalScore int null ) insert into evaluations values (1, 123, 222, 18), (2, 124, 222, 12), (3, 125, 223, 20), (4, 126, 224, 21), (5, 126, 223, 35) select * from evaluations select courseid, employeeid, evalscore from evaluations ; with evals_CTE (courseID, employeeid, evalscore) as (select courseid, employeeid, evalscore from evaluations) select courseID, avg(distinct(evalscore)) from evals_cte group by courseid
upvoted 1 times
...
Vermonster
4 years, 5 months ago
No correct answer. Even with DISTINCT(CourseID, EmployeeID, EvalScore) you would get multiple rows for the course/employee if the eval scores were different.
upvoted 1 times
...
TatyanaY
4 years, 8 months ago
To include one score for each employee for each course the DISTINCT clause is not enough; this would need a ranking function.
upvoted 1 times
...
TheDUdeu
4 years, 9 months ago
This portion is correct: SELECTCourseID, EmployeeID, EvalScore FROM Evaluations will bring in all the Course and their EvalScore. When you group by CourseID and get the AVG(EvalScore) you will get average score by course but not by employee so you need to group by employeeID and CourseID and also add EmployeeID to the select in order for the result set to be correct. If you want to see the employeeID per course you should show it.
upvoted 1 times
...
stm22
4 years, 11 months ago
this req: "The result set must include only one score for each employee for each course." seems like it would need a distinct courseid, empid, evalscore
upvoted 1 times
...
99_es
5 years ago
so which is the correct answer for the first box?
upvoted 1 times
...
Anette
5 years ago
how about select courseid, avg(distinct evalscore) in second box?
upvoted 1 times
Anette
5 years ago
Sorry, not. Box 2 is just courseid, avg(evalscore). While first course is without distinct. The answer of this question is right. Try to test with the same evalscore for the same courseid fro different employeeid. The right result is not with Distinct in first box but WITHOUT distinct.
upvoted 2 times
Anette
5 years ago
I regret, first box is distinct and second just avg. The problem here is with groub by employeeid, which must be included
upvoted 1 times
...
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...