Dludora/DAIL-BIRD huggingface dataset:
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: Which station has the highest number of stores? Calculate the said station's average maximum temperature in February 2012. station with highest number of stores refers to station_nbr where Max(Count(store_nbr)); station refers to station_nbr; in February 2012 refers to substring (date, 1, 7) = '2012-02'; average maximum temperature = Divide(Sum(tmax), 29) */
SELECT 
SELECT CAST(SUM(T2.tmax) AS REAL) / 29 FROM ( SELECT station_nbr FROM relation GROUP BY station_nbr ORDER BY COUNT(store_nbr) DESC LIMIT 1 ) AS T1 INNER JOIN weather AS T2 ON T1.station_nbr = T2.station_nbr WHERE SUBSTR(T2.`date`, 1, 7) = '2012-02'
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: Between the stores under weather station 12, what is the percentage of item 5 sold in store 10 in 2014? weather station 12 refers to station_nbr = 12; item 5 refers to item_nbr = 5; 10 store refers to store_nbr = 10; in 2014 refers to SUBSTR(date, 1, 4) = '2014'; percentage = Divide (Sum(units where store_nbr = 10), Sum(units)) * 100 */
SELECT 
SELECT CAST(SUM(CASE WHEN T2.store_nbr = 10 THEN units * 1 ELSE 0 END) AS REAL) * 100 / SUM(units) FROM relation AS T1 INNER JOIN sales_in_weather AS T2 ON T1.store_nbr = T2.store_nbr WHERE station_nbr = 12 AND item_nbr = 5 AND T2.`date` LIKE '%2014%'
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What is the maximum average speed? maximum average speed refers to Max(avgspeed) */
SELECT 
SELECT MAX(avgspeed) FROM weather
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: How many days did the show fell more than 5 inches? snow fell more than 5 inches refers to snowfall > 5 */
SELECT 
SELECT COUNT(DISTINCT `date`) FROM weather WHERE snowfall > 5
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: How many days did the sun rise before 5 AM? sunrise before 5 Am refers to sunrise < time ('5:00:00') */
SELECT 
SELECT COUNT(DISTINCT `date`) AS days FROM weather WHERE sunrise < time('05:00:00')
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What is the minimum dew point? minimum dew point refers to Min(dewpoint) */
SELECT 
SELECT MIN(dewpoint) FROM weather
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What is the maximum and minimum temperature for station number 1 on 15 January 2012? station number 1 refers to station_nbr = 1 ; minimum temperature = tmin; maximum temperature = tmax; on 15 January 2012 refers to date = '2012-01-15' */
SELECT 
SELECT tmax, tmin FROM weather WHERE station_nbr = 1 AND `date` = '2012-01-15'
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: How many stations were able to sell item 5 on January 2014? item 5 refers to item_nbr = 5; on January 2014 refers to Substring (date, 1, 7) = '2014-01' */
SELECT 
SELECT COUNT(DISTINCT T2.station_nbr) AS number FROM sales_in_weather AS T1 INNER JOIN relation AS T2 ON T1.store_nbr = T2.store_nbr WHERE SUBSTR(`date`, 1, 7) = '2014-01' AND item_nbr = 5
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What is the lowest minimum temperature recorded in store 16 on January 2012? lowest minimum temperature refers to Min(tmin); store 16 refers to store_nbr = 16; on January 2012 refers to Substring (date, 1, 7) = '2012-01' */
SELECT 
SELECT MIN(tmin) FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr WHERE T2.store_nbr = 16 AND T1.`date` LIKE '%2012-01%'
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: How many units of item 7 have been sold by store 7 when the snow is less than 5 inches? item 7 refers to item_nbr = 7; store 7 refers to store_nbr = 7; snow is less than 5 inches refers to snowfall < 5 */
SELECT 
SELECT SUM(units) FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr INNER JOIN sales_in_weather AS T3 ON T2.store_nbr = T3.store_nbr WHERE T2.store_nbr = 7 AND T3.item_nbr = 7 AND T1.snowfall < 5
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: How many items were sold by store 9 during a snowy day? store 9 refers to store_nbr = 9; snowy day refers to snowfall < > 0 and snowfall is not null; item refers to item_nbr */
SELECT 
SELECT COUNT(DISTINCT item_nbr) FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr INNER JOIN sales_in_weather AS T3 ON T2.store_nbr = T3.store_nbr WHERE T3.store_nbr = 9 AND T1.snowfall <> 0 AND T1.snowfall IS NOT NULL
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: List out stations number and items sold by store 17. station number refers to station_nbr; store 17 refers to store_nbr = 17 */
SELECT 
SELECT T1.station_nbr, T2.item_nbr FROM relation AS T1 INNER JOIN sales_in_weather AS T2 ON T1.store_nbr = T2.store_nbr WHERE T1.store_nbr = 17 GROUP BY T1.station_nbr, T2.item_nbr
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: List out dates when haze is recorded in store 35. store 35 refers to store_nbr = 35; haze is recorded refers to codesum like '%'||'HZ'||'%' */
SELECT 
SELECT T1.`date` FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr WHERE T2.store_nbr = 35 AND T1.codesum LIKE '%' OR 'HZ' OR '%'
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What is the sea level and average speed for store number 3 and store number 4? store number 3 refers to store_nbr = 3; average speed refers to avgspeed; store number 4 refers to store_nbr = 4 */
SELECT 
SELECT T1.sealevel, T1.avgspeed FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr WHERE T2.store_nbr = 3 OR T2.store_nbr = 4
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: Which items from store 1 have the highest units sold during rainy day? store 1 refers to store_nbr = 1; highest unit sold refers to Max(units); during rainy day refers to codesum like '%'||'RA'||'%'; item refers to item_nbr */
SELECT 
SELECT T2.item_nbr FROM weather AS T1 INNER JOIN sales_in_weather AS T2 ON T1.`date` = T2.`date` INNER JOIN relation AS T3 ON T2.store_nbr = T3.store_nbr AND T1.station_nbr = T3.station_nbr WHERE T2.store_nbr = 1 AND T1.codesum LIKE '%' OR 'RA' OR '%' GROUP BY T2.item_nbr ORDER BY T2.units DESC LIMIT 1
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What is the ratio of the highest and lowest temperature in store 11? store 11 refers to store_nbr = 11; highest temperature refers to Max(tmax); lowest temperature refers to Min(tmin); ration = Divide (Max(tmax), Min(tmin)) */
SELECT 
SELECT CAST((MAX(T1.tmax) - MIN(T1.tmin)) AS REAL) / MIN(T1.tmin) FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr WHERE T2.store_nbr = 11
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What was the difference of number of units sold in station number 1 and number 2 on year 2012? station 1 refers to station_nbr = 1; station 2 refers to station_nbr = 2; on year 2012 refers to substring (date, 1, 4) = '2012'; difference = Subtract (Sum(units where station_nbr = 1), Sum(units where station_nbr = 2)) */
SELECT 
SELECT SUM(CASE WHEN T1.station_nbr = 1 THEN units ELSE 0 END) - SUM(CASE WHEN T1.station_nbr = 2 THEN units ELSE 0 END) FROM relation AS T1 INNER JOIN sales_in_weather AS T2 ON T1.store_nbr = T2.store_nbr WHERE T2.`date` LIKE '%2012%'
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What was the average temperature difference between store number 18 and 19 on 16 September 2022? store number 18 refers to store_nbr = 18; store number 19 refers to store_nbr = 19; on 16 September 2022 refers to date = '2022-09-16'; average temperature difference = Subtract(tavg where store_nbr = 18, tavg where store_nbr = 19) */
SELECT 
SELECT SUM(CASE WHEN T1.store_nbr = 18 THEN T2.tavg ELSE 0 END) - SUM(CASE WHEN T1.store_nbr = 19 THEN T2.tavg ELSE 0 END) FROM relation AS T1 INNER JOIN weather AS T2 ON T1.station_nbr = T2.station_nbr WHERE T2.`date` = '2012-09-16'
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: How many units are being sold for item 1 when the average temperature is 83? item 1 refers to item_nbr = 1; when the average temperature is 83 refers to tavg = 83 */
SELECT 
SELECT SUM(units) FROM weather AS T1 INNER JOIN sales_in_weather AS T2 ON T1.`date` = T2.`date` INNER JOIN relation AS T3 ON T2.store_nbr = T3.store_nbr WHERE T2.item_nbr = 1 AND T1.tavg = 83
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What is the difference between the units sold for item 1 when the sunset was the earliest and the latest? item 1 refers to item_nbr = 1; when the sunset earliest refers to Min(sunset); latest sunset refers to Max(sunset); difference unit sold refers to Subtract(Sum(units where Min(sunset)), Sum(units where Max(sunset))) */
SELECT 
SELECT ( SELECT SUM(T2.units) AS sumunit FROM weather AS T1 INNER JOIN sales_in_weather AS T2 ON T1.`date` = T2.`date` INNER JOIN relation AS T3 ON T2.store_nbr = T3.store_nbr WHERE T2.item_nbr = 5 AND sunset IS NOT NULL GROUP BY T1.sunset ORDER BY T1.sunset LIMIT 1 ) - ( SELECT SUM(T2.units) AS sumunit FROM weather AS T1 INNER JOIN sales_in_weather AS T2 ON T1.`date` = T2.`date` INNER JOIN relation AS T3 ON T2.store_nbr = T3.store_nbr WHERE T2.item_nbr = 5 AND sunset IS NOT NULL GROUP BY T1.sunset ORDER BY T1.sunset DESC LIMIT 1 )
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What was the total unit sold for item 10 when the average temperature was below the median temperature? item 10 refers to item_nbr = 10; average temperature below median temperature refers to tavg < avg(tavg); total units refers to Sum(units) */
SELECT 
SELECT SUM(T5.units) FROM weather AS T4 INNER JOIN sales_in_weather AS T5 ON T4.`date` = T5.`date` INNER JOIN relation AS T6 ON T5.store_nbr = T6.store_nbr WHERE T5.item_nbr = 10 AND T4.tavg < ( SELECT AVG(T1.tavg) FROM weather AS T1 INNER JOIN sales_in_weather AS T2 ON T1.`date` = T2.`date` INNER JOIN relation AS T3 ON T2.store_nbr = T3.store_nbr WHERE T2.item_nbr = 10 )
/* Given the following database schema: */
CREATE TABLE sales_in_weather
(
    date      DATE,
    store_nbr INTEGER,
    item_nbr  INTEGER,
    units     INTEGER,
    primary key (store_nbr, date, item_nbr)
)

