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 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%'
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)
);
