exam questions

Exam DP-600 All Questions

View all questions & answers for the DP-600 exam

Exam DP-600 topic 1 question 10 discussion

Actual exam question from Microsoft's DP-600
Question #: 10
Topic #: 1
[All DP-600 Questions]

You have a Fabric warehouse that contains a table named Staging.Sales. Staging.Sales contains the following columns.

You need to write a T-SQL query that will return data for the year 2023 that displays ProductID and ProductName and has a summarized Amount that is higher than 10,000.
Which query should you use?

  • A.
  • B.
  • C.
  • D.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
TashaP
Highly Voted 9 months, 2 weeks ago
Anything without HAVING() + an aggregate is incorrect. HAVING was created for SQL to deal with filtering using an aggregate. Any option that references TotalAmount is incorrect because there is no nested statement in the syntax. Anything that uses HAVING() + DATEPART() is incorrect because you use a where clause for that. The answer is A.
upvoted 18 times
...
Rakesh16
Most Recent 3 weeks, 6 days ago
Selected Answer: A
SELECT ProductID, ProductName, SUM(Amount) AS TotalAmount FROM Staging.Sales WHERE DATEPART(YEAR, SaleDate) = '2023' GROUP BY ProductID, ProductName HAVING SUM(Amount) > 10000
upvoted 1 times
...
semauni
1 month, 1 week ago
Selected Answer: A
SELECT ProductID, ProductName, SUM(Amount) AS TotalAmount FROM Staging.Sales WHERE DATEPART(YEAR, SaleDate) = '2023' GROUP BY ProductID, ProductName HAVING SUM(Amount) > 10000 Answer A is the only answer with valid syntax. Answer B is excluded because the filter on year should be included in the WHERE-clause. It is the result of a function, but it is not an aggregate. Answer C is excluded because the filter on SUM(Amount) should be included in the HAVING-clause, since this is an aggregate. Answer D is excluded because the HAVING-clause does not accept aliases.
upvoted 2 times
...
BhavaniSubu
4 months, 3 weeks ago
I am confused between A and B. But A is a correct Answer. Here is the explanation- If we use non-aggregate function to Having clause it will throw below error- Column 'SalesDate' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause.
upvoted 1 times
...
sen_su
6 months, 1 week ago
Actually both D & A are correct, aren't they? "TotalAmount" is already available after the GROUP BY clause, or are there any reasons D is not correct?
upvoted 1 times
werka
6 months ago
In D TotalAmount is an alias (HAVING TotalAmount > 10000) and only ORDER BY accepts aliases.
upvoted 7 times
...
...
see007
6 months, 2 weeks ago
In some instances, you might want to exclude individual rows from groups (using a WHERE clause) before applying a condition to groups as a whole (using a HAVING clause). A HAVING clause is like a WHERE clause, but applies only to groups as a whole (that is, to the rows in the result set representing groups), whereas the WHERE clause applies to individual rows. A query can contain both a WHERE clause and a HAVING clause. In that case: The WHERE clause is applied first to the individual rows in the tables or table-valued objects in the Diagram pane. Only the rows that meet the conditions in the WHERE clause are grouped. The HAVING clause is then applied to the rows in the result set. Only the groups that meet the HAVING conditions appear in the query output. You can apply a HAVING clause only to columns that also appear in the GROUP BY clause or in an aggregate function.
upvoted 2 times
...
RunicSkye
7 months ago
the table includes 'SalesDate' but every answer includes 'SaleDate' so they are all wrong!!! E. None of the above
upvoted 1 times
sen_su
6 months, 1 week ago
The Table does not have to include SalesDate. It just return data for the year 2023, which can be filtered under the hood and not to be shown in SELECT.
upvoted 1 times
...
...
stilferx
7 months, 1 week ago
IMHO, A
upvoted 1 times
...
JpLZa
7 months, 1 week ago
I would say Option D. Sum(Amount) AS TotalAmount is effectively TotalAmount > 10000
upvoted 3 times
AdventureChick
1 day, 14 hours ago
The HAVING clause does not allow aliases. This question is testing your knowledge of the order of operations (the order in which SQL statements are processed).
upvoted 1 times
...
...
rmeng
7 months, 1 week ago
Selected Answer: A
SELECT ProductID, ProductName, SUM(Amount) AS TotalAmount FROM Staging.Sales WHERE DATEPART(YEAR, SaleDate) = '2023' GROUP BY ProductID, ProductName HAVING SUM(Amount) > 10000
upvoted 4 times
...
shivamgaurr
7 months, 2 weeks ago
second one could be correct but saledate is neither used in group by nor in any aggregate function. Hence A is the correct answer.
upvoted 1 times
...
earlqq
9 months, 2 weeks ago
BTW spark sql allows us to refer to the count() alias
upvoted 2 times
...
David_Webb
9 months, 3 weeks ago
Selected Answer: A
The answer is A, no-brainer.
upvoted 2 times
...
SamuComqi
9 months, 4 weeks ago
Selected Answer: A
A. SELECT ProductID, ProductName, SUM(Amount) AS TotalAmount FROM Staging.Sales WHERE DATEPART(YEAR, SaleDate) = '2023' GROUP BY ProductID, ProductName HAVING SUM(Amount) > 10000 Selected data is first filtered by Year, then grouped by ProductID and ProductName to compute the TotalAmount. Finally, only SUM(Amount) cane be used after HAVING (not the alias).
upvoted 2 times
...
Momoanwar
9 months, 4 weeks ago
Selected Answer: A
Where to filter year data Having to filter summerized data Alias like TotalAmount not work in having
upvoted 2 times
...
objecto
10 months ago
Selected Answer: A
TotalAmount can not be used with HAVING. You must use SUM(Amount)
upvoted 4 times
...
theseon
10 months ago
Selected Answer: A
Summarized Amount by ProductID and ProductName -> Group BY Above 10.000 -> HAVING SUM(Amount) ...
upvoted 3 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago