/* Given the following database schema: */
CREATE TABLE customers
(
    CustomerID            INTEGER
            primary key,
    First                 TEXT,
    Last                  TEXT,
    StreetAddress         TEXT,
    City                  TEXT,
    State                 TEXT,
    ZipCode               INTEGER,
    Email                 TEXT,
    PhoneNumber           TEXT,
    FirstPurchaseDate     DATE,
    SubscribedToEmailList TEXT,
    Gender                TEXT
)

CREATE TABLE geolocation
(
    LocationID INTEGER
            primary key,
    Latitude   REAL,
    Longitude  REAL,
    foreign key (LocationID) references location(LocationID)
)

CREATE TABLE location
(
    LocationID    INTEGER
            primary key,
    LocationName  TEXT,
    StreetAddress TEXT,
    City          TEXT,
    State         TEXT,
    ZipCode       INTEGER,
    foreign key (LocationID) references geolocation(LocationID)
)

CREATE TABLE rootbeerbrand
(
    BrandID             INTEGER
            primary key,
    BrandName           TEXT,
    FirstBrewedYear     INTEGER,
    BreweryName         TEXT,
    City                TEXT,
    State               TEXT,
    Country             TEXT,
    Description         TEXT,
    CaneSugar           TEXT,
    CornSyrup           TEXT,
    Honey               TEXT,
    ArtificialSweetener TEXT,
    Caffeinated         TEXT,
    Alcoholic           TEXT,
    AvailableInCans     TEXT,
    AvailableInBottles  TEXT,
    AvailableInKegs     TEXT,
    Website             TEXT,
    FacebookPage        TEXT,
    Twitter             TEXT,
    WholesaleCost       REAL,
    CurrentRetailPrice  REAL
)

CREATE TABLE rootbeer
(
    RootBeerID    INTEGER
            primary key,
    BrandID       INTEGER,
    ContainerType TEXT,
    LocationID    INTEGER,
    PurchaseDate  DATE,
    foreign key (LocationID) references geolocation(LocationID),
    foreign key (LocationID) references location(LocationID),
    foreign key (BrandID) references rootbeerbrand(BrandID)
)

CREATE TABLE rootbeerreview
(
    CustomerID INTEGER,
    BrandID    INTEGER,
    StarRating INTEGER,
    ReviewDate DATE,
    Review     TEXT,
    primary key (CustomerID, BrandID),
    foreign key (CustomerID) references customers(CustomerID),
    foreign key (BrandID) references rootbeerbrand(BrandID)
)

CREATE TABLE "transaction"
(
    TransactionID    INTEGER
            primary key,
    CreditCardNumber INTEGER,
    CustomerID       INTEGER,
    TransactionDate  DATE,
    CreditCardType   TEXT,
    LocationID       INTEGER,
    RootBeerID       INTEGER,
    PurchasePrice    REAL,
    foreign key (CustomerID) references customers(CustomerID),
    foreign key (LocationID) references location(LocationID),
    foreign key (RootBeerID) references rootbeer(RootBeerID)
)

/* Answer the following: Calculate the total purchases made by customers using their Visa credit cards in the Sac State American River Courtyard between 6/3/2014 and 11/27/2015. total purchases = SUM(PurchasePrice); Visa credit card refers to CreditCardType = 'Visa'; Sac State American River Courtyard refers to LocationName = 'Sac State American River Courtyard'; between 6/3/2014 and 11/27/2015 refers to TransactionDate BETWEEN '2014-06-03' AND '2015-11-27'; */
SELECT 
SELECT SUM(T1.PurchasePrice) FROM `transaction` AS T1 INNER JOIN location AS T2 ON T1.LocationID = T2.LocationID WHERE T2.LocationName = 'Sac State American River Courtyard' AND T1.CreditCardType = 'Visa' AND T1.TransactionDate BETWEEN '2014-06-03' AND '2015-11-27'