Consider the following tables and data:
CREATE TABLE “public”.countries (
country_code char(2) NOT NULL ,
country_name varchar(100) NOT NULL ,
CONSTRAINT pk_countries_country_code PRIMARY KEY ( country_code )
);
CREATE TABLE “public”.cities (
city_id integer NOT NULL ,
city_name varchar(100) NOT NULL ,
country_code char(2) NOT NULL ,
inhabitants bigint NOT NULL ,
average_salary integer NOT NULL ,
CONSTRAINT pk_cities_city_id PRIMARY KEY ( city_id )
);
ALTER TABLE “public”.cities ADD CONSTRAINT fk_cities_countries FOREIGN KEY ( country_code ) REFERENCES “public”.countries( country_code );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘BB’, ‘Bartinia’ );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘CF’, ‘Cliffinia’ );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘GM’, ‘Gemerani’ );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘LT’, ‘Lituania’ );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘MF’, ‘Memrish’ );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘NR’, ‘Nirania’ );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘SC’, ‘Scanji’ );
INSERT INTO “public”.countries( country_code, country_name ) VALUES ( ‘RM’, ‘Rimani’ );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 0, ‘Fremont’, ‘MF’, 731057, 3653 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 1, ‘Fresno’, ‘BB’, 70992, 4593 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 2, ‘Portland’, ‘SC’, 67120, 4593 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 3, ‘Buffalo’, ‘CF’, 768156, 3397 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 4, ‘Detroit’, ‘GM’, 227334, 391 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 5, ‘Las Vegas’, ‘MF’, 660319, 124 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 6, ‘St. Paul’, ‘SC’, 806673, 3496 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 7, ‘Wichita’, ‘CF’, 29817, 4024 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 8, ‘Oakland’, ‘MF’, 811170, 756 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 9, ‘Las Vegas’, ‘SC’, 945416, 4622 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 10, ‘Norfolk’, ‘SC’, 152733, 3819 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 11, ‘Boston’, ‘GM’, 910276, 16 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 12, ‘St. Louis’, ‘NR’, 999146, 3682 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 13, ‘Norfolk’, ‘GM’, 539992, 4781 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 14, ‘Greensboro’, ‘CF’, 977512, 4118 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 15, ‘Milwaukee’, ‘MF’, 158437, 943 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 16, ‘Tulsa’, ‘MF’, 549088, 1630 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 17, ‘St. Paul’, ‘NR’, 93545, 3757 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 18, ‘Tulsa’, ‘SC’, 443390, 1402 );
INSERT INTO “public”.cities( city_id, city_name, country_code, inhabitants, average_salary ) VALUES ( 19, ‘Shreveport’, ‘GM’, 412861, 1150 );