exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 156 discussion

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

HOTSPOT -
You need to develop a function that returns a list of courses grouped by the total number of students in a course.
The function must list only courses that have more than a specific number of students. The specific number of students is defined as an input variable for the function.
How should you complete the function? 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
Dieter
Highly Voted 5 years, 10 months ago
Update: in addition, answer of Box 3 must be HAVING, since where does not allow aggregate functions
upvoted 27 times
...
Anette
Highly Voted 5 years ago
it is: 1. Table 2. SUM(cp.NumStudents) AS NumStudents 3. Having
upvoted 21 times
...
Billybob0604
Most Recent 4 years, 5 months ago
you can only do this using group by and having. An alias after the sum is even permitted. select A.EMPLOYEENUMBER, sum(B.AMOUNT) AS TOTALSUM from TBLEMPLOYEES INNER JOIN TBLTRANSACTIES B ON A.EMPLOYEENUMBER = B.EMPLOYEENUMBER GROUP BY A.EMPLOYEENUMBER HAVING SUM(B.AMOUNT) > 0
upvoted 1 times
...
Vermonster
4 years, 5 months ago
Need alias and then move on
upvoted 1 times
...
SimSql
4 years, 6 months ago
2) The result set must include only one score for each employee for each course. If you want to solve this part of the question: ;with Evals_CTE (courseId, EmployeeId, EvalScore) AS ( select CourseID, EmployeeID, EvalScore from Evaluations ) select EmployeeId, courseId, AVG(EvalScore) AvgScore from Evals_CTE group by EmployeeId, courseId All that said and done the question is asking two different things that can only be answered with two different approaches. I think we got two for one here. let's move on to the next question :)
upvoted 1 times
...
SimSql
4 years, 6 months ago
The question has two parts: 1)You must create a report that returns course identifiers and the average evaluation score for each course Ok If you want to solve this part use: ;with Evals_CTE (courseId, EmployeeId, EvalScore) AS ( select CourseID, EmployeeID, EvalScore from Evaluations ) select courseId, AVG(EvalScore) AvgScore from Evals_CTE group by courseId
upvoted 1 times
...
SimSql
4 years, 6 months ago
You are welcome to use this sample date below: use test3 go create table Evaluations( EvaluationID int not null, EmployeeID int not null, CourseId int null, EvalScore int null ) insert into Evaluations values (1, 11, 2000, 89), (1, 11, 2000, 91), (2, 11, 3000, 90), (2, 11, 3000, 80), (3, 11, 4000, 78), (3, 11, 4000, 88), (4, 22, 2000, 90), (4, 22, 2000, 60), (5, 22, 3000, 70), (5, 22, 3000, 90), (6, 22, 4000, 88), (6, 22, 4000, 98), (7, 33, 2000, 80), (7, 33, 2000, 90), (8, 33, 3000, 80), (8, 33, 3000, 90), (9, 33, 4000, 86), (9, 33, 4000, 86), (10,44, 2000, 70), (10,44, 2000, 90), (10,44, 3000, 70), (10,44, 3000, 60), (10,44, 4000, 70), (10,44, 4000, 90)
upvoted 1 times
...
SimSql
4 years, 6 months ago
That is right the Group by Clause is missing here. The example given above has the Group By that is why it works. Question needs some corrections.
upvoted 1 times
...
Andy7622
4 years, 6 months ago
is it only me who doesn't see GROUP BY clause?
upvoted 1 times
...
HA2020
4 years, 7 months ago
You have to provide a name for every column in a table...including the table returned by the function, so the 2nd choice should be the one with a name. Check something similar: https://stackoverflow.com/questions/20251911/column-alias-error-with-sql-server-udf Tested: create table employees(ID int, orderAmount INT); GO insert into employees values(1, 5),(2,5),(3,5),(4,4),(5,1); GO CREATE function MyF(@var int) returns table as Return select ID, sum(orderAmount) as S from employees group by ID having sum(orderAmount) > @var; GO Select * from MyF(4);
upvoted 2 times
...
TheDUdeu
4 years, 9 months ago
Need a Group By C.Course and it has to be Having Sum(cp.NumStudents) > @totalStudents
upvoted 3 times
...
stm22
4 years, 11 months ago
having wont work without a group by
upvoted 4 times
jonasdv
4 years, 8 months ago
actually it does work. When GROUP BY is not used, there is an implicit single, aggregated group. https://docs.microsoft.com/en-us/sql/t-sql/queries/select-having-transact-sql?view=sql-server-ver15
upvoted 3 times
...
...
loceweh520
5 years, 3 months ago
You must provide alias for column, otherwise you will get compilation error when creating function. Group by is another thing which is missing here but let's suppose that is not part of this question.
upvoted 8 times
...
Andybug
5 years, 4 months ago
having is correct
upvoted 3 times
...
fabzo
5 years, 7 months ago
Missing alias as well
upvoted 3 times
...
fabzo
5 years, 7 months ago
I agree where cannot be used. Should be having
upvoted 3 times
...
prakash101179
5 years, 9 months ago
'Group by' is missing as well.
upvoted 17 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 ...