Exam DA0-002 Topic 1 Question 32 Discussion
Actual exam question for CompTIA's DA0-002 exam
Question #: 32
Topic #: 1
Question #: 32
Topic #: 1
The following SQL code returns an error in the program console:
SELECT firstName, lastName, SUM(income)
FROM companyRoster
SORT BY lastName, income
Which of the following changes allows this SQL code to run?
SELECT firstName, lastName, SUM(income)
FROM companyRoster
SORT BY lastName, income
Which of the following changes allows this SQL code to run?
Suggested Answer: B Vote an answer
This question falls under theData Analysisdomain, focusing on SQL query correction. The query uses an aggregate function (SUM) but has two issues: it uses "SORT BY" (incorrect syntax) and lacks a GROUP BY clause for non-aggregated columns.
* The query selects firstName, lastName, and SUM(income), but firstName and lastName are not aggregated, requiring a GROUP BY clause.
* "SORT BY" is incorrect; the correct syntax is "ORDER BY."
* Option A: SELECT firstName, lastName, SUM(income) FROM companyRoster HAVING SUM (income) > 10000000This adds a HAVING clause but doesn't fix the GROUP BY issue, so it's still invalid.
* Option B: SELECT firstName, lastName, SUM(income) FROM companyRoster GROUP BY firstName, lastNameThis adds the required GROUP BY clause for firstName and lastName, fixing the aggregation error. While it removes the ORDER BY, the query will run without it, addressing the primary error.
* Option C: SELECT firstName, lastName, SUM(income) FROM companyRoster ORDER BY firstName, incomeThis fixes "SORT BY" to "ORDER BY" but doesn't address the missing GROUP BY, so the query remains invalid.
* Option D: SELECT firstName, lastName, SUM(income) FROM companyRosterThis removes the ORDER BY but still lacks the GROUP BY clause, making it invalid.
The DA0-002 Data Analysis domain includes "applying the appropriate descriptive statistical methods using SQL queries," and adding GROUP BY fixes the aggregation error, allowing the query to run.
Reference: CompTIA Data+ DA0-002 Draft Exam Objectives, Domain 3.0 Data Analysis.
* The query selects firstName, lastName, and SUM(income), but firstName and lastName are not aggregated, requiring a GROUP BY clause.
* "SORT BY" is incorrect; the correct syntax is "ORDER BY."
* Option A: SELECT firstName, lastName, SUM(income) FROM companyRoster HAVING SUM (income) > 10000000This adds a HAVING clause but doesn't fix the GROUP BY issue, so it's still invalid.
* Option B: SELECT firstName, lastName, SUM(income) FROM companyRoster GROUP BY firstName, lastNameThis adds the required GROUP BY clause for firstName and lastName, fixing the aggregation error. While it removes the ORDER BY, the query will run without it, addressing the primary error.
* Option C: SELECT firstName, lastName, SUM(income) FROM companyRoster ORDER BY firstName, incomeThis fixes "SORT BY" to "ORDER BY" but doesn't address the missing GROUP BY, so the query remains invalid.
* Option D: SELECT firstName, lastName, SUM(income) FROM companyRosterThis removes the ORDER BY but still lacks the GROUP BY clause, making it invalid.
The DA0-002 Data Analysis domain includes "applying the appropriate descriptive statistical methods using SQL queries," and adding GROUP BY fixes the aggregation error, allowing the query to run.
Reference: CompTIA Data+ DA0-002 Draft Exam Objectives, Domain 3.0 Data Analysis.
by Olga at May 14, 2026, 02:10 AM
0
0
0
10
Comments
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.
Report Comment
Commenting
You can sign-up / login (it's free).