CREATE TABLE weather
(
    station_nbr INTEGER,
    date        DATE,
    tmax        INTEGER,
    tmin        INTEGER,
    tavg        INTEGER,
    depart      INTEGER,
    dewpoint    INTEGER,
    wetbulb     INTEGER,
    heat        INTEGER,
    cool        INTEGER,
    sunrise     TEXT,
    sunset      TEXT,
    codesum     TEXT,
    snowfall    REAL,
    preciptotal REAL,
    stnpressure REAL,
    sealevel    REAL,
    resultspeed REAL,
    resultdir   INTEGER,
    avgspeed    REAL,
    primary key (station_nbr, date)
)

CREATE TABLE relation
(
    store_nbr   INTEGER
            primary key,
    station_nbr INTEGER,
    foreign key (store_nbr) references sales_in_weather(store_nbr),
    foreign key (station_nbr) references weather(station_nbr)
)

/* Answer the following: What was the average temperature differences during May 2012 for store number 6 and 7? during May 2012 refers to SUBSTR(date, 1, 7) = '2012-05'; store number 6 refers to store_nbr = 6; store number 7 refers to store_nbr = 7; average temperature difference = Subtract (Divide (Sum(tavg), Count (date) where the store_nbr = 6), Divide (Sum(tavg), Count(date) where store_nbr = 7)) */
SELECT 
SELECT ( SELECT CAST(SUM(tavg) AS REAL) / COUNT(`date`) FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr AND T1.`date` LIKE '%2012-05%' AND T2.store_nbr = 6 ) - ( SELECT CAST(SUM(tavg) AS REAL) / COUNT(`date`) FROM weather AS T1 INNER JOIN relation AS T2 ON T1.station_nbr = T2.station_nbr WHERE T1.`date` LIKE '%2012-05%' AND T2.store_nbr = 7 )
/* 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 customers have never married? MARITAL_STATUS = 'Never-married'; */
SELECT 
SELECT COUNT(ID) FROM Customers WHERE 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: Among all the customers, how many of them are teenagers? teenager is a person aged between 13 and 19 years; */
SELECT 
SELECT COUNT(ID) FROM Customers WHERE 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: Please list the occupations of the customers with an education level of 11. education level of 11 refers to EDUCATIONNUM = 11; */
SELECT 
SELECT DISTINCT OCCUPATION FROM Customers WHERE EDUCATIONNUM = 11
/* 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 the first 60,000 customers' responses to the incentive mailing sent by the marketing department, how many of them are considered a true response? RESPONSE = 'true'; */
SELECT 
SELECT COUNT(REFID) custmoer_number 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: Among the customers over 30, how many of them are Machine-op-inspcts? over 30 refers to age > 30; OCCUPATION = 'Machine-op-inspct'; */
SELECT 
SELECT COUNT(ID) FROM Customers WHERE OCCUPATION = 'Machine-op-inspct' AND 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: How many female customers have an education level of over 11? education level of 11 refers to EDUCATIONNUM = 11; SEX = 'Female'; */
SELECT 
SELECT COUNT(ID) FROM Customers WHERE EDUCATIONNUM > 11 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: Of the first 60,000 customers who sent a true response to the incentive mailing sent by the marketing department, how many of them are female? RESPONSE = 'true'; SEX = 'Female'; */
SELECT 
SELECT COUNT(T1.ID) FROM Customers AS T1 INNER JOIN Mailings1_2 AS T2 ON T1.ID = T2.REFID WHERE T1.SEX = 'Female' 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: Please list the occupations of the customers over 40 and have sent a true response to the incentive mailing sent by the marketing department. over 40 refers to age > 40; RESPONSE = 'true'; */
SELECT 
SELECT DISTINCT T1.OCCUPATION FROM Customers AS T1 INNER JOIN Mailings1_2 AS T2 ON T1.ID = T2.REFID WHERE T1.age > 40 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: Among the male customers, how many of them come from a place with over 30,000 inhabitants? SEX = 'Male', over 30,000 inhabitants refer to NHABITANTS_K > 30; place refers to GEOID; */
SELECT 
SELECT COUNT(T1.GEOID) FROM Customers AS T1 INNER JOIN Demog AS T2 ON T1.GEOID = T2.GEOID WHERE T1.SEX = 'Male' AND T2.INHABITANTS_K > 30