Database schema:
CREATE TABLE customers (
  Id NUMBER PRIMARY KEY,
  LastName TEXT,
  FirstName TEXT
);
CREATE TABLE goods (
  Id TEXT PRIMARY KEY,
  Flavor TEXT,
  Food TEXT,
  Price NUMBER
);
CREATE TABLE items (
  Receipt NUMBER PRIMARY KEY,
  Ordinal NUMBER,
  Item TEXT,
  FOREIGN KEY (Item) REFERENCES goods(Id)
);
CREATE TABLE receipts (
  ReceiptNumber NUMBER PRIMARY KEY,
  Date TEXT,
  CustomerId NUMBER,
  FOREIGN KEY (CustomerId) REFERENCES customers(Id)
);

Question: Count the number of types of cake this bakery sells.
SQL: SELECT count(*) FROM goods WHERE food  =  "Cake"

Question: What are the ids of Cookie and Cake that cost between 3 and 7 dollars.
SQL: SELECT id FROM goods WHERE food  =  "Cookie" OR food  =  "Cake" AND price BETWEEN 3 AND 7

Question: Give the average price for each food type.
SQL: SELECT avg(price) ,  food FROM goods GROUP BY food

Question: What are the receipt numbers for which either an apple flavor pie was purchased or the customer with id 12 shopped?
SQL: SELECT T1.receipt FROM items AS T1 JOIN goods AS T2 ON T1.item  =  T2.id WHERE T2.flavor  =  "Apple" AND T2.food  =  "Pie" UNION SELECT ReceiptNumber FROM receipts WHERE CustomerId  =  12

Question: Find the first name and last name of a customer who visited on the earliest date.
SQL: SELECT T1.FirstName ,  T1.LastName FROM customers AS T1 JOIN receipts AS T2 ON T1.id  =  T2.CustomerId ORDER BY T2.date LIMIT 1

Question: What is the cheapest good with cheese flavor?
SQL: SELECT min(price) FROM goods WHERE flavor  =  "Cheese"

Question: What are the ids of customers who have spent over 150 dollars in total?
SQL: SELECT T3.CustomerId FROM goods AS T1 JOIN items AS T2 ON T1.id  =  T2.item JOIN receipts AS T3 ON T2.receipt  =  T3.ReceiptNumber GROUP BY T3.CustomerId HAVING sum(T1.price)  >  150

Question: What are the ids of goods whose price is above twice the average price of all goods?
SQL: SELECT id FROM goods WHERE price  >  (SELECT avg(price) FROM goods)

Question: What are the maximum, minimum, and average prices of goods of each flavor, ordered by flavor?
SQL: SELECT max(price) ,  min(price) ,  avg(price) ,  flavor FROM goods GROUP BY flavor ORDER BY flavor

Question: List all the flavors of Croissant available in this bakery.
SQL: SELECT flavor FROM goods WHERE food  =  "Croissant"

Question: Find the receipt numbers where both Cake and Cookie were bought.
SQL: SELECT T1.receipt FROM items AS T1 JOIN goods AS T2 ON T1.item  =  T2.id WHERE T2.food  =  "Cake" INTERSECT SELECT T1.receipt FROM items AS T1 JOIN goods AS T2 ON T1.item  =  T2.id WHERE T2.food  =  "Cookie"

Question: How many types of Cake does this bakery sell?
SQL: SELECT count(*) FROM goods WHERE food  =  "Cake"

Question: Find all the items that have chocolate flavor but were not bought more than 10 times.
SQL: SELECT DISTINCT T1.item FROM items AS T1 JOIN goods AS T2 ON T1.item  =  T2.id WHERE T2.flavor  =  "Chocolate" GROUP BY item HAVING count(*)  <=  10

Question: What are the receipt numbers for instances where both cakes and cookies were purchased?
SQL: SELECT T1.receipt FROM items AS T1 JOIN goods AS T2 ON T1.item  =  T2.id WHERE T2.food  =  "Cake" INTERSECT SELECT T1.receipt FROM items AS T1 JOIN goods AS T2 ON T1.item  =  T2.id WHERE T2.food  =  "Cookie"

Question: What are all the flavors of croissant?
SQL: SELECT flavor FROM goods WHERE food  =  "Croissant"

Question: What is the full name of the customer who visited on the earliest date?
SQL: SELECT T1.FirstName ,  T1.LastName FROM customers AS T1 JOIN receipts AS T2 ON T1.id  =  T2.CustomerId ORDER BY T2.date LIMIT 1

Question: Find all receipts which either has the earliest date or has a good with price above 10.
SQL: SELECT T1.Receipt FROM items AS T1 JOIN goods AS T2 ON T1.item  =  T2.id WHERE T2.price  >  10 UNION SELECT ReceiptNumber FROM receipts WHERE date  =  (SELECT date FROM receipts ORDER BY date LIMIT 1)

Question: List distinct receipt numbers for which someone bought a good that costs more than 13 dollars.
SQL: SELECT DISTINCT T1.ReceiptNumber FROM receipts AS T1 JOIN items AS T2 ON T1.ReceiptNumber  =  T2.receipt JOIN goods AS T3 ON T2.item  =  T3.id WHERE T3.price  >  13

Question: List the last names of all customers in an alphabetical order.
SQL: SELECT DISTINCT LastName FROM customers ORDER BY LastName

Question: Order the distinct good ids.
SQL: SELECT DISTINCT id FROM goods ORDER BY id

Question: How many cusomters visited on each date?
SQL: SELECT date ,  COUNT (DISTINCT CustomerId) FROM receipts GROUP BY date

Question: Give the customer id of the customer that made the most purchases, as well as the number of purchases made.
SQL: SELECT CustomerId ,  count(*) FROM receipts GROUP BY CustomerId ORDER BY count(*) DESC LIMIT 1

Question: For each type of food, tell me how many customers have ever bought it.
SQL: SELECT T1.food ,  count(DISTINCT T3.CustomerId) FROM goods AS T1 JOIN items AS T2 ON T1.Id  =  T2.Item JOIN receipts AS T3 ON T2.Receipt  =  T3.ReceiptNumber GROUP BY T1.food

Question: What are the ids with apple flavor?
SQL: SELECT id FROM goods WHERE flavor  =  "Apple"