/* Given the following database schema: */
CREATE TABLE all_prevalences
(
    ITEM                    TEXT
            primary key,
    "POPULATION TYPE"       TEXT,
    OCCURRENCES             INTEGER,
    "POPULATION COUNT"      INTEGER,
    "PREVALENCE RATE"       REAL,
    "PREVALENCE PERCENTAGE" REAL
)

CREATE TABLE patients
(
    patient    TEXT
            primary key,
    birthdate  DATE,
    deathdate  DATE,
    ssn        TEXT,
    drivers    TEXT,
    passport   TEXT,
    prefix     TEXT,
    first      TEXT,
    last       TEXT,
    suffix     TEXT,
    maiden     TEXT,
    marital    TEXT,
    race       TEXT,
    ethnicity  TEXT,
    gender     TEXT,
    birthplace TEXT,
    address    TEXT
)

CREATE TABLE encounters
(
    ID                TEXT
            primary key,
    DATE              DATE,
    PATIENT           TEXT,
    CODE              INTEGER,
    DESCRIPTION       TEXT,
    REASONCODE        INTEGER,
    REASONDESCRIPTION TEXT,
    foreign key (PATIENT) references patients(patient)
)

CREATE TABLE allergies
(
    START       TEXT,
    STOP        TEXT,
    PATIENT     TEXT,
    ENCOUNTER   TEXT,
    CODE        INTEGER,
    DESCRIPTION TEXT,
    primary key (PATIENT, ENCOUNTER, CODE),
    foreign key (ENCOUNTER) references encounters(ID),
    foreign key (PATIENT) references patients(patient)
)

CREATE TABLE careplans
(
    ID                TEXT,
    START             DATE,
    STOP              DATE,
    PATIENT           TEXT,
    ENCOUNTER         TEXT,
    CODE              REAL,
    DESCRIPTION       TEXT,
    REASONCODE        INTEGER,
    REASONDESCRIPTION TEXT,
    foreign key (ENCOUNTER) references encounters(ID),
    foreign key (PATIENT) references patients(patient)
)

CREATE TABLE conditions
(
    START       DATE,
    STOP        DATE,
    PATIENT     TEXT,
    ENCOUNTER   TEXT,
    CODE        INTEGER,
    DESCRIPTION TEXT,
    foreign key (ENCOUNTER) references encounters(ID),
    foreign key (PATIENT) references patients(patient),
    foreign key (DESCRIPTION) references all_prevalences(ITEM)
)

CREATE TABLE immunizations
(
    DATE        DATE,
    PATIENT     TEXT,
    ENCOUNTER   TEXT,
    CODE        INTEGER,
    DESCRIPTION TEXT,
    primary key (DATE, PATIENT, ENCOUNTER, CODE),
    foreign key (ENCOUNTER) references encounters(ID),
    foreign key (PATIENT) references patients(patient)
)

CREATE TABLE medications
(
    START             DATE,
    STOP              DATE,
    PATIENT           TEXT,
    ENCOUNTER         TEXT,
    CODE              INTEGER,
    DESCRIPTION       TEXT,
    REASONCODE        INTEGER,
    REASONDESCRIPTION TEXT,
    primary key (START, PATIENT, ENCOUNTER, CODE),
    foreign key (ENCOUNTER) references encounters(ID),
    foreign key (PATIENT) references patients(patient)
)

CREATE TABLE observations
(
    DATE        DATE,
    PATIENT     TEXT,
    ENCOUNTER   TEXT,
    CODE        TEXT,
    DESCRIPTION TEXT,
    VALUE       REAL,
    UNITS       TEXT,
    foreign key (ENCOUNTER) references encounters(ID),
    foreign key (PATIENT) references patients(patient)
)

CREATE TABLE procedures
(
    DATE              DATE,
    PATIENT           TEXT,
    ENCOUNTER         TEXT,
    CODE              INTEGER,
    DESCRIPTION       TEXT,
    REASONCODE        INTEGER,
    REASONDESCRIPTION TEXT,
    foreign key (ENCOUNTER) references encounters(ID),
    foreign key (PATIENT) references patients(patient)
)

CREATE TABLE "claims"
(
    ID             TEXT
        primary key,
    PATIENT        TEXT
        references patients,
    BILLABLEPERIOD DATE,
    ORGANIZATION   TEXT,
    ENCOUNTER      TEXT
        references encounters,
    DIAGNOSIS      TEXT,
    TOTAL          INTEGER
)

/* Answer the following: How many patients sought medical attention due to a second-degree burn? Describe the care plan recommended to them. second-degree burn refers to encounters.REASONDESCRIPTION = 'Second degree burn'; ; */
SELECT 
SELECT COUNT(DISTINCT T2.PATIENT), T2.DESCRIPTION FROM encounters AS T1 INNER JOIN careplans AS T2 ON T1.PATIENT = T2.PATIENT WHERE T2.REASONDESCRIPTION = 'Second degree burn'