Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What is the invoice number and invoice date for the invoice with most number of transactions? [/INST]

Output: SELECT T2.invoice_number ,  T2.invoice_date FROM Financial_transactions AS T1 JOIN Invoices AS T2 ON T1.invoice_number  =  T2.invoice_number GROUP BY T1.invoice_number ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What is the invoice number and invoice date corresponding to the invoice with the greatest number of transactions? [/INST]

Output: SELECT T2.invoice_number ,  T2.invoice_date FROM Financial_transactions AS T1 JOIN Invoices AS T2 ON T1.invoice_number  =  T2.invoice_number GROUP BY T1.invoice_number ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: How many invoices do we have? [/INST]

Output: SELECT count(*) FROM Invoices;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Count the number of invoices. [/INST]

Output: SELECT count(*) FROM Invoices;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show invoice dates and order id and details for all invoices. [/INST]

Output: SELECT T1.invoice_date ,  T1.order_id ,  T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id  =  T2.order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What are the invoice dates, order ids, and order details for all invoices? [/INST]

Output: SELECT T1.invoice_date ,  T1.order_id ,  T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id  =  T2.order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show the order ids and the number of invoices for each order. [/INST]

Output: SELECT order_id ,  count(*) FROM Invoices GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: How many invoices correspond to each order id? [/INST]

Output: SELECT order_id ,  count(*) FROM Invoices GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What is the order id and order details for the order more than two invoices. [/INST]

Output: SELECT T2.order_id ,  T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id  =  T2.order_id GROUP BY T2.order_id HAVING count(*)  >  2;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Return the order ids and details for orderes with two or more invoices. [/INST]

Output: SELECT T2.order_id ,  T2.order_details FROM Invoices AS T1 JOIN Orders AS T2 ON T1.order_id  =  T2.order_id GROUP BY T2.order_id HAVING count(*)  >  2;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What is the customer last name, id and phone number with most number of orders? [/INST]

Output: SELECT T2.customer_last_name ,  T1.customer_id ,  T2.phone_number FROM Orders AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Return the last name, id and phone number of the customer who has made the greatest number of orders. [/INST]

Output: SELECT T2.customer_last_name ,  T1.customer_id ,  T2.phone_number FROM Orders AS T1 JOIN Customers AS T2 ON T1.customer_id  =  T2.customer_id GROUP BY T1.customer_id ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show all product names without an order. [/INST]

Output: SELECT product_name FROM Products EXCEPT SELECT T1.product_name FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id  =  T2.product_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What are the names of products that have never been ordered? [/INST]

Output: SELECT product_name FROM Products EXCEPT SELECT T1.product_name FROM Products AS T1 JOIN Order_items AS T2 ON T1.product_id  =  T2.product_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show all product names and the total quantity ordered for each product name. [/INST]

Output: SELECT T2.product_name ,  sum(T1.product_quantity) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id  =  T2.product_id GROUP BY T2.product_name;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What are the different product names, and what is the sum of quantity ordered for each product? [/INST]

Output: SELECT T2.product_name ,  sum(T1.product_quantity) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id  =  T2.product_id GROUP BY T2.product_name;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show the order ids and the number of items in each order. [/INST]

Output: SELECT order_id ,  count(*) FROM Order_items GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: How many order items correspond to each order id? [/INST]

Output: SELECT order_id ,  count(*) FROM Order_items GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show the product ids and the number of unique orders containing each product. [/INST]

Output: SELECT product_id ,  count(DISTINCT order_id) FROM Order_items GROUP BY product_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: How many distinct order ids correspond to each product? [/INST]

Output: SELECT product_id ,  count(DISTINCT order_id) FROM Order_items GROUP BY product_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show all product names and the number of customers having an order on each product. [/INST]

Output: SELECT T2.product_name ,  count(*) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id  =  T2.product_id JOIN Orders AS T3 ON T3.order_id  =  T1.order_id GROUP BY T2.product_name;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: What are teh names of the different products, as well as the number of customers who have ordered each product. [/INST]

Output: SELECT T2.product_name ,  count(*) FROM Order_items AS T1 JOIN Products AS T2 ON T1.product_id  =  T2.product_id JOIN Orders AS T3 ON T3.order_id  =  T1.order_id GROUP BY T2.product_name;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show order ids and the number of products in each order. [/INST]

Output: SELECT order_id ,  count(DISTINCT product_id) FROM Order_items GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: How many different products correspond to each order id? [/INST]

Output: SELECT order_id ,  count(DISTINCT product_id) FROM Order_items GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Show order ids and the total quantity in each order. [/INST]

Output: SELECT order_id ,  sum(product_quantity) FROM Order_items GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Give the order ids for all orders, as well as the total product quantity in each. [/INST]

Output: SELECT order_id ,  sum(product_quantity) FROM Order_items GROUP BY order_id;


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: How many products were not included in any order? [/INST]

Output: SELECT count(*) FROM products WHERE product_id NOT IN ( SELECT product_id FROM Order_items );


Input:
[INST] Here is a database schema:
Customers :
customer_id [ INT ] primary_key
customer_first_name [ TEXT ]
customer_middle_initial [ TEXT ]
customer_last_name [ TEXT ]
gender [ TEXT ]
email_address [ TEXT ]
login_name [ TEXT ]
login_password [ TEXT ]
phone_number [ TEXT ]
town_city [ TEXT ]
state_county_province [ TEXT ]
country [ TEXT ]

Orders :
order_id [ INT ] primary_key
customer_id [ INT ] Orders.customer_id = Customers.customer_id
date_order_placed [ TEXT ]
order_details [ TEXT ]

Invoices :
invoice_number [ INT ] primary_key
order_id [ INT ] Invoices.order_id = Orders.order_id
invoice_date [ TEXT ]

Accounts :
account_id [ INT ] primary_key
customer_id [ INT ] Accounts.customer_id = Customers.customer_id
date_account_opened [ TEXT ]
account_name [ TEXT ]
other_account_details [ TEXT ]

Product_Categories :
production_type_code [ TEXT ] primary_key
product_type_description [ TEXT ]
vat_rating [ INT ]

Products :
product_id [ INT ] primary_key
parent_product_id [ INT ]
production_type_code [ TEXT ] Products.production_type_code = Product_Categories.production_type_code
unit_price [ INT ]
product_name [ TEXT ]
product_color [ TEXT ]
product_size [ TEXT ]

Financial_Transactions :
transaction_id [ INT ]
account_id [ INT ] Financial_Transactions.account_id = Accounts.account_id
invoice_number [ INT ] Financial_Transactions.invoice_number = Invoices.invoice_number
transaction_type [ TEXT ]
transaction_date [ TEXT ]
transaction_amount [ INT ]
transaction_comment [ TEXT ]
other_transaction_details [ TEXT ]

Order_Items :
order_item_id [ INT ] primary_key
order_id [ INT ] Order_Items.order_id = Orders.order_id
product_id [ INT ] Order_Items.product_id = Products.product_id
product_quantity [ TEXT ]
other_order_item_details [ TEXT ]

Invoice_Line_Items :
order_item_id [ INT ] Invoice_Line_Items.order_item_id = Order_Items.order_item_id
invoice_number [ INT ] Invoice_Line_Items.invoice_number = Invoices.invoice_number
product_id [ INT ] Invoice_Line_Items.product_id = Products.product_id
product_title [ TEXT ]
product_quantity [ TEXT ]
product_price [ INT ]
derived_product_cost [ INT ]
derived_vat_payable [ INT ]
derived_total_cost [ INT ]

Please write me a SQL statement that answers the following question: Count the number of products that were never ordered. [/INST]

Output: SELECT count(*) FROM products WHERE product_id NOT IN ( SELECT product_id FROM Order_items );


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: How many churches opened before 1850 are there? [/INST]

Output: SELECT count(*) FROM Church WHERE Open_Date  <  1850;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the name, open date, and organizer for all churches. [/INST]

Output: SELECT name ,  open_date ,  organized_by FROM Church;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: List all church names in descending order of opening date. [/INST]

Output: SELECT name FROM church ORDER BY open_date DESC;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the opening year in whcih at least two churches opened. [/INST]

Output: SELECT open_date FROM church GROUP BY open_date HAVING count(*)  >=  2;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the organizer and name for churches that opened between 1830 and 1840. [/INST]

Output: SELECT organized_by ,  name FROM church WHERE open_date BETWEEN 1830 AND 1840;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show all opening years and the number of churches that opened in that year. [/INST]

Output: SELECT open_date ,  count(*) FROM church GROUP BY open_date;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the name and opening year for three churches that opened most recently. [/INST]

Output: SELECT name ,  open_date FROM church ORDER BY open_date DESC LIMIT 3;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: How many female people are older than 30 in our record? [/INST]

Output: SELECT count(*) FROM people WHERE is_male  =  'F' AND age  >  30;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the country where people older than 30 and younger than 25 are from. [/INST]

Output: SELECT country FROM people WHERE age  <  25 INTERSECT SELECT country FROM people WHERE age  >  30;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the minimum, maximum, and average age for all people. [/INST]

Output: SELECT min(age) ,  max(age) ,  avg(age) FROM people;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the name and country for all people whose age is smaller than the average. [/INST]

Output: SELECT name ,  country FROM people WHERE age  <  (SELECT avg(age) FROM people);


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the pair of male and female names in all weddings after year 2014 [/INST]

Output: SELECT T2.name ,  T3.name FROM wedding AS T1 JOIN people AS T2 ON T1.male_id  =  T2.people_id JOIN people AS T3 ON T1.female_id  =  T3.people_id WHERE T1.year  >  2014;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the name and age for all male people who don't have a wedding. [/INST]

Output: SELECT name ,  age FROM people WHERE is_male  =  'T' AND people_id NOT IN (SELECT male_id FROM wedding);


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show all church names except for those that had a wedding in year 2015. [/INST]

Output: SELECT name FROM church EXCEPT SELECT T1.name FROM church AS T1 JOIN wedding AS T2 ON T1.church_id  =  T2.church_id WHERE T2.year  =  2015;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show all church names that have hosted least two weddings. [/INST]

Output: SELECT T1.name FROM church AS T1 JOIN wedding AS T2 ON T1.church_id  =  T2.church_id GROUP BY T1.church_id HAVING count(*)  >=  2;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the names for all females from Canada having a wedding in year 2016. [/INST]

Output: SELECT T2.name FROM wedding AS T1 JOIN people AS T2 ON T1.female_id  =  T2.people_id WHERE T1.year  =  2016 AND T2.is_male  =  'F' AND T2.country  =  'Canada';


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: How many weddings are there in year 2016? [/INST]

Output: SELECT count(*) FROM wedding WHERE YEAR  =  2016;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show the church names for the weddings of all people older than 30. [/INST]

Output: SELECT T4.name FROM wedding AS T1 JOIN people AS T2 ON T1.male_id  =  T2.people_id JOIN people AS T3 ON T1.female_id  =  T3.people_id JOIN church AS T4 ON T4.church_id  =  T1.church_id WHERE T2.age  >  30 OR T3.age  >  30;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: Show all countries and the number of people from each country. [/INST]

Output: SELECT country ,  count(*) FROM people GROUP BY country;


Input:
[INST] Here is a database schema:
people :
People_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Is_Male [ TEXT ]
Age [ INT ]

church :
Church_ID [ INT ] primary_key
Name [ TEXT ]
Organized_by [ TEXT ]
Open_Date [ INT ]
Continuation_of [ TEXT ]

wedding :
Church_ID [ INT ] primary_key wedding.Church_ID = church.Church_ID
Male_ID [ INT ] wedding.Male_ID = people.People_ID
Female_ID [ INT ] wedding.Female_ID = people.People_ID
Year [ INT ]

Please write me a SQL statement that answers the following question: How many churches have a wedding in year 2016? [/INST]

Output: SELECT COUNT (DISTINCT church_id) FROM wedding WHERE YEAR  =  2016;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: How many artists do we have? [/INST]

Output: SELECT count(*) FROM artist;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Count the number of artists. [/INST]

Output: SELECT count(*) FROM artist;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Show all artist name, age, and country ordered by the yeared they joined. [/INST]

Output: SELECT name ,  age ,  country FROM artist ORDER BY Year_Join;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What are the names, ages, and countries of artists, sorted by the year they joined? [/INST]

Output: SELECT name ,  age ,  country FROM artist ORDER BY Year_Join;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What are all distinct country for artists? [/INST]

Output: SELECT DISTINCT country FROM artist;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Return the different countries for artists. [/INST]

Output: SELECT DISTINCT country FROM artist;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Show all artist names and the year joined who are not from United States. [/INST]

Output: SELECT name ,  year_join FROM artist WHERE country != 'United States';


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What are the names and year of joining for artists that do not have the country "United States"? [/INST]

Output: SELECT name ,  year_join FROM artist WHERE country != 'United States';


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: How many artists are above age 46 and joined after 1990? [/INST]

Output: SELECT count(*) FROM artist WHERE age  >  46 AND year_join  >  1990;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Count the number of artists who are older than 46 and joined after 1990. [/INST]

Output: SELECT count(*) FROM artist WHERE age  >  46 AND year_join  >  1990;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What is the average and minimum age of all artists from United States. [/INST]

Output: SELECT avg(age) ,  min(age) FROM artist WHERE country  =  'United States';


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Return the average and minimum ages across artists from the United States. [/INST]

Output: SELECT avg(age) ,  min(age) FROM artist WHERE country  =  'United States';


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What is the name of the artist who joined latest? [/INST]

Output: SELECT name FROM artist ORDER BY year_join DESC LIMIT 1;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Return the name of the artist who has the latest join year. [/INST]

Output: SELECT name FROM artist ORDER BY year_join DESC LIMIT 1;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: How many exhibition are there in year 2005 or after? [/INST]

Output: SELECT count(*) FROM exhibition WHERE YEAR  >=  2005;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Count the number of exhibitions that happened in or after 2005. [/INST]

Output: SELECT count(*) FROM exhibition WHERE YEAR  >=  2005;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Show theme and year for all exhibitions with ticket prices lower than 15. [/INST]

Output: SELECT theme ,  YEAR FROM exhibition WHERE ticket_price  <  15;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What are the theme and year for all exhibitions that have a ticket price under 15? [/INST]

Output: SELECT theme ,  YEAR FROM exhibition WHERE ticket_price  <  15;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Show all artist names and the number of exhibitions for each artist. [/INST]

Output: SELECT T2.name ,  count(*) FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id  =  T2.artist_id GROUP BY T1.artist_id;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: How many exhibitions has each artist had? [/INST]

Output: SELECT T2.name ,  count(*) FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id  =  T2.artist_id GROUP BY T1.artist_id;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What is the name and country for the artist with most number of exhibitions? [/INST]

Output: SELECT T2.name , T2.country FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id  =  T2.artist_id GROUP BY T1.artist_id ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Return the name and country corresponding to the artist who has had the most exhibitions. [/INST]

Output: SELECT T2.name , T2.country FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id  =  T2.artist_id GROUP BY T1.artist_id ORDER BY count(*) DESC LIMIT 1;


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: Show names for artists without any exhibition. [/INST]

Output: SELECT name FROM artist WHERE artist_id NOT IN (SELECT artist_id FROM exhibition);


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What are the names of artists that have not had any exhibitions? [/INST]

Output: SELECT name FROM artist WHERE artist_id NOT IN (SELECT artist_id FROM exhibition);


Input:
[INST] Here is a database schema:
artist :
Artist_ID [ INT ] primary_key
Name [ TEXT ]
Country [ TEXT ]
Year_Join [ INT ]
Age [ INT ]

exhibition :
Exhibition_ID [ INT ] primary_key
Year [ INT ]
Theme [ TEXT ]
Artist_ID [ INT ] exhibition.Artist_ID = artist.Artist_ID
Ticket_Price [ INT ]

exhibition_record :
Exhibition_ID [ INT ] primary_key exhibition_record.Exhibition_ID = exhibition.Exhibition_ID
Date [ TEXT ]
Attendance [ INT ]

Please write me a SQL statement that answers the following question: What is the theme and artist name for the exhibition with a ticket price higher than the average? [/INST]

Output: SELECT T1.theme ,  T2.name FROM exhibition AS T1 JOIN artist AS T2 ON T1.artist_id  =  T2.artist_id WHERE T1.ticket_price  >  (SELECT avg(ticket_price) FROM exhibition);