Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the product type, name, and price for products supplied by supplier 3. [/INST]

Output: SELECT T2.product_type_code ,  T2.product_name ,  T2.product_price FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id  =  T2.product_id WHERE T1.supplier_id  =  3;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the distinct name of customers whose order status is Pending, in the order of customer id. [/INST]

Output: SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.order_status_code  =  "Pending" ORDER BY T2.customer_id;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the distinct names of customers with an order status of Pending, sorted by customer id? [/INST]

Output: SELECT DISTINCT T1.customer_name FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.order_status_code  =  "Pending" ORDER BY T2.customer_id;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Find the name and address of the customers who have both New and Pending orders. [/INST]

Output: SELECT T1.customer_name ,  T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.order_status_code  =  "New" INTERSECT SELECT T1.customer_name ,  T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.order_status_code  =  "Pending";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the names and addressed of customers who have both New and Pending orders? [/INST]

Output: SELECT T1.customer_name ,  T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.order_status_code  =  "New" INTERSECT SELECT T1.customer_name ,  T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id  =  T2.customer_id WHERE T2.order_status_code  =  "Pending";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return ids of all the products that are supplied by supplier id 2 and are more expensive than the average price of all products. [/INST]

Output: SELECT T1.product_id FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id  =  T2.product_id WHERE T1.supplier_id  =  2 AND T2.product_price  >  (SELECT avg(product_price) FROM products);


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the ids of products from the supplier with id 2, which are more expensive than the average price across all products? [/INST]

Output: SELECT T1.product_id FROM product_suppliers AS T1 JOIN products AS T2 ON T1.product_id  =  T2.product_id WHERE T1.supplier_id  =  2 AND T2.product_price  >  (SELECT avg(product_price) FROM products);


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What is the id and name of the department store that has both marketing and managing department? [/INST]

Output: SELECT T2.dept_store_id ,  T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id  =  T2.dept_store_id WHERE T1.department_name  =  "marketing" INTERSECT SELECT T2.dept_store_id ,  T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id  =  T2.dept_store_id WHERE T1.department_name  =  "managing";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the ids and names of department stores with both marketing and managing departments? [/INST]

Output: SELECT T2.dept_store_id ,  T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id  =  T2.dept_store_id WHERE T1.department_name  =  "marketing" INTERSECT SELECT T2.dept_store_id ,  T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id  =  T2.dept_store_id WHERE T1.department_name  =  "managing";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the ids of the two department store chains with the largest number of department stores? [/INST]

Output: SELECT dept_store_chain_id FROM department_stores GROUP BY dept_store_chain_id ORDER BY count(*) DESC LIMIT 2;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the ids of the two department store chains with the most department stores. [/INST]

Output: SELECT dept_store_chain_id FROM department_stores GROUP BY dept_store_chain_id ORDER BY count(*) DESC LIMIT 2;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What is the id of the department with the least number of staff? [/INST]

Output: SELECT department_id FROM staff_department_assignments GROUP BY department_id ORDER BY count(*) LIMIT 1;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the id of the department with the fewest staff assignments. [/INST]

Output: SELECT department_id FROM staff_department_assignments GROUP BY department_id ORDER BY count(*) LIMIT 1;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: For each product type, return the maximum and minimum price. [/INST]

Output: SELECT product_type_code ,  max(product_price) ,  min(product_price) FROM products GROUP BY product_type_code;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the maximum and minimum product prices for each product type? [/INST]

Output: SELECT product_type_code ,  max(product_price) ,  min(product_price) FROM products GROUP BY product_type_code;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Find the product type whose average price is higher than the average price of all products. [/INST]

Output: SELECT product_type_code FROM products GROUP BY product_type_code HAVING avg(product_price)  >  (SELECT avg(product_price) FROM products);


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What is the code of the product type with an average price higher than the average price of all products? [/INST]

Output: SELECT product_type_code FROM products GROUP BY product_type_code HAVING avg(product_price)  >  (SELECT avg(product_price) FROM products);


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Find the id and name of the staff who has been assigned for the shortest period. [/INST]

Output: SELECT T1.staff_id ,  T1.staff_name FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id  =  T2.staff_id ORDER BY date_assigned_to - date_assigned_from LIMIT 1;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What is the id and name of the staff who has been assigned for the least amount of time? [/INST]

Output: SELECT T1.staff_id ,  T1.staff_name FROM staff AS T1 JOIN Staff_Department_Assignments AS T2 ON T1.staff_id  =  T2.staff_id ORDER BY date_assigned_to - date_assigned_from LIMIT 1;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the names and ids of all products whose price is between 600 and 700. [/INST]

Output: SELECT product_name ,  product_id FROM products WHERE product_price BETWEEN 600 AND 700;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the names and ids of products costing between 600 and 700? [/INST]

Output: SELECT product_name ,  product_id FROM products WHERE product_price BETWEEN 600 AND 700;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Find the ids of all distinct customers who made order after some orders that were Cancelled. [/INST]

Output: SELECT DISTINCT customer_id FROM Customer_Orders WHERE order_date  >  (SELECT min(order_date) FROM Customer_Orders WHERE order_status_code  =  "Cancelled");


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the distinct ids of customers who made an order after any order that was Cancelled? [/INST]

Output: SELECT DISTINCT customer_id FROM Customer_Orders WHERE order_date  >  (SELECT min(order_date) FROM Customer_Orders WHERE order_status_code  =  "Cancelled");


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What is id of the staff who had a Staff Department Assignment earlier than any Clerical Staff? [/INST]

Output: SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to  <  (SELECT max(date_assigned_to) FROM Staff_Department_Assignments WHERE job_title_code  =  'Clerical Staff');


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the id of the staff whose Staff Department Assignment was earlier than that of any Clerical Staff. [/INST]

Output: SELECT staff_id FROM Staff_Department_Assignments WHERE date_assigned_to  <  (SELECT max(date_assigned_to) FROM Staff_Department_Assignments WHERE job_title_code  =  'Clerical Staff');


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the names and ids of customers whose address contains TN? [/INST]

Output: SELECT customer_name ,  customer_id FROM customers WHERE customer_address LIKE "%TN%";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the names and ids of customers who have TN in their address. [/INST]

Output: SELECT customer_name ,  customer_id FROM customers WHERE customer_address LIKE "%TN%";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the name and gender of the staff who was assigned in 2016. [/INST]

Output: SELECT T1.staff_name ,  T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id  =  T2.staff_id WHERE T2.date_assigned_from LIKE "2016%";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the names and genders of staff who were assigned in 2016? [/INST]

Output: SELECT T1.staff_name ,  T1.staff_gender FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id  =  T2.staff_id WHERE T2.date_assigned_from LIKE "2016%";


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: List the name of staff who has been assigned multiple jobs. [/INST]

Output: SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id  =  T2.staff_id GROUP BY T2.staff_id HAVING COUNT (*)  >  1;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the names of staff who have been assigned multiple jobs? [/INST]

Output: SELECT T1.staff_name FROM staff AS T1 JOIN staff_department_assignments AS T2 ON T1.staff_id  =  T2.staff_id GROUP BY T2.staff_id HAVING COUNT (*)  >  1;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: List the name and phone number of all suppliers in the alphabetical order of their addresses. [/INST]

Output: SELECT T1.supplier_name ,  T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id  =  T2.supplier_id JOIN addresses AS T3 ON T2.address_id  =  T3.address_id ORDER BY T3.address_details;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the names and phone numbers for all suppliers, sorted in alphabetical order of their addressed? [/INST]

Output: SELECT T1.supplier_name ,  T1.supplier_phone FROM Suppliers AS T1 JOIN supplier_addresses AS T2 ON T1.supplier_id  =  T2.supplier_id JOIN addresses AS T3 ON T2.address_id  =  T3.address_id ORDER BY T3.address_details;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: What are the phone numbers of all customers and suppliers. [/INST]

Output: SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers;


Input:
[INST] Here is a database schema:
Addresses :
address_id [ INT ] primary_key
address_details [ TEXT ]

Staff :
staff_id [ INT ] primary_key
staff_gender [ TEXT ]
staff_name [ TEXT ]

Suppliers :
supplier_id [ INT ] primary_key
supplier_name [ TEXT ]
supplier_phone [ TEXT ]

Department_Store_Chain :
dept_store_chain_id [ INT ] primary_key
dept_store_chain_name [ TEXT ]

Customers :
customer_id [ INT ] primary_key
payment_method_code [ TEXT ]
customer_code [ TEXT ]
customer_name [ TEXT ]
customer_address [ TEXT ]
customer_phone [ TEXT ]
customer_email [ TEXT ]

Products :
product_id [ INT ] primary_key
product_type_code [ TEXT ]
product_name [ TEXT ]
product_price [ INT ]

Supplier_Addresses :
supplier_id [ INT ] primary_key Supplier_Addresses.supplier_id = Suppliers.supplier_id
address_id [ INT ] Supplier_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Addresses :
customer_id [ INT ] primary_key Customer_Addresses.customer_id = Customers.customer_id
address_id [ INT ] Customer_Addresses.address_id = Addresses.address_id
date_from [ TEXT ]
date_to [ TEXT ]

Customer_Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Customer_Orders.customer_id = Customers.customer_id
order_status_code [ TEXT ]
order_date [ TEXT ]

Department_Stores :
dept_store_id [ INT ] primary_key
dept_store_chain_id [ INT ] Department_Stores.dept_store_chain_id = Department_Store_Chain.dept_store_chain_id
store_name [ TEXT ]
store_address [ TEXT ]
store_phone [ TEXT ]
store_email [ TEXT ]

Departments :
department_id [ INT ] primary_key
dept_store_id [ INT ] Departments.dept_store_id = Department_Stores.dept_store_id
department_name [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Customer_Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id

Product_Suppliers :
product_id [ INT ] primary_key Product_Suppliers.product_id = Products.product_id
supplier_id [ INT ] Product_Suppliers.supplier_id = Suppliers.supplier_id
date_supplied_from [ TEXT ]
date_supplied_to [ TEXT ]
total_amount_purchased [ TEXT ]
total_value_purchased [ INT ]

Staff_Department_Assignments :
staff_id [ INT ] primary_key Staff_Department_Assignments.staff_id = Staff.staff_id
department_id [ INT ] Staff_Department_Assignments.department_id = Departments.department_id
date_assigned_from [ TEXT ]
job_title_code [ TEXT ]
date_assigned_to [ TEXT ]

Please write me a SQL statement that answers the following question: Return the phone numbers for all customers and suppliers. [/INST]

Output: SELECT customer_phone FROM customers UNION SELECT supplier_phone FROM suppliers;