DA0-002 · Question #49
A table contains several rows of cellular numbers with call timestamps, call durations, called numbers, and carriers of the called number. Which of the following allows a data analyst to sort the…
The correct answer is C. SELECT cellular_number, called_number_carrier, SUM(call_duration) FROM calls GROUP BY. To sort cellular numbers by carrier and include total call durations, the SQL query must SELECT the cellular number, carrier, and SUM of call duration, then GROUP BY both the cellular number and carrier, and finally ORDER BY the carrier.
Question
A table contains several rows of cellular numbers with call timestamps, call durations, called numbers, and carriers of the called number. Which of the following allows a data analyst to sort the cellular numbers based on the carriers of the called numbers and include the total call durations?
Options
- ASELECT cellular_number, called_number_carrier, SUM(call_duration) FROM calls GROUP BY
- BSELECT cellular_number, SUM(call_duration) FROM calls GROUP BY call_duration ORDERBY
- CSELECT cellular_number, called_number_carrier, SUM(call_duration) FROM calls GROUP BY
- DSELECT cellular_number, called_number_carrier, SUM(call_duration) FROM calls GROUP BY
How the community answered
(20 responses)- A5% (1)
- B10% (2)
- C80% (16)
- D5% (1)
Why each option
To sort cellular numbers by carrier and include total call durations, the SQL query must `SELECT` the cellular number, carrier, and `SUM` of call duration, then `GROUP BY` both the cellular number and carrier, and finally `ORDER BY` the carrier.
This choice is incomplete as it lacks the `GROUP BY` columns and `ORDER BY` clause in the provided snippet, making it syntactically incorrect for the desired aggregation and sorting.
This query attempts to `GROUP BY call_duration`, which is incorrect for summarizing by cellular number and carrier, and the `ORDER BY` clause is also incomplete.
To aggregate `SUM(call_duration)` for each `cellular_number` and `called_number_carrier`, both non-aggregated columns must be included in the `GROUP BY` clause. The `ORDER BY called_number_carrier` clause then sorts the results as requested.
This choice is incomplete as it lacks the `GROUP BY` columns and `ORDER BY` clause in the provided snippet, making it syntactically incorrect for the desired aggregation and sorting.
Concept tested: SQL GROUP BY and ORDER BY clauses
Source: https://learn.microsoft.com/en-us/sql/t-sql/queries/select-group-by-transact-sql
Topics
Community Discussion
No community discussion yet for this question.