exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 79 discussion

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

You have a database named MyDb. You run the following Transact-SQL statements:

A value of 1 in the IsActive column indicates that a user is active.
You need to create a count for active users in each role. If a role has no active users. You must display a zero as the active users count.
Which Transact-SQL statement should you run?

A.

B.

C.

D.

Show Suggested Answer Hide Answer
Suggested Answer: B

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
Scooter123
Highly Voted 5 years, 7 months ago
Answer B is wrong because the COUNT(*) returns 1, it should be COUNT(U.UserId)
upvoted 16 times
...
mlourinho
Highly Voted 5 years, 7 months ago
Actually, none of the answers works... (I checked). D answer needs a join that doesn't have B answer should be COUNT(U.UserID) otherwise COUNT(*) even without active users always returns the value 1
upvoted 15 times
...
Angelcr
Most Recent 4 years, 5 months ago
None of the options are correct: The correct answer is option A from question 43. select R.RoleID, count (u.UserID) by #tblRole R LEFT JOIN ( SELECT j.UserID, j.RoleID FROM #tblUsers j where j.IsActive = 1 ) u in r.RoleID = u.RoleID GROUP BY r.RoleID What the subquery does is take only the users that are active, that is, only the IsActive = 1 but as in the outside query they are compared to be the same and since it is a LEFT JOIN, obviously those with IsActive = 0 will be then since it is a LEFT JOIN, I know if they are going to show but they are NULL, the count () sends it to 0, COUNT (*) should not be used because if it returns 1 since COUNT (*) even counts the nulls.
upvoted 1 times
...
Anette
5 years, 1 month ago
This question is the same with Q43 in these questions and Answer is: SELECT R.RoleName, COUNT(UserId) AS ActiveUserCount FROM tblRoles R LEFT JOIN (SELECT UserID, RoleID FROM tblUsers WHERE IsActive = 1) U ON U.RoleId = R.RoleId GROUP BY R.RoleId, R.RoleName (TESTED)
upvoted 7 times
Anette
5 years, 1 month ago
So, it is correct C
upvoted 1 times
Anette
5 years, 1 month ago
Sorry B (Count(UserId) = Count(*))
upvoted 2 times
Anette
5 years, 1 month ago
Anyway Count* = 1 when there is no active users :/
upvoted 4 times
...
...
...
...
Barbedx
5 years, 4 months ago
I think is just cropped a part of answer D, and it should be correct
upvoted 4 times
Braindripper
4 years, 9 months ago
agree with you - seems that the have miss something on crop. here is a similar questions with answers: https://www.briefmenow.org/microsoft/which-transact-sql-statement-should-you-run-10/
upvoted 1 times
...
...
fabzo
5 years, 7 months ago
I agree with Scooter123: SELECT R.RoleName, COUNT(UserId) AS ActiveUserCount FROM tb1Roles R LEFT JOIN (SELECT UserID, RoleID FROM tb1Users WHERE IsActive = 1) U ON U.RoleId = R.RoleId GROUP BY R.RoleId, R.RoleName I have simulated this as well
upvoted 5 times
...
safiullah
5 years, 10 months ago
Hallo, I think the correct answer should be D, because there is a condition in the question "If a role has no active users, you must disply a zero as the active users count". To satisfy this condition the correct answer should be query D, where ISNULL (U.activeUseCount,0) is used to satify the above condition. https://docs.microsoft.com/en-us/sql/t-sql/functions/isnull-transact-sql?view=sql-server-2017
upvoted 11 times
Bartek
5 years, 9 months ago
Answer B is fine. Answer D even do not have "ON" clause after "JOIN" clause
upvoted 13 times
...
BabyBee
4 years, 7 months ago
Yes, the best option including at the end the ON clause like so: ON R.RoleID = U.RoleID
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 ...