Dludora/DAIL-BIRD huggingface dataset:
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: List the marital status of customers within the age of 40 to 60 that has the highest income among the group. age of 40 to 60 refers to age BETWEEN 40 AND 60; the highest income refers to MAX(INCOME_K); */
SELECT 
SELECT T1.MARITAL_STATUS FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.age >= 40 AND T1.age <= 60 ORDER BY T2.INCOME_K DESC LIMIT 1
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: What is the number of inhabitants of male customers ages from 20 to 30 years old who are farming or fishing? male customers ages from 20 to 30 years old refer to SEX = 'Male' where age BETWEEN 20 AND 30; farming or fishing refers to OCCUPATION; number of inhabitants refers to INHABITANTS_K; */
SELECT 
SELECT T2.INHABITANTS_K FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.OCCUPATION = 'Farming-fishing' AND T1.SEX = 'Male' AND T1.age >= 20 AND T1.age <= 30
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: Among the customers with a marital status of married-civ-spouse, list the number of inhabitants and age of those who are machine-op-inspct. OCCUPATION = 'Machine-op-inspct'; number of inhabitants refers to INHABITANTS_K; */
SELECT 
SELECT T2.INHABITANTS_K FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.OCCUPATION = 'Farming-fishing' AND T1.SEX = 'Male' AND T1.age >= 20 AND T1.age <= 30
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: In female customers ages from 50 to 60, how many of them has an number of inhabitants ranges from 19 to 24? female customers ages from 50 to 60 refer to SEX = 'Female' where age BETWEEN 50 AND 60; number of inhabitants ranges from 19 to 24 refers to INHABITANTS_K BETWEEN 19 AND 24; */
SELECT 
SELECT COUNT(T1.ID) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.SEX = 'Female' AND T1.age >= 50 AND T1.age <= 60 AND T2.INHABITANTS_K >= 19 AND T2.INHABITANTS_K <= 24
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: List the income and number of inhabitants of customers with an age greater than the 80% of average age of all customers? age greater than the 80% of average age refers to age > (AVG(age) * 0.8); income refers to INCOME_K; number of inhabitants refers to INHABITANTS_K; */
SELECT 
SELECT T2.INCOME_K, T2.INHABITANTS_K FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID GROUP BY T2.INCOME_K, T2.INHABITANTS_K HAVING T1.age > 0.8 * AVG(T1.age)
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: In customers with marital status of never married, what is the percentage of customers with income of 2500 and above? DIVIDE(COUNT(INCOME_K ≥ 2500 where MARITAL_STATUS = 'Never-married'), COUNT(INCOME_K where MARITAL_STATUS = 'Never-married')) as percentage; */
SELECT 
SELECT CAST(SUM(CASE WHEN T2.INCOME_K > 2500 THEN 1.0 ELSE 0 END) AS REAL) * 100 / COUNT(*) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.MARITAL_STATUS = 'Never-married'
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: Find and list the id and geographic ID of the elderly customers with an education level below 3. elderly customers with an education level below 3 refer to age > 65 where EDUCATIONNUM < 3; geographic ID refers to GEOID; */
SELECT 
SELECT ID, GEOID FROM Customers WHERE EDUCATIONNUM < 3 AND age > 65
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: List the geographic id of places where the income is above average. geographic ID refers to GEOID; income is above average refers to INCOME_K > DIVIDE(SUM(INCOME_K), COUNT(GEOID)); */
SELECT 
SELECT AVG(INCOME_K) FROM Demog
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: Calculate the number of customers who did not respond in February of 2007. did not respond refers to RESPONSE = 'false'; February of 2007 refers to REF_DATE BETWEEN '2007-02-01 12:00:00.0'AND '2007-02-28 12:00:00.0'; */
SELECT 
SELECT COUNT(REFID) custmoer_number FROM Mailings1_2 WHERE RESPONSE = 'false' AND REF_DATE BETWEEN '2007-02-01' AND '2007-02-28'
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: How many teenagers are working as Machine-op-inspct? teenager is a person aged between 13 and 19 years; OCCUPATION = 'Machine-op-inspct'; */
SELECT 
SELECT COUNT(ID) teenager_number FROM Customers WHERE OCCUPATION = 'Machine-op-inspct' AND age >= 13 AND age <= 19
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: Of customers who provide other services, how many are from places where inhabitants are more than 20000? OCCUPATION = 'Other-service'; inhabitants are more than 20000 refer to INHABITANTS_K > 20; */
SELECT 
SELECT COUNT(T2.GEOID) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.OCCUPATION = 'Other-service' AND T2.INHABITANTS_K > 20
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: Among the male customer in their twenties, how many are from places where the average income is more than 3000? male customer in their twenties refer to SEX = 'Male' where age BETWEEN 20 AND 29; average income is more than 3000 refers to INCOME_K > 3000; */
SELECT 
SELECT COUNT(T2.GEOID) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.SEX = 'Male' AND T2.INCOME_K > 3000 AND T1.age >= 20 AND T1.age <= 29
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: What percentage of elderly customers who are never married in the place with geographic ID 24? elderly customers refer to age > 65; DIVIDE(COUNT(ID where age > 65, MARITAL_STATUS = 'never married' and GEOID = 24), COUNT(ID where GEOID = 24)) as percentage; */
SELECT 
SELECT CAST(SUM(CASE WHEN T1.MARITAL_STATUS = 'never married' THEN 1.0 ELSE 0 END) AS REAL) * 100 / COUNT(*) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.GEOID = 24
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: Among the customers with an average income per inhabitant above 3000, what percentage are in their eighties? average income per inhabitant above 3000 refers to INCOME_K > 3000; eighties refer to age BETWEEN 80 AND 89; DIVIDE(COUNT(INCOME_K > 3000 and age BETWEEN 80 AND 89), COUNT(INCOME_K > 3000 )) as percentage; */
SELECT 
SELECT CAST(SUM(CASE WHEN T1.age BETWEEN 80 AND 89 THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.ID) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T2.INCOME_K > 3000
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: How many of the customer's reference ID that has a TRUE response? reference ID refers to REFID; */
SELECT 
SELECT COUNT(REFID) FROM Mailings1_2 WHERE RESPONSE = 'true'
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: List down the customer's reference ID with true response. reference ID refers to REFID; */
SELECT 
SELECT REFID FROM Mailings1_2 WHERE RESPONSE = 'true'
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: What is the total number of widowed customers with an age below 50? widowed customers with an age below 50 refer to MARITAL_STATUS = 'Widowed' where age < 50; */
SELECT 
SELECT COUNT(ID) FROM Customers WHERE MARITAL_STATUS = 'Widowed' AND age < 50
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: List down the geographic identifier with an number of inhabitants less than 30. geographic identifier with an number of inhabitants less than 30 refers to GEOID where INHABITANTS_K < 30; */
SELECT 
SELECT GEOID FROM Demog WHERE INHABITANTS_K < 30
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: In geographic identifier from 10 to 30, how many of them has an income below 2000? GEOID BETWEEN 10 AND 30; INCOME_K < 2000; */
SELECT 
SELECT COUNT(GEOID) FROM Demog WHERE INCOME_K < 2000 AND GEOID >= 10 AND GEOID <= 30
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: What is the marital status of the customer ages 62 with an level of education of 7? customer ages 62 with an level of education of 7 refer age = 62 where EDUCATIONNUM = 7; */
SELECT 
SELECT DISTINCT MARITAL_STATUS FROM Customers WHERE EDUCATIONNUM = 7 AND age = 62
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: List down the number of inhabitants of customers with a widowed marital status and false response . number of inhabitants refers to INHABITANTS_K; RESPONSE = 'false'; */
SELECT 
SELECT COUNT(T1.ID) FROM Customers AS T1 INNER JOIN Mailings1_2 AS T2 ON T1.ID = T2.REFID INNER JOIN Demog AS T3 ON T1.GEOID = T3.GEOID WHERE T1.MARITAL_STATUS = 'Widowed' AND T2.RESPONSE = 'true'
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: What is the response and number of inhabitants of the oldest female customer? number of inhabitants refers to INHABITANTS_K; oldest female customer refers to SEX = 'Female' where MAX(age); */
SELECT 
SELECT T2.RESPONSE, T3.INHABITANTS_K FROM Customers AS T1 INNER JOIN Mailings1_2 AS T2 ON T1.ID = T2.REFID INNER JOIN Demog AS T3 ON T1.GEOID = T3.GEOID WHERE T1.SEX = 'Female' ORDER BY T1.age DESC LIMIT 1
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: Among the female customers with an level of education of 3 and below, list their income. female customers with level of education of 3 and below refer to SEX = 'Female' where EDUCATIONNUM ≤ 3; income refers to INCOME_K; */
SELECT 
SELECT INCOME_K FROM Demog WHERE GEOID IN ( SELECT GEOID FROM Customers WHERE EDUCATIONNUM < 3 AND SEX = 'Female' )
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: List the level of education and income of customers ages from 30 to 55 with a true response. ages from 30 to 55 refer to age BETWEEN 30 AND 55; RESPONSE = 'true'; income refers to INCOME_K; education level refers to EDUCATIONNUM; */
SELECT 
SELECT T1.EDUCATIONNUM, T3.INCOME_K FROM Customers AS T1 INNER JOIN Mailings1_2 AS T2 ON T1.ID = T2.REFID INNER JOIN Demog AS T3 ON T1.GEOID = T3.GEOID WHERE T1.age >= 30 AND T1.age <= 55 AND T2.RESPONSE = 'true'
/* Given the following database schema: */
CREATE TABLE Demog
(
    GEOID         INTEGER
        constraint Demog_pk
            primary key,
    INHABITANTS_K REAL,
    INCOME_K      REAL,
    A_VAR1        REAL,
    A_VAR2        REAL,
    A_VAR3        REAL,
    A_VAR4        REAL,
    A_VAR5        REAL,
    A_VAR6        REAL,
    A_VAR7        REAL,
    A_VAR8        REAL,
    A_VAR9        REAL,
    A_VAR10       REAL,
    A_VAR11       REAL,
    A_VAR12       REAL,
    A_VAR13       REAL,
    A_VAR14       REAL,
    A_VAR15       REAL,
    A_VAR16       REAL,
    A_VAR17       REAL,
    A_VAR18       REAL
)

CREATE TABLE mailings3
(
    REFID    INTEGER
        constraint mailings3_pk
            primary key,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Customers"
(
    ID             INTEGER
        constraint Customers_pk
            primary key,
    SEX            TEXT,
    MARITAL_STATUS TEXT,
    GEOID          INTEGER
        constraint Customers_Demog_GEOID_fk
            references Demog,
    EDUCATIONNUM   INTEGER,
    OCCUPATION     TEXT,
    age            INTEGER
)

CREATE TABLE "Mailings1_2"
(
    REFID    INTEGER
        constraint Mailings1_2_pk
            primary key
        constraint Mailings1_2_Customers_ID_fk
            references Customers,
    REF_DATE DATETIME,
    RESPONSE TEXT
)

CREATE TABLE "Sales"
(
    EVENTID    INTEGER
        constraint Sales_pk
            primary key,
    REFID      INTEGER
        references Customers,
    EVENT_DATE DATETIME,
    AMOUNT     REAL
)

/* Answer the following: In male customers ages from 30 to 50, how many of them has an income ranges from 2000 to 2300? male customers ages from 30 to 50 refer to SEX = 'Male' where age BETWEEN 30 AND 50; income ranges from 2000 to 2300 refers to INCOME_K BETWEEN 2000 AND 3000; */
SELECT 
SELECT COUNT(T1.ID) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.SEX = 'Male' AND T1.age >= 30 AND T1.age <= 50 AND T2.INCOME_K >= 2000 AND T2.INCOME_K <= 2300