PrepAway - Latest Free Exam Questions & Answers

The query must return the following columns: tblProvinc…

Note: This question is part of a series of questions that present the same scenario. Each question inthe series contains a unique solution that might meet the stated goals. Some question sets might have
more than one correct solution, while others might not have a correct solution.
After you answer a question in this section. You will NOT be able to return to it. As a result, these
questions will not appear in the review screen.
A database has two tables as shown in the following database diagram:

You need to list all provinces that have at least two large cities. A large city is defined as having a population of
at least one million residents. The query must return the following columns:
tblProvince.ProvinceId
tblProvince.ProvinceName
a derived column named LargeCityCount that presents the total count of large cities for the province
Solution: You run the following Transact-SQL statement:

Does the solution meet the goal?

PrepAway - Latest Free Exam Questions & Answers

A.
Yes

B.
No

Explanation:
We need to list all provinces that have at least two large cities. There is no reference to this in the code.

3 Comments on “The query must return the following columns: tblProvinc…

  1. eder says:

    THE CORRECT ANSWER IS NO , SOLO LE FALTO EN EL WHERE LA CONDICION EN LA TABLA NO DERIVADA where s.LargeCityCount>=2

    CREATE TABLE test.tblProvince(
    ProvinceID int NOT NULL IDENTITY(1,1)PRIMARY KEY CLUSTERED,
    ProvinceName VARCHAR(250)NOT NULL,
    Description VARCHAR(250)NOT NULL
    )

    INSERT INTO test.tblProvince VALUES
    (‘Ayacucho’,’Provincia de Ayacucho’),
    (‘Amazonas’,’Provincia de Piura’),
    (‘Ancash’,’Provincia de Piura’),
    (‘Lima’,’Provincia de Piura’),
    (‘Piura’,’Provincia de Piura’)

    CREATE TABLE test.tblCity (
    CityID int NOT NULL IDENTITY(1,1)PRIMARY KEY CLUSTERED,
    CityName VARCHAR(250)NOT NULL,
    Population int NULL,
    ProvinceID int NOT NULL,
    Description VARCHAR(250)NOT NULL
    )

    ALTER TABLE test.tblCity
    ADD CONSTRAINT FK_TblCity_ProvinceID FOREIGN KEY (ProvinceID)
    REFERENCES test.tblProvince (ProvinceID)
    ON DELETE CASCADE
    ON UPDATE CASCADE

    INSERT INTO test.tblCity
    VALUES
    (‘Huamanga’,137583,5,’ciudad Huamanga’ ),
    (‘Cangallo’,114630,5,’Cangallo’ ),
    (‘Huanca sancos’,4046,5,’Huanca sancos’ ),

    (‘Chachapoyas’,27301,1,’ciudad chacha’ ),
    (‘bagua’,37198,1,’ciudad de bagua’ ),
    (‘bongara’,12851,1,’ciudad de bongara’ ),

    (‘huaraz’,80099,2,’ciudad ‘ ),
    (‘aija’,3242,2,’ciudad ‘ ),
    (‘carhuaz’,21786,2,’ciudad ‘ ),

    (‘Lima’,11000000,3,’ciudad de lima’ ),
    (‘Barranca’,71231,3,’ciudad de barranca’ ),
    (‘CaƱete’,10500000,3,’ciudad de barranca’ ),

    (‘Piura’,1935920,4,’ciudad de piura’ )

    USANDO TABLA DERIVADAS ES :
    SELECT p.provinceID,p.provinceName,s.LargeCityCount
    FROM test.tblProvince AS p
    OUTER APPLY(
    SELECT count(*) as LargeCityCount
    FROM test.tblCity as c
    WHERE c.Population>=1000000 and p.ProvinceID=c.ProvinceID
    )as s
    WHERE S.LargeCityCount>=2

    ———O——

    SELECT S.ProvinceName,S.LargeCityCount
    FROM (
    SELECT p.ProvinceName,COUNT(*)AS LargeCityCount
    FROM test.tblCity as c
    inner JOIN test.tblProvince as p
    ON c.ProvinceID=P.ProvinceID
    WHERE c.Population>=1000000
    GROUP BY p.ProvinceName
    )as s
    where s.LargeCityCount>=2




    3



    1

Leave a Reply