exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 20 discussion

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

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.

Show Suggested Answer Hide Answer
Suggested Answer: Please see explanation
SELECT Average(NormalizedReading), NearestMountain(SensorID)

FROM GroundSensors -
WHERE TREMOR IS NOT 0 AND NormalizedReading IS NOT NULL
GROUP BY NearestMountain(SensorID)
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.
References:
https://msdn.microsoft.com/en-us/library/ms177673.aspx

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
BenAsare
Highly Voted 5 years, 7 months ago
SELECT AVG(normalizedreading), NearestMountain(SensorID) FROM groundsensor WHERE normalizedreading is not null AND tremor <> 0 GROUP BY NearestMountain(SensorID)
upvoted 14 times
...
Dieter
Highly Voted 5 years, 9 months ago
"WHERE TREMOR IS NOT 0...L" > should be "WHERE TREMOR <> 0 " instead, since you need to check for the value zero.
upvoted 13 times
...
finger
Most Recent 3 years, 1 month ago
is NearestMountain a function?
upvoted 1 times
...
mccallumafc
4 years, 7 months ago
Could 'and tremor != 0' also be used here?
upvoted 1 times
...
Mountie
4 years, 9 months ago
SELECT AVG(normalizedreading), NearestMountain(SensorID) FROM groundsensor WHERE normalizedreading is not null OR tremor <> 0 GROUP BY NearestMountain(SensorID)
upvoted 1 times
...
Aghie
4 years, 9 months ago
Select avg(normalizedreading), NearestMountain(Location) from groundsensor where normalizedreading is not null AND tremor <> 0 group by NearestMountain(Location)
upvoted 1 times
...
tcroots19
5 years, 3 months ago
I'm not sure you actually need the NULL check b/c AVG seems to ignore these https://stackoverflow.com/questions/22220449/sql-avg-with-null-values
upvoted 1 times
...
DEBRA
5 years, 4 months ago
select avg(normalisedReading), nearestmountain(SensorId) from Ground sensors where tremorID <> 0 and normalisedreading is not null order by nearestmountain(SensorId)
upvoted 1 times
...
Vanesa30
5 years, 4 months ago
select NearestMountain(SensorID),Avg(NormalizeReading) from GroundSensors where NormalizedReading is null) or (Tremor=0) group by NearestMountain(SensorID)
upvoted 2 times
...
hgi
5 years, 5 months ago
imo, it's logical to use Location to find the nearest mountain...
upvoted 4 times
Anette
5 years, 1 month ago
yes but it is calculated in NearestMountain Function through Sensor ID
upvoted 2 times
...
...
prakash101179
5 years, 8 months ago
Answer should be - Select avg(normalizedreading), NearestMountain(SensorID) from groundsensor where normalizedreading is not null or tremor <> 0 group by NearestMountain(SensorID)
upvoted 6 times
Barbedx
5 years, 4 months ago
this should be AND statement
upvoted 5 times
...
...
M4x
5 years, 9 months ago
SELECT Average(NormalizedReading), NearestMountain(SensorID) must be SELECT AVG(NormalizedReading), NearestMountain(SensorID)
upvoted 5 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 ...