#223 Finding the House with the Highest Residents’ Purchase Amount

Companies:
MangoOffice
Themes:
SQLJoinsAggregationPractice

Find the street and house number whose residents made purchases for the largest total amount during the selected time interval:

CREATE TABLE employee (
    id uuid NOT NULL,
    "name" varchar(255) NOT NULL,
    surname varchar(255) NOT NULL,
    created_at timestamp NOT NULL,
    CONSTRAINT employee_pk PRIMARY KEY (id),
    CONSTRAINT employee_un UNIQUE (name, surname)
);

CREATE TABLE address (
    id uuid NOT NULL,
    employee_id uuid NOT NULL,
    city varchar(255) NOT NULL,
    street varchar(255) NOT NULL,
    building int8 NOT NULL,
    CONSTRAINT address_pk PRIMARY KEY (id),
    CONSTRAINT address_fk FOREIGN KEY (employee_id) REFERENCES employee(id)
);

CREATE TABLE purshasing (
    id uuid NOT NULL,
    employee_id uuid NOT NULL,
    "name" varchar(255) NOT NULL,
    amount int8 NOT NULL,
    created_at timestamp NOT NULL,
    CONSTRAINT purshasing_pk PRIMARY KEY (id),
    CONSTRAINT purshasing_fk FOREIGN KEY (employee_id) REFERENCES employee(id)
);

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in