Microsoft Exam Questions

You need to create a query that shows the average of th…

SIMULATION
You work for an organization that monitors seismic activity around volcanos. You have a table named
GroundSensors. The table stored data collected from seismic sensors. It includes the columns describes in the
following table:

The database also contains a scalar value function named NearestMountain that returns the name of the
mountain that is nearest to the sensor.You need to create a query that shows the average of the normalized readings from the sensors for each
mountain. The query must meet the following requirements:
Include the average normalized readings and nearest mountain name.
Exclude sensors for which no normalized reading exists.
Exclude those sensors with value of zero for tremor.
Construct the query using the following guidelines:
Use one part names to reference tables, columns and functions.
Do not use parentheses unless required.
Do not use aliases for column names and table names.
Do not surround object names with square brackets.

Part of the correct Transact-SQL has been provided in the answer area below. Enter the code in the answer
area that resolves the problem and meets the stated goals or requirements. You can add code within the code
that has been provided as well as below it.

Use the Check Syntax button to verify your work. Any syntax or spelling errors will be reported by line and
character position.

Answer: See the explanation

Explanation:
SELECT Average(NormalizedReading), NearestMountain(SensorID)
FROM GroundSensors
GROUP BY NearestMountain(SensorID)
WHERE TREMOR IS NOT 0 AND NormalizedReading IS NOT NULL

GROUP BY is a SELECT statement clause that divides the query result into groups of rows, usually for the
purpose of performing one or more aggregations on each group. The SELECT statement returns one row per
group.
https://msdn.microsoft.com/en-us/library/ms177673.aspx