Where RawCount is the value from the RawSurvey table.

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.
Your Response type here
A. Please see explanation

microsoft-exams

2 thoughts on “Where RawCount is the value from the RawSurvey table.

  1. This works for me:
    SELECT CityID, QuestionID, RawCount
    FROM (SELECT QuestionID, [Tokyo], [Boston], [London], [New York] FROM RawSurvey) AS t1
    UNPIVOT (RawCount FOR CityName IN([Tokyo], [Boston], [London], [New York])) AS t2
    JOIN Cities ON t2.CityName=Cities.CityName

  2. Correct Answer:

    Select CityID, QuestionID, RawCount
    FROM
    Select QuestionID, CityName, RawCount
    from (
    select QuestionID, Tokyo, Boston, London, NewYork
    from RawSurvey
    ) as t1
    UNPIVOT
    (
    RawCount for CityName in (‘Tokyo’, ‘Boston’, ‘London’, ‘NewYork’)
    ) as t2
    Join Cities on Cities.CityName = T2.CityName

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.