You have a table named Cities that has the following two columns: CityID and CityName. The CityID column uses the int data type, and CityName uses nvarchar(max)

SIMULATION

You have a table named Cities that has the following two columns: CityID and CityName. The CityID column uses the int data type, and CityName uses nvarchar(max).

You have a table named RawSurvey. Each row includes an identifier for a question and the number of persons that responded to that question from each of four cities.

The table contains the following representative data:

A reporting table named SurveyReport has the following columns: CityID, QuestionID, and RawCount, where RawCount is the value from the RawSurvey table.

You need to write a Transact-SQL query to meet the following requirements:

– Retrieve data from the RawSurvey table in the format of the SurveyReport table.

– The CityID must contain the CityID of the city that was surveyed.

– The order of cities in all SELECT queries must match the order in the RawSurvey table.

– The order of cities in all IN statements must match the order in the RawSurvey table.

Construct the query using the following guidelines:

– Use one-part names to reference tables and columns, except where not possible.

– ALL SELECT statements must specify columns.

– Do not use column or table aliases, except those provided.

– 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: 1 Select CityID, QuestionID, RawCount

2 FROM (SELECT QuestionId, Tokyo, Boston, London, NewYork FROM RawSurvey) AS t1

3 UNPIVOT (RawCount FOR CityName IN (Tokyo, Boston, London, NewYork)) AS t2

4 JOIN Cities ON t2.CityName = t1.CityName

UNPIVOT must be used to rotate columns of the Rawsurvey table into column values.

References: https://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx

Latest 70-761 Dumps Valid Version with 212 Q&As

Latest And Valid Q&A | Instant Download | Once Fail, Full Refund

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments