[User] What are the name, tax_rate, quantity of each department?

[Assistant] SELECT name, tax_rate, quantity FROM healthcare.departments;

[User] Show me departments with description LIKE 'A%'.

[Assistant] SELECT name, tax_rate, quantity FROM healthcare.departments WHERE description LIKE 'A%';

[User] Only show the top 10 results.

[Assistant] SELECT name, tax_rate, quantity FROM healthcare.departments WHERE description LIKE 'A%' LIMIT 10;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.departments (
  product_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  created_at date,
  thumbnail_url varchar,
  tax_rate character varying(128) NOT NULL,
  quantity character varying(64),
  reserved character varying(64) NOT NULL,
  description text,
  name char,
  patient_id text NOT NULL -- reference to patients.employee_id,
  FOREIGN KEY (patient_id) REFERENCES patients(employee_id)
)

CREATE TABLE healthcare.patients (
  employee_id varchar PRIMARY KEY -- unique identifier,
  last_active timestamp without time zone,
  salt char,
  gender character varying(64) NOT NULL,
  display_name character varying(64) NOT NULL,
  nationality character varying(128) NOT NULL,
  age character varying(256),
  department_id integer -- reference to departments.product_id,
  FOREIGN KEY (department_id) REFERENCES departments(product_id)
)

[User] Get patient_id, updated_at, tax_rate from all departments.

[Assistant] SELECT patient_id, updated_at, tax_rate FROM healthcare.departments;

[User] Show me tax_rate, updated_at, gender, salt from departments and their related patients.

[Assistant] SELECT patient_id, updated_at, tax_rate, patients.gender, patients.salt FROM healthcare.departments JOIN healthcare.patients ON departments.patient_id = patients.employee_id;

[User] Get the distribution of departments across different updated_at values.

[Assistant] SELECT updated_at, COUNT(*) AS count FROM healthcare.departments GROUP BY updated_at ORDER BY count DESC;


[User] Retrieve all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] Find patients modified within the last hour.

[Assistant] SELECT * FROM healthcare.patients WHERE last_active >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Group patients by age and show the sum of department_id.

[Assistant] SELECT age, SUM(department_id) AS sum_department_id FROM healthcare.patients GROUP BY age;


[User] Retrieve created_at, patient_id, tax_rate for every department.

[Assistant] SELECT created_at, patient_id, tax_rate FROM healthcare.departments;

[User] Show me departments that were from 2023.

[Assistant] SELECT created_at, patient_id, tax_rate FROM healthcare.departments WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Show me count of quantity grouped by updated_at for departments.

[Assistant] SELECT updated_at, COUNT(quantity) AS count_quantity FROM healthcare.departments GROUP BY updated_at;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.loans (
  id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp without time zone,
  currency character varying(64),
  payee_id character varying(64) -- identifier for payee,
  customer_id character varying(64) NOT NULL -- identifier for customer,
  category character varying(64)
)

CREATE TABLE finance.customers (
  user_id integer PRIMARY KEY -- unique identifier,
  created_at date,
  gender text,
  status character varying(64),
  birth_date timestamp,
  first_name character varying(64),
  timezone varchar NOT NULL,
  full_name character varying(64),
  api_key character varying(128)
)

[User] Display all loans.

[Assistant] SELECT * FROM finance.loans;

[User] List loans with dates created after December 1st, 2023.

[Assistant] SELECT * FROM finance.loans WHERE updated_at > '2023-12-01';

[User] How many loans are there per currency?

[Assistant] SELECT currency, COUNT(*) AS count FROM finance.loans GROUP BY currency ORDER BY count DESC;


[User] Show me created_at, gender, timezone for all customers.

[Assistant] SELECT created_at, gender, timezone FROM finance.customers;

[User] Arrange the results with gender in descending order.

[Assistant] SELECT created_at, gender, timezone FROM finance.customers ORDER BY gender DESC;

[User] Get the distribution of customers across different timezone values.

[Assistant] SELECT timezone, COUNT(*) AS count FROM finance.customers GROUP BY timezone ORDER BY count DESC;


[User] List api_key, first_name, timezone from customers.

[Assistant] SELECT api_key, first_name, timezone FROM finance.customers;

[User] Sort the results by api_key ascending.

[Assistant] SELECT api_key, first_name, timezone FROM finance.customers ORDER BY api_key ASC;

[User] Return just 25 rows.

[Assistant] SELECT api_key, first_name, timezone FROM finance.customers ORDER BY api_key ASC LIMIT 25;


[User] Get all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Can you order these by customer_id ascending?

[Assistant] SELECT * FROM finance.loans ORDER BY customer_id ASC;

[User] Return just 20 rows.

[Assistant] SELECT * FROM finance.loans ORDER BY customer_id ASC LIMIT 20;


[User] Retrieve payee_id, customer_id, category for every loan.

[Assistant] SELECT payee_id, customer_id, category FROM finance.loans;

[User] Show the results sorted by id descending.

[Assistant] SELECT payee_id, customer_id, category FROM finance.loans ORDER BY id DESC;

[User] Get the distribution of loans across different payee_id values.

[Assistant] SELECT payee_id, COUNT(*) AS count FROM finance.loans GROUP BY payee_id ORDER BY count DESC;


[User] Display all customers.

[Assistant] SELECT * FROM finance.customers;

[User] Show me customers that were created after December 1st, 2023.

[Assistant] SELECT * FROM finance.customers WHERE created_at > '2023-12-01';

[User] Count the number of customers in each timezone category.

[Assistant] SELECT timezone, COUNT(*) AS count FROM finance.customers GROUP BY timezone ORDER BY count DESC;


[User] List category, id, currency from loans.

[Assistant] SELECT category, id, currency FROM finance.loans;

[User] Show me loans that were from 2023.

[Assistant] SELECT category, id, currency FROM finance.loans WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Arrange the results with customer_id in ascending order.

[Assistant] SELECT category, id, currency FROM finance.loans WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY customer_id ASC;


[User] List all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Arrange the results with id in ascending order.

[Assistant] SELECT * FROM finance.loans ORDER BY id ASC;

[User] Sort the results by category ascending.

[Assistant] SELECT * FROM finance.loans ORDER BY category ASC;


[User] List all customers.

[Assistant] SELECT * FROM finance.customers;

[User] Get customers that match full_name LIKE 'A%'.

[Assistant] SELECT * FROM finance.customers WHERE full_name LIKE 'A%';

[User] Restrict the output to 5 items.

[Assistant] SELECT * FROM finance.customers WHERE full_name LIKE 'A%' LIMIT 5;


[User] Show me all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Arrange the results with category in ascending order.

[Assistant] SELECT * FROM finance.loans ORDER BY category ASC;

[User] Show me the count of loans grouped by payee_id.

[Assistant] SELECT payee_id, COUNT(*) AS count FROM finance.loans GROUP BY payee_id ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.audits (
  item_id integer PRIMARY KEY -- unique identifier,
  updated_at date,
  description char,
  backorder character varying(256),
  available varchar,
  currency char NOT NULL,
  featured_rank character varying(128),
  transaction_id text NOT NULL -- reference to transactions.id,
  FOREIGN KEY (transaction_id) REFERENCES transactions(id)
)

CREATE TABLE finance.transactions (
  id varchar PRIMARY KEY -- unique identifier,
  completed_at timestamp,
  amount numeric,
  payment_method character varying(128),
  buyer_id varchar,
  exchange_rate text NOT NULL
)

[User] Get all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Show the results sorted by featured_rank descending.

[Assistant] SELECT * FROM finance.audits ORDER BY featured_rank DESC;

[User] Only show the top 20 results.

[Assistant] SELECT * FROM finance.audits ORDER BY featured_rank DESC LIMIT 20;


[User] List transaction_id, backorder, featured_rank from audits.

[Assistant] SELECT transaction_id, backorder, featured_rank FROM finance.audits;

[User] Arrange the results with available in descending order.

[Assistant] SELECT transaction_id, backorder, featured_rank FROM finance.audits ORDER BY available DESC;

[User] Show me sum of currency grouped by description for audits.

[Assistant] SELECT description, SUM(currency) AS sum_currency FROM finance.audits GROUP BY description;


[User] Get description, featured_rank, available from all audits.

[Assistant] SELECT description, featured_rank, available FROM finance.audits;

[User] Retrieve audits where the date is from last week.

[Assistant] SELECT description, featured_rank, available FROM finance.audits WHERE updated_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Restrict the output to 25 items.

[Assistant] SELECT description, featured_rank, available FROM finance.audits WHERE updated_at >= CURRENT_DATE - INTERVAL '7 days' LIMIT 25;


[User] Get description, transaction_id, featured_rank from all audits.

[Assistant] SELECT description, transaction_id, featured_rank FROM finance.audits;

[User] Show the results sorted by updated_at descending.

[Assistant] SELECT description, transaction_id, featured_rank FROM finance.audits ORDER BY updated_at DESC;

[User] Show me the count of audits grouped by available.

[Assistant] SELECT available, COUNT(*) AS count FROM finance.audits GROUP BY available ORDER BY count DESC;


[User] Show me description, transaction_id, updated_at for all audits.

[Assistant] SELECT description, transaction_id, updated_at FROM finance.audits;

[User] Sort the results by updated_at ascending.

[Assistant] SELECT description, transaction_id, updated_at FROM finance.audits ORDER BY updated_at ASC;

[User] Order the output by currency descending.

[Assistant] SELECT description, transaction_id, updated_at FROM finance.audits ORDER BY currency DESC;


[User] List all audits.

[Assistant] SELECT * FROM finance.audits;

[User] List audits with dates created yesterday.

[Assistant] SELECT * FROM finance.audits WHERE updated_at = CURRENT_DATE - INTERVAL '1 day';

[User] Calculate min of currency for each backorder in audits.

[Assistant] SELECT backorder, MIN(currency) AS min_currency FROM finance.audits GROUP BY backorder;


[User] Show me available, updated_at, backorder for all audits.

[Assistant] SELECT available, updated_at, backorder FROM finance.audits;

[User] List audits with dates between January and March.

[Assistant] SELECT available, updated_at, backorder FROM finance.audits WHERE updated_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Calculate min of updated_at for each backorder in audits.

[Assistant] SELECT backorder, MIN(updated_at) AS min_updated_at FROM finance.audits GROUP BY backorder;


[User] Get currency, description, updated_at from all audits.

[Assistant] SELECT currency, description, updated_at FROM finance.audits;

[User] Get all audits modified within the last hour.

[Assistant] SELECT currency, description, updated_at FROM finance.audits WHERE updated_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Return just 50 rows.

[Assistant] SELECT currency, description, updated_at FROM finance.audits WHERE updated_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 50;


[User] Retrieve available, currency, backorder for every audit.

[Assistant] SELECT available, currency, backorder FROM finance.audits;

[User] Get audits that match available LIKE 'A%'.

[Assistant] SELECT available, currency, backorder FROM finance.audits WHERE available LIKE 'A%';

[User] Count the number of audits in each featured_rank category.

[Assistant] SELECT featured_rank, COUNT(*) AS count FROM finance.audits GROUP BY featured_rank ORDER BY count DESC;


[User] Show me featured_rank, available, description for all audits.

[Assistant] SELECT featured_rank, available, description FROM finance.audits;

[User] Show the results sorted by description ascending.

[Assistant] SELECT featured_rank, available, description FROM finance.audits ORDER BY description ASC;

[User] Show only 50 records.

[Assistant] SELECT featured_rank, available, description FROM finance.audits ORDER BY description ASC LIMIT 50;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE marketing.goods (
  product_id text PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  description varchar,
  available character varying(128),
  video_url character varying(256) NOT NULL -- identifier for video_url,
  title char,
  popularity_score varchar,
  purchase_id integer -- reference to purchases.order_id,
  store_id integer -- reference to stores.store_id,
  FOREIGN KEY (purchase_id) REFERENCES purchases(order_id),
  FOREIGN KEY (store_id) REFERENCES stores(store_id)
)

CREATE TABLE marketing.purchases (
  order_id integer PRIMARY KEY -- unique identifier,
  processed_at date,
  completed_at timestamp,
  buyer_id character varying(64),
  exchange_rate character varying(128) NOT NULL,
  total integer,
  currency char,
  store_id integer NOT NULL -- reference to stores.store_id,
  FOREIGN KEY (store_id) REFERENCES stores(store_id)
)

CREATE TABLE marketing.stores (
  store_id integer PRIMARY KEY -- unique identifier,
  last_inspected date,
  updated_at date,
  capacity character varying(64) NOT NULL,
  timezone character varying(64),
  latitude character varying(128) NOT NULL,
  location_lat character varying(256),
  zip_code character varying(256),
  purchase_id integer -- reference to purchases.order_id,
  FOREIGN KEY (purchase_id) REFERENCES purchases(order_id)
)

[User] What are the updated_at, last_inspected, zip_code of each store?

[Assistant] SELECT updated_at, last_inspected, zip_code FROM marketing.stores;

[User] List stores that have zip_code LIKE 'A%'.

[Assistant] SELECT updated_at, last_inspected, zip_code FROM marketing.stores WHERE zip_code LIKE 'A%';

[User] Show the results sorted by last_inspected descending.

[Assistant] SELECT updated_at, last_inspected, zip_code FROM marketing.stores WHERE zip_code LIKE 'A%' ORDER BY last_inspected DESC;


[User] Display all stores.

[Assistant] SELECT * FROM marketing.stores;

[User] Can you order these by last_inspected descending?

[Assistant] SELECT * FROM marketing.stores ORDER BY last_inspected DESC;

[User] Show me count of capacity grouped by zip_code for stores.

[Assistant] SELECT zip_code, COUNT(capacity) AS count_capacity FROM marketing.stores GROUP BY zip_code;


[User] Display all stores.

[Assistant] SELECT * FROM marketing.stores;

[User] Sort the results by latitude ascending.

[Assistant] SELECT * FROM marketing.stores ORDER BY latitude ASC;

[User] Show the results sorted by updated_at ascending.

[Assistant] SELECT * FROM marketing.stores ORDER BY updated_at ASC;


[User] List last_inspected, purchase_id, updated_at from stores.

[Assistant] SELECT last_inspected, purchase_id, updated_at FROM marketing.stores;

[User] Show me stores with timezone LIKE 'A%'.

[Assistant] SELECT last_inspected, purchase_id, updated_at FROM marketing.stores WHERE timezone LIKE 'A%';

[User] Restrict the output to 100 items.

[Assistant] SELECT last_inspected, purchase_id, updated_at FROM marketing.stores WHERE timezone LIKE 'A%' LIMIT 100;


[User] Display all goods.

[Assistant] SELECT * FROM marketing.goods;

[User] Show the results sorted by popularity_score ascending.

[Assistant] SELECT * FROM marketing.goods ORDER BY popularity_score ASC;

[User] Only show the top 50 results.

[Assistant] SELECT * FROM marketing.goods ORDER BY popularity_score ASC LIMIT 50;


[User] Show me all stores.

[Assistant] SELECT * FROM marketing.stores;

[User] Retrieve purchase_id, updated_at, completed_at, processed_at showing the relationship between stores and purchases.

[Assistant] SELECT *, purchases.completed_at, purchases.processed_at FROM marketing.stores JOIN marketing.purchases ON stores.purchase_id = purchases.order_id;

[User] What is the average purchase_id for each last_inspected in stores?

[Assistant] SELECT last_inspected, AVERAGE(purchase_id) AS average_purchase_id FROM marketing.stores GROUP BY last_inspected;


[User] List all stores.

[Assistant] SELECT * FROM marketing.stores;

[User] Get all stores created in the last 30 days.

[Assistant] SELECT * FROM marketing.stores WHERE last_inspected >= CURRENT_DATE - INTERVAL '30 days';

[User] Return just 10 rows.

[Assistant] SELECT * FROM marketing.stores WHERE last_inspected >= CURRENT_DATE - INTERVAL '30 days' LIMIT 10;


[User] Get all goods.

[Assistant] SELECT * FROM marketing.goods;

[User] List goods that have video_url LIKE 'A%'.

[Assistant] SELECT * FROM marketing.goods WHERE video_url LIKE 'A%';

[User] Only show the top 10 results.

[Assistant] SELECT * FROM marketing.goods WHERE video_url LIKE 'A%' LIMIT 10;


[User] Get all purchases.

[Assistant] SELECT * FROM marketing.purchases;

[User] Retrieve purchases where total > 85.

[Assistant] SELECT * FROM marketing.purchases WHERE total > 85;

[User] Show only 100 records.

[Assistant] SELECT * FROM marketing.purchases WHERE total > 85 LIMIT 100;


[User] Get capacity, zip_code, purchase_id from all stores.

[Assistant] SELECT capacity, zip_code, purchase_id FROM marketing.stores;

[User] Sort the results by location_lat descending.

[Assistant] SELECT capacity, zip_code, purchase_id FROM marketing.stores ORDER BY location_lat DESC;

[User] Tally up stores by zip_code.

[Assistant] SELECT zip_code, COUNT(*) AS count FROM marketing.stores GROUP BY zip_code ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.appointments (
  order_id character varying(64) NOT NULL -- unique identifier,
  processed_at date,
  card_type text NOT NULL,
  subtotal integer,
  status varchar
)

CREATE TABLE healthcare.medical_records (
  customer_id character varying(64) NOT NULL -- unique identifier,
  joined_at timestamp without time zone,
  created_at date,
  password_hash character varying(64),
  phone character varying(64) NOT NULL,
  language text,
  age character varying(128),
  nationality character varying(128),
  membership_level text NOT NULL,
  last_login timestamp without time zone
)

[User] Show me processed_at, status, subtotal for all appointments.

[Assistant] SELECT processed_at, status, subtotal FROM healthcare.appointments;

[User] List appointments that have processed_at > '2023-01-01'.

[Assistant] SELECT processed_at, status, subtotal FROM healthcare.appointments WHERE processed_at > '2023-01-01';

[User] Arrange the results with card_type in ascending order.

[Assistant] SELECT processed_at, status, subtotal FROM healthcare.appointments WHERE processed_at > '2023-01-01' ORDER BY card_type ASC;


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Find appointments where status LIKE 'A%'.

[Assistant] SELECT * FROM healthcare.appointments WHERE status LIKE 'A%';

[User] Restrict the output to 100 items.

[Assistant] SELECT * FROM healthcare.appointments WHERE status LIKE 'A%' LIMIT 100;


[User] List membership_level, language, nationality from medical_records.

[Assistant] SELECT membership_level, language, nationality FROM healthcare.medical_records;

[User] Arrange the results with phone in ascending order.

[Assistant] SELECT membership_level, language, nationality FROM healthcare.medical_records ORDER BY phone ASC;

[User] Get count of created_at by created_at from medical_records.

[Assistant] SELECT created_at, COUNT(created_at) AS count_created_at FROM healthcare.medical_records GROUP BY created_at;


[User] Retrieve phone, password_hash, language for every medical_record.

[Assistant] SELECT phone, password_hash, language FROM healthcare.medical_records;

[User] Can you order these by phone ascending?

[Assistant] SELECT phone, password_hash, language FROM healthcare.medical_records ORDER BY phone ASC;

[User] Group medical_records by language and show the average of joined_at.

[Assistant] SELECT language, AVERAGE(joined_at) AS average_joined_at FROM healthcare.medical_records GROUP BY language;


[User] Get last_login, joined_at, nationality from all medical_records.

[Assistant] SELECT last_login, joined_at, nationality FROM healthcare.medical_records;

[User] Retrieve medical_records where nationality LIKE 'A%'.

[Assistant] SELECT last_login, joined_at, nationality FROM healthcare.medical_records WHERE nationality LIKE 'A%';

[User] How many medical_records are there per joined_at?

[Assistant] SELECT joined_at, COUNT(*) AS count FROM healthcare.medical_records GROUP BY joined_at ORDER BY count DESC;


[User] Get all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

[User] Find medical_records where joined_at > '2023-01-01'.

[Assistant] SELECT * FROM healthcare.medical_records WHERE joined_at > '2023-01-01';

[User] Order the output by nationality descending.

[Assistant] SELECT * FROM healthcare.medical_records WHERE joined_at > '2023-01-01' ORDER BY nationality DESC;


[User] Get all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Sort the results by subtotal descending.

[Assistant] SELECT * FROM healthcare.appointments ORDER BY subtotal DESC;

[User] What is the sum processed_at for each card_type in appointments?

[Assistant] SELECT card_type, SUM(processed_at) AS sum_processed_at FROM healthcare.appointments GROUP BY card_type;


[User] List all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

[User] Find medical_records created after December 1st, 2023.

[Assistant] SELECT * FROM healthcare.medical_records WHERE created_at > '2023-12-01';

[User] Arrange the results with password_hash in ascending order.

[Assistant] SELECT * FROM healthcare.medical_records WHERE created_at > '2023-12-01' ORDER BY password_hash ASC;


[User] Retrieve order_id, processed_at, card_type for every appointment.

[Assistant] SELECT order_id, processed_at, card_type FROM healthcare.appointments;

[User] Find appointments where processed_at > '2023-01-01'.

[Assistant] SELECT order_id, processed_at, card_type FROM healthcare.appointments WHERE processed_at > '2023-01-01';

[User] Arrange the results with status in descending order.

[Assistant] SELECT order_id, processed_at, card_type FROM healthcare.appointments WHERE processed_at > '2023-01-01' ORDER BY status DESC;


[User] What are the order_id, card_type, subtotal of each appointment?

[Assistant] SELECT order_id, card_type, subtotal FROM healthcare.appointments;

[User] Get all appointments between January and March.

[Assistant] SELECT order_id, card_type, subtotal FROM healthcare.appointments WHERE processed_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Get the distribution of appointments across different card_type values.

[Assistant] SELECT card_type, COUNT(*) AS count FROM healthcare.appointments GROUP BY card_type ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE e-commerce.order_items (
  person_id character varying(64) NOT NULL -- unique identifier,
  updated_at date,
  created_at date,
  is_active bit,
  is_verified bit,
  status character varying(128),
  api_key char NOT NULL,
  order_id text -- reference to orders.order_id,
  FOREIGN KEY (order_id) REFERENCES orders(order_id)
)

CREATE TABLE e-commerce.orders (
  order_id varchar PRIMARY KEY -- unique identifier,
  created_at date,
  completed_at timestamp,
  exchange_rate character varying(64) NOT NULL,
  currency text,
  card_type character varying(256),
  payment_method character varying(128),
  subtotal bigint,
  price numeric(38,14),
  inventor_id text -- reference to inventory.item_id,
  FOREIGN KEY (inventor_id) REFERENCES inventory(item_id)
)

CREATE TABLE e-commerce.inventory (
  item_id text PRIMARY KEY -- unique identifier,
  published_at timestamp,
  tax_rate char,
  video_url text,
  available character varying(64) NOT NULL
)

[User] List subtotal, created_at, exchange_rate from orders.

[Assistant] SELECT subtotal, created_at, exchange_rate FROM e-commerce.orders;

[User] Sort the results by currency descending.

[Assistant] SELECT subtotal, created_at, exchange_rate FROM e-commerce.orders ORDER BY currency DESC;

[User] Sort the results by created_at descending.

[Assistant] SELECT subtotal, created_at, exchange_rate FROM e-commerce.orders ORDER BY created_at DESC;


[User] Get currency, created_at, card_type from all orders.

[Assistant] SELECT currency, created_at, card_type FROM e-commerce.orders;

[User] What exchange_rate, inventor_id, published_at, available do we have for orders and their associated inventory?

[Assistant] SELECT currency, created_at, card_type, inventory.published_at, inventory.available FROM e-commerce.orders JOIN e-commerce.inventory ON orders.inventor_id = inventory.item_id;

[User] Only show the top 100 results.

[Assistant] SELECT currency, created_at, card_type, inventory.published_at, inventory.available FROM e-commerce.orders JOIN e-commerce.inventory ON orders.inventor_id = inventory.item_id LIMIT 100;


[User] Show me all orders.

[Assistant] SELECT * FROM e-commerce.orders;

[User] Show the results sorted by price ascending.

[Assistant] SELECT * FROM e-commerce.orders ORDER BY price ASC;

[User] Sort the results by exchange_rate ascending.

[Assistant] SELECT * FROM e-commerce.orders ORDER BY exchange_rate ASC;


[User] List currency, inventor_id, price from orders.

[Assistant] SELECT currency, inventor_id, price FROM e-commerce.orders;

[User] Arrange the results with completed_at in descending order.

[Assistant] SELECT currency, inventor_id, price FROM e-commerce.orders ORDER BY completed_at DESC;

[User] Count the number of orders in each exchange_rate category.

[Assistant] SELECT exchange_rate, COUNT(*) AS count FROM e-commerce.orders GROUP BY exchange_rate ORDER BY count DESC;


[User] Get all order_items.

[Assistant] SELECT * FROM e-commerce.order_items;

[User] Retrieve order_items where the date is from last week.

[Assistant] SELECT * FROM e-commerce.order_items WHERE created_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Show me the count of order_items grouped by created_at.

[Assistant] SELECT created_at, COUNT(*) AS count FROM e-commerce.order_items GROUP BY created_at ORDER BY count DESC;


[User] Show me order_id, status, api_key for all order_items.

[Assistant] SELECT order_id, status, api_key FROM e-commerce.order_items;

[User] Sort the results by created_at ascending.

[Assistant] SELECT order_id, status, api_key FROM e-commerce.order_items ORDER BY created_at ASC;

[User] Show only 20 records.

[Assistant] SELECT order_id, status, api_key FROM e-commerce.order_items ORDER BY created_at ASC LIMIT 20;


[User] Display all orders.

[Assistant] SELECT * FROM e-commerce.orders;

[User] List orders that have card_type LIKE 'A%'.

[Assistant] SELECT * FROM e-commerce.orders WHERE card_type LIKE 'A%';

[User] Get min of created_at by payment_method from orders.

[Assistant] SELECT payment_method, MIN(created_at) AS min_created_at FROM e-commerce.orders GROUP BY payment_method;


[User] Retrieve completed_at, subtotal, inventor_id for every order.

[Assistant] SELECT completed_at, subtotal, inventor_id FROM e-commerce.orders;

[User] Retrieve orders where inventor_id LIKE 'A%'.

[Assistant] SELECT completed_at, subtotal, inventor_id FROM e-commerce.orders WHERE inventor_id LIKE 'A%';

[User] Show me the count of orders grouped by payment_method.

[Assistant] SELECT payment_method, COUNT(*) AS count FROM e-commerce.orders GROUP BY payment_method ORDER BY count DESC;


[User] Retrieve all order_items.

[Assistant] SELECT * FROM e-commerce.order_items;

[User] Arrange the results with updated_at in ascending order.

[Assistant] SELECT * FROM e-commerce.order_items ORDER BY updated_at ASC;

[User] Show me the count of order_items grouped by updated_at.

[Assistant] SELECT updated_at, COUNT(*) AS count FROM e-commerce.order_items GROUP BY updated_at ORDER BY count DESC;


[User] Show me exchange_rate, payment_method, created_at for all orders.

[Assistant] SELECT exchange_rate, payment_method, created_at FROM e-commerce.orders;

[User] Show me card_type, created_at, available, tax_rate from orders and their related inventory.

[Assistant] SELECT exchange_rate, payment_method, created_at, inventory.available, inventory.tax_rate FROM e-commerce.orders JOIN e-commerce.inventory ON orders.inventor_id = inventory.item_id;

[User] Tally up orders by created_at.

[Assistant] SELECT created_at, COUNT(*) AS count FROM e-commerce.orders GROUP BY created_at ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.grades (
  sku varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  reserved text,
  brand character varying(256) NOT NULL,
  manufacturer character varying(64),
  image_url text,
  enrollment_id text -- reference to enrollments.item_id,
  department_id integer NOT NULL -- reference to departments.transaction_id,
  FOREIGN KEY (enrollment_id) REFERENCES enrollments(item_id),
  FOREIGN KEY (department_id) REFERENCES departments(transaction_id)
)

CREATE TABLE education.enrollments (
  item_id varchar PRIMARY KEY -- unique identifier,
  published_at date,
  name varchar NOT NULL,
  video_url character varying(256),
  views char NOT NULL,
  msrp varchar NOT NULL,
  thumbnail_url text,
  grade_id text NOT NULL -- reference to grades.sku,
  department_id integer NOT NULL -- reference to departments.transaction_id,
  FOREIGN KEY (grade_id) REFERENCES grades(sku),
  FOREIGN KEY (department_id) REFERENCES departments(transaction_id)
)

CREATE TABLE education.departments (
  transaction_id integer PRIMARY KEY -- unique identifier,
  payment_date date,
  due_date timestamp,
  payee_id character varying(64),
  reconciliation_status text,
  reference_number character varying(256)
)

[User] Retrieve grade_id, video_url, views for every enrollment.

[Assistant] SELECT grade_id, video_url, views FROM education.enrollments;

[User] Get video_url, thumbnail_url, reserved, updated_at by joining enrollments with grades.

[Assistant] SELECT grade_id, video_url, views, grades.reserved, grades.updated_at FROM education.enrollments JOIN education.grades ON enrollments.grade_id = grades.sku;

[User] Get the distribution of enrollments across different grade_id values.

[Assistant] SELECT grade_id, COUNT(*) AS count FROM education.enrollments GROUP BY grade_id ORDER BY count DESC;


[User] Show me all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Arrange the results with msrp in descending order.

[Assistant] SELECT * FROM education.enrollments ORDER BY msrp DESC;

[User] Restrict the output to 20 items.

[Assistant] SELECT * FROM education.enrollments ORDER BY msrp DESC LIMIT 20;


[User] Display all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Show me name, msrp, enrollment_id, department_id from enrollments and their related grades.

[Assistant] SELECT *, grades.enrollment_id, grades.department_id FROM education.enrollments JOIN education.grades ON enrollments.grade_id = grades.sku;

[User] Can you order these by name ascending?

[Assistant] SELECT *, grades.enrollment_id, grades.department_id FROM education.enrollments JOIN education.grades ON enrollments.grade_id = grades.sku ORDER BY name ASC;


[User] List manufacturer, image_url, department_id from grades.

[Assistant] SELECT manufacturer, image_url, department_id FROM education.grades;

[User] Get manufacturer, reserved, msrp, video_url by joining grades with enrollments.

[Assistant] SELECT manufacturer, image_url, department_id, enrollments.msrp, enrollments.video_url FROM education.grades JOIN education.enrollments ON grades.enrollment_id = enrollments.item_id;

[User] Count the number of grades in each manufacturer category.

[Assistant] SELECT manufacturer, COUNT(*) AS count FROM education.grades GROUP BY manufacturer ORDER BY count DESC;


[User] Get enrollment_id, department_id, brand from all grades.

[Assistant] SELECT enrollment_id, department_id, brand FROM education.grades;

[User] Retrieve enrollment_id, image_url, department_id, name showing the relationship between grades and enrollments.

[Assistant] SELECT enrollment_id, department_id, brand, enrollments.department_id, enrollments.name FROM education.grades JOIN education.enrollments ON grades.enrollment_id = enrollments.item_id;

[User] How many grades are there per reserved?

[Assistant] SELECT reserved, COUNT(*) AS count FROM education.grades GROUP BY reserved ORDER BY count DESC;


[User] Retrieve all grades.

[Assistant] SELECT * FROM education.grades;

[User] Find grades from last week.

[Assistant] SELECT * FROM education.grades WHERE updated_at >= CURRENT_DATE - INTERVAL '7 days';

[User] How many grades are there per manufacturer?

[Assistant] SELECT manufacturer, COUNT(*) AS count FROM education.grades GROUP BY manufacturer ORDER BY count DESC;


[User] Display all grades.

[Assistant] SELECT * FROM education.grades;

[User] Show me reserved, department_id, grade_id, thumbnail_url from grades and their related enrollments.

[Assistant] SELECT *, enrollments.grade_id, enrollments.thumbnail_url FROM education.grades JOIN education.enrollments ON grades.enrollment_id = enrollments.item_id;

[User] Can you order these by manufacturer descending?

[Assistant] SELECT *, enrollments.grade_id, enrollments.thumbnail_url FROM education.grades JOIN education.enrollments ON grades.enrollment_id = enrollments.item_id ORDER BY manufacturer DESC;


[User] Display all grades.

[Assistant] SELECT * FROM education.grades;

[User] Can you order these by enrollment_id ascending?

[Assistant] SELECT * FROM education.grades ORDER BY enrollment_id ASC;

[User] Show me average of reserved grouped by manufacturer for grades.

[Assistant] SELECT manufacturer, AVERAGE(reserved) AS average_reserved FROM education.grades GROUP BY manufacturer;


[User] Retrieve all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Retrieve msrp, grade_id, updated_at, reserved showing the relationship between enrollments and grades.

[Assistant] SELECT *, grades.updated_at, grades.reserved FROM education.enrollments JOIN education.grades ON enrollments.grade_id = grades.sku;

[User] Get count of msrp by msrp from enrollments.

[Assistant] SELECT msrp, COUNT(msrp) AS count_msrp FROM education.enrollments GROUP BY msrp;


[User] Show me all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Retrieve published_at, name, image_url, manufacturer showing the relationship between enrollments and grades.

[Assistant] SELECT *, grades.image_url, grades.manufacturer FROM education.enrollments JOIN education.grades ON enrollments.grade_id = grades.sku;

[User] Show me max of grade_id grouped by department_id for enrollments.

[Assistant] SELECT department_id, MAX(grade_id) AS max_grade_id FROM education.enrollments GROUP BY department_id;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.departments (
  order_id varchar PRIMARY KEY -- unique identifier,
  updated_at date,
  created_at timestamp without time zone,
  user_id varchar -- identifier for user,
  tax bigint,
  currency character varying(128),
  price integer NOT NULL,
  payment_method character varying(256),
  prescription_id text -- reference to prescriptions.id,
  FOREIGN KEY (prescription_id) REFERENCES prescriptions(id)
)

CREATE TABLE healthcare.prescriptions (
  id varchar PRIMARY KEY -- unique identifier,
  created_at date,
  views char NOT NULL,
  cost numeric,
  media_url character varying(64) NOT NULL
)

CREATE TABLE healthcare.patients (
  id varchar PRIMARY KEY -- unique identifier,
  created_at date,
  language text,
  address character varying(64),
  gender varchar NOT NULL,
  password_hash character varying(256),
  status char,
  timezone character varying(128),
  department_id text NOT NULL -- reference to departments.order_id,
  FOREIGN KEY (department_id) REFERENCES departments(order_id)
)

[User] Show me all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Retrieve departments where the date is created after December 1st, 2023.

[Assistant] SELECT * FROM healthcare.departments WHERE created_at > '2023-12-01';

[User] Only show the top 25 results.

[Assistant] SELECT * FROM healthcare.departments WHERE created_at > '2023-12-01' LIMIT 25;


[User] List address, gender, language from patients.

[Assistant] SELECT address, gender, language FROM healthcare.patients;

[User] Get password_hash, timezone, created_at, payment_method by joining patients with departments.

[Assistant] SELECT address, gender, language, departments.created_at, departments.payment_method FROM healthcare.patients JOIN healthcare.departments ON patients.department_id = departments.order_id;

[User] Restrict the output to 100 items.

[Assistant] SELECT address, gender, language, departments.created_at, departments.payment_method FROM healthcare.patients JOIN healthcare.departments ON patients.department_id = departments.order_id LIMIT 100;


[User] Retrieve all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Get user_id, updated_at, cost, views by joining departments with prescriptions.

[Assistant] SELECT *, prescriptions.cost, prescriptions.views FROM healthcare.departments JOIN healthcare.prescriptions ON departments.prescription_id = prescriptions.id;

[User] Tally up departments by updated_at.

[Assistant] SELECT updated_at, COUNT(*) AS count FROM healthcare.departments GROUP BY updated_at ORDER BY count DESC;


[User] Get payment_method, price, tax from all departments.

[Assistant] SELECT payment_method, price, tax FROM healthcare.departments;

[User] Get currency, updated_at, created_at, media_url by joining departments with prescriptions.

[Assistant] SELECT payment_method, price, tax, prescriptions.created_at, prescriptions.media_url FROM healthcare.departments JOIN healthcare.prescriptions ON departments.prescription_id = prescriptions.id;

[User] Sort the results by user_id descending.

[Assistant] SELECT payment_method, price, tax, prescriptions.created_at, prescriptions.media_url FROM healthcare.departments JOIN healthcare.prescriptions ON departments.prescription_id = prescriptions.id ORDER BY user_id DESC;


[User] Get tax, created_at, currency from all departments.

[Assistant] SELECT tax, created_at, currency FROM healthcare.departments;

[User] Arrange the results with updated_at in descending order.

[Assistant] SELECT tax, created_at, currency FROM healthcare.departments ORDER BY updated_at DESC;

[User] Arrange the results with payment_method in ascending order.

[Assistant] SELECT tax, created_at, currency FROM healthcare.departments ORDER BY payment_method ASC;


[User] Get all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Retrieve updated_at, prescription_id, views, created_at showing the relationship between departments and prescriptions.

[Assistant] SELECT *, prescriptions.views, prescriptions.created_at FROM healthcare.departments JOIN healthcare.prescriptions ON departments.prescription_id = prescriptions.id;

[User] Calculate average of tax for each payment_method in departments.

[Assistant] SELECT payment_method, AVERAGE(tax) AS average_tax FROM healthcare.departments GROUP BY payment_method;


[User] Retrieve all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] List departments with dates modified within the last hour.

[Assistant] SELECT * FROM healthcare.departments WHERE created_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Calculate min of user_id for each updated_at in departments.

[Assistant] SELECT updated_at, MIN(user_id) AS min_user_id FROM healthcare.departments GROUP BY updated_at;


[User] Show me all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Retrieve departments where the date is from last week.

[Assistant] SELECT * FROM healthcare.departments WHERE created_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Show only 15 records.

[Assistant] SELECT * FROM healthcare.departments WHERE created_at >= CURRENT_DATE - INTERVAL '7 days' LIMIT 15;


[User] Get all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Get all departments modified within the last hour.

[Assistant] SELECT * FROM healthcare.departments WHERE updated_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] How many departments are there per payment_method?

[Assistant] SELECT payment_method, COUNT(*) AS count FROM healthcare.departments GROUP BY payment_method ORDER BY count DESC;


[User] Show me address, status, timezone for all patients.

[Assistant] SELECT address, status, timezone FROM healthcare.patients;

[User] Show me patients with address LIKE 'A%'.

[Assistant] SELECT address, status, timezone FROM healthcare.patients WHERE address LIKE 'A%';

[User] Count the number of patients in each address category.

[Assistant] SELECT address, COUNT(*) AS count FROM healthcare.patients GROUP BY address ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.customers (
  id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  last_login date NOT NULL,
  username varchar NOT NULL,
  bio text,
  account_id text NOT NULL -- reference to accounts.invoice_id,
  FOREIGN KEY (account_id) REFERENCES accounts(invoice_id)
)

CREATE TABLE finance.loans (
  employee_id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  last_active date,
  full_name char,
  last_name character varying(256) NOT NULL,
  first_name character varying(128),
  account_id text NOT NULL -- reference to accounts.invoice_id,
  FOREIGN KEY (account_id) REFERENCES accounts(invoice_id)
)

CREATE TABLE finance.accounts (
  invoice_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  status char,
  vendor_id character varying(256) NOT NULL,
  customer_id character varying(128),
  user_id character varying(128),
  invoice_number character varying(128) NOT NULL,
  loan_id text -- reference to loans.employee_id,
  FOREIGN KEY (loan_id) REFERENCES loans(employee_id)
)

[User] Retrieve all accounts.

[Assistant] SELECT * FROM finance.accounts;

[User] Can you order these by invoice_number ascending?

[Assistant] SELECT * FROM finance.accounts ORDER BY invoice_number ASC;

[User] Only show the top 5 results.

[Assistant] SELECT * FROM finance.accounts ORDER BY invoice_number ASC LIMIT 5;


[User] Get username, last_login, bio from all customers.

[Assistant] SELECT username, last_login, bio FROM finance.customers;

[User] Get created_at, bio, invoice_number, vendor_id by joining customers with accounts.

[Assistant] SELECT username, last_login, bio, accounts.invoice_number, accounts.vendor_id FROM finance.customers JOIN finance.accounts ON customers.account_id = accounts.invoice_id;

[User] What is the min last_login for each bio in customers?

[Assistant] SELECT bio, MIN(last_login) AS min_last_login FROM finance.customers GROUP BY bio;


[User] What are the loan_id, customer_id, vendor_id of each account?

[Assistant] SELECT loan_id, customer_id, vendor_id FROM finance.accounts;

[User] Order the output by loan_id ascending.

[Assistant] SELECT loan_id, customer_id, vendor_id FROM finance.accounts ORDER BY loan_id ASC;

[User] Can you order these by vendor_id descending?

[Assistant] SELECT loan_id, customer_id, vendor_id FROM finance.accounts ORDER BY vendor_id DESC;


[User] Display all accounts.

[Assistant] SELECT * FROM finance.accounts;

[User] List accounts with dates created yesterday.

[Assistant] SELECT * FROM finance.accounts WHERE updated_at = CURRENT_DATE - INTERVAL '1 day';

[User] Show me count of updated_at grouped by customer_id for accounts.

[Assistant] SELECT customer_id, COUNT(updated_at) AS count_updated_at FROM finance.accounts GROUP BY customer_id;


[User] List all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Show me loans with first_name LIKE 'A%'.

[Assistant] SELECT * FROM finance.loans WHERE first_name LIKE 'A%';

[User] Can you order these by first_name ascending?

[Assistant] SELECT * FROM finance.loans WHERE first_name LIKE 'A%' ORDER BY first_name ASC;


[User] Show me first_name, last_name, last_active for all loans.

[Assistant] SELECT first_name, last_name, last_active FROM finance.loans;

[User] Retrieve loans where last_active > '2023-01-01'.

[Assistant] SELECT first_name, last_name, last_active FROM finance.loans WHERE last_active > '2023-01-01';

[User] Count the number of loans in each full_name category.

[Assistant] SELECT full_name, COUNT(*) AS count FROM finance.loans GROUP BY full_name ORDER BY count DESC;


[User] Show me account_id, last_active, last_name for all loans.

[Assistant] SELECT account_id, last_active, last_name FROM finance.loans;

[User] Find loans from 2023.

[Assistant] SELECT account_id, last_active, last_name FROM finance.loans WHERE last_active BETWEEN '2023-01-01' AND '2023-12-31';

[User] Count the number of loans in each full_name category.

[Assistant] SELECT full_name, COUNT(*) AS count FROM finance.loans GROUP BY full_name ORDER BY count DESC;


[User] Show me all customers.

[Assistant] SELECT * FROM finance.customers;

[User] Can you order these by bio descending?

[Assistant] SELECT * FROM finance.customers ORDER BY bio DESC;

[User] Show only 25 records.

[Assistant] SELECT * FROM finance.customers ORDER BY bio DESC LIMIT 25;


[User] Get all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Order the output by last_active descending.

[Assistant] SELECT * FROM finance.loans ORDER BY last_active DESC;

[User] Order the output by created_at descending.

[Assistant] SELECT * FROM finance.loans ORDER BY created_at DESC;


[User] Retrieve all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Get first_name, last_name, customer_id, vendor_id by joining loans with accounts.

[Assistant] SELECT *, accounts.customer_id, accounts.vendor_id FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.invoice_id;

[User] Show me the count of loans grouped by first_name.

[Assistant] SELECT first_name, COUNT(*) AS count FROM finance.loans GROUP BY first_name ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.courses (
  person_id text PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  last_active date,
  account_status character varying(256) NOT NULL,
  display_name varchar,
  salt text NOT NULL,
  last_login timestamp,
  gender char,
  student_id integer NOT NULL -- reference to students.person_id,
  FOREIGN KEY (student_id) REFERENCES students(person_id)
)

CREATE TABLE education.students (
  person_id integer PRIMARY KEY -- unique identifier,
  joined_at date,
  timezone character varying(64),
  email character varying(64) NOT NULL,
  membership_level character varying(64) NOT NULL,
  city varchar,
  token char,
  first_name character varying(128),
  last_login timestamp
)

CREATE TABLE education.assignments (
  invoice_id character varying(64) NOT NULL -- unique identifier,
  processed_at date,
  notes character varying(128),
  category text,
  reconciliation_status char,
  amount decimal,
  invoice_number char NOT NULL,
  student_id integer -- reference to students.person_id,
  FOREIGN KEY (student_id) REFERENCES students(person_id)
)

[User] What are the salt, last_login, gender of each course?

[Assistant] SELECT salt, last_login, gender FROM education.courses;

[User] Arrange the results with account_status in descending order.

[Assistant] SELECT salt, last_login, gender FROM education.courses ORDER BY account_status DESC;

[User] Sort the results by display_name descending.

[Assistant] SELECT salt, last_login, gender FROM education.courses ORDER BY display_name DESC;


[User] Retrieve all courses.

[Assistant] SELECT * FROM education.courses;

[User] What account_status, salt, membership_level, token do we have for courses and their associated students?

[Assistant] SELECT *, students.membership_level, students.token FROM education.courses JOIN education.students ON courses.student_id = students.person_id;

[User] Show me the count of courses grouped by display_name.

[Assistant] SELECT display_name, COUNT(*) AS count FROM education.courses GROUP BY display_name ORDER BY count DESC;


[User] Get all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Get invoice_id, invoice_number, membership_level, token by joining assignments with students.

[Assistant] SELECT *, students.membership_level, students.token FROM education.assignments JOIN education.students ON assignments.student_id = students.person_id;

[User] Show me the count of assignments grouped by student_id.

[Assistant] SELECT student_id, COUNT(*) AS count FROM education.assignments GROUP BY student_id ORDER BY count DESC;


[User] Show me all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] List assignments that have reconciliation_status LIKE 'A%'.

[Assistant] SELECT * FROM education.assignments WHERE reconciliation_status LIKE 'A%';

[User] Get min of amount by processed_at from assignments.

[Assistant] SELECT processed_at, MIN(amount) AS min_amount FROM education.assignments GROUP BY processed_at;


[User] Show me all courses.

[Assistant] SELECT * FROM education.courses;

[User] List salt, created_at, membership_level, email for each course along with their student information.

[Assistant] SELECT *, students.membership_level, students.email FROM education.courses JOIN education.students ON courses.student_id = students.person_id;

[User] Get the distribution of courses across different account_status values.

[Assistant] SELECT account_status, COUNT(*) AS count FROM education.courses GROUP BY account_status ORDER BY count DESC;


[User] Show me invoice_number, notes, processed_at for all assignments.

[Assistant] SELECT invoice_number, notes, processed_at FROM education.assignments;

[User] Find assignments where notes LIKE 'A%'.

[Assistant] SELECT invoice_number, notes, processed_at FROM education.assignments WHERE notes LIKE 'A%';

[User] Arrange the results with invoice_number in descending order.

[Assistant] SELECT invoice_number, notes, processed_at FROM education.assignments WHERE notes LIKE 'A%' ORDER BY invoice_number DESC;


[User] Show me display_name, student_id, salt for all courses.

[Assistant] SELECT display_name, student_id, salt FROM education.courses;

[User] List last_active, created_at, last_login, token for each course along with their student information.

[Assistant] SELECT display_name, student_id, salt, students.last_login, students.token FROM education.courses JOIN education.students ON courses.student_id = students.person_id;

[User] Get the distribution of courses across different display_name values.

[Assistant] SELECT display_name, COUNT(*) AS count FROM education.courses GROUP BY display_name ORDER BY count DESC;


[User] Retrieve all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Get all assignments from 2023.

[Assistant] SELECT * FROM education.assignments WHERE processed_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] How many assignments are there per student_id?

[Assistant] SELECT student_id, COUNT(*) AS count FROM education.assignments GROUP BY student_id ORDER BY count DESC;


[User] What are the student_id, reconciliation_status, category of each assignment?

[Assistant] SELECT student_id, reconciliation_status, category FROM education.assignments;

[User] Arrange the results with category in ascending order.

[Assistant] SELECT student_id, reconciliation_status, category FROM education.assignments ORDER BY category ASC;

[User] Get average of student_id by invoice_number from assignments.

[Assistant] SELECT invoice_number, AVERAGE(student_id) AS average_student_id FROM education.assignments GROUP BY invoice_number;


[User] What are the salt, display_name, last_active of each course?

[Assistant] SELECT salt, display_name, last_active FROM education.courses;

[User] Show the results sorted by salt ascending.

[Assistant] SELECT salt, display_name, last_active FROM education.courses ORDER BY salt ASC;

[User] What is the max account_status for each last_login in courses?

[Assistant] SELECT last_login, MAX(account_status) AS max_account_status FROM education.courses GROUP BY last_login;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE media.sales (
  invoice_id integer PRIMARY KEY -- unique identifier,
  processed_at timestamp,
  user_id text NOT NULL -- identifier for user,
  buyer_id char,
  subtotal bigint,
  currency text,
  approval_status char,
  customer_id character varying(64),
  product_id text NOT NULL -- reference to products.item_id,
  patient_id integer -- reference to patients.employee_id,
  FOREIGN KEY (product_id) REFERENCES products(item_id),
  FOREIGN KEY (patient_id) REFERENCES patients(employee_id)
)

CREATE TABLE media.patients (
  employee_id integer PRIMARY KEY -- unique identifier,
  last_active timestamp,
  updated_at date,
  bio varchar NOT NULL,
  membership_level char,
  display_name text,
  gender character varying(256),
  sale_id integer NOT NULL -- reference to sales.invoice_id,
  product_id text -- reference to products.item_id,
  FOREIGN KEY (sale_id) REFERENCES sales(invoice_id),
  FOREIGN KEY (product_id) REFERENCES products(item_id)
)

CREATE TABLE media.products (
  item_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  popularity_score varchar NOT NULL,
  currency character varying(128),
  brand varchar,
  sale_id integer -- reference to sales.invoice_id,
  FOREIGN KEY (sale_id) REFERENCES sales(invoice_id)
)

[User] Retrieve updated_at, popularity_score, sale_id for every product.

[Assistant] SELECT updated_at, popularity_score, sale_id FROM media.products;

[User] List products with dates created in the last 30 days.

[Assistant] SELECT updated_at, popularity_score, sale_id FROM media.products WHERE updated_at >= CURRENT_DATE - INTERVAL '30 days';

[User] How many products are there per updated_at?

[Assistant] SELECT updated_at, COUNT(*) AS count FROM media.products GROUP BY updated_at ORDER BY count DESC;


[User] Show me membership_level, last_active, gender for all patients.

[Assistant] SELECT membership_level, last_active, gender FROM media.patients;

[User] Get patients that match bio LIKE 'A%'.

[Assistant] SELECT membership_level, last_active, gender FROM media.patients WHERE bio LIKE 'A%';

[User] Can you order these by display_name ascending?

[Assistant] SELECT membership_level, last_active, gender FROM media.patients WHERE bio LIKE 'A%' ORDER BY display_name ASC;


[User] Retrieve all sales.

[Assistant] SELECT * FROM media.sales;

[User] Retrieve sales where approval_status LIKE 'A%'.

[Assistant] SELECT * FROM media.sales WHERE approval_status LIKE 'A%';

[User] Order the output by currency ascending.

[Assistant] SELECT * FROM media.sales WHERE approval_status LIKE 'A%' ORDER BY currency ASC;


[User] List bio, updated_at, membership_level from patients.

[Assistant] SELECT bio, updated_at, membership_level FROM media.patients;

[User] Find patients from last week.

[Assistant] SELECT bio, updated_at, membership_level FROM media.patients WHERE last_active >= CURRENT_DATE - INTERVAL '7 days';

[User] Sort the results by gender ascending.

[Assistant] SELECT bio, updated_at, membership_level FROM media.patients WHERE last_active >= CURRENT_DATE - INTERVAL '7 days' ORDER BY gender ASC;


[User] Display all patients.

[Assistant] SELECT * FROM media.patients;

[User] Sort the results by product_id descending.

[Assistant] SELECT * FROM media.patients ORDER BY product_id DESC;

[User] Show me max of membership_level grouped by display_name for patients.

[Assistant] SELECT display_name, MAX(membership_level) AS max_membership_level FROM media.patients GROUP BY display_name;


[User] Get all sales.

[Assistant] SELECT * FROM media.sales;

[User] List subtotal, product_id, currency, brand for each sale along with their product information.

[Assistant] SELECT *, products.currency, products.brand FROM media.sales JOIN media.products ON sales.product_id = products.item_id;

[User] Tally up sales by product_id.

[Assistant] SELECT product_id, COUNT(*) AS count FROM media.sales GROUP BY product_id ORDER BY count DESC;


[User] List updated_at, sale_id, popularity_score from products.

[Assistant] SELECT updated_at, sale_id, popularity_score FROM media.products;

[User] Find products older than 6 months.

[Assistant] SELECT updated_at, sale_id, popularity_score FROM media.products WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Arrange the results with updated_at in descending order.

[Assistant] SELECT updated_at, sale_id, popularity_score FROM media.products WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months' ORDER BY updated_at DESC;


[User] List popularity_score, sale_id, updated_at from products.

[Assistant] SELECT popularity_score, sale_id, updated_at FROM media.products;

[User] What brand, updated_at, approval_status, currency do we have for products and their associated sales?

[Assistant] SELECT popularity_score, sale_id, updated_at, sales.approval_status, sales.currency FROM media.products JOIN media.sales ON products.sale_id = sales.invoice_id;

[User] Get the distribution of products across different sale_id values.

[Assistant] SELECT sale_id, COUNT(*) AS count FROM media.products GROUP BY sale_id ORDER BY count DESC;


[User] Get all sales.

[Assistant] SELECT * FROM media.sales;

[User] List currency, user_id, updated_at, brand for each sale along with their product information.

[Assistant] SELECT *, products.updated_at, products.brand FROM media.sales JOIN media.products ON sales.product_id = products.item_id;

[User] Show the results sorted by user_id descending.

[Assistant] SELECT *, products.updated_at, products.brand FROM media.sales JOIN media.products ON sales.product_id = products.item_id ORDER BY user_id DESC;


[User] Show me sale_id, bio, updated_at for all patients.

[Assistant] SELECT sale_id, bio, updated_at FROM media.patients;

[User] Get updated_at, last_active, approval_status, subtotal by joining patients with sales.

[Assistant] SELECT sale_id, bio, updated_at, sales.approval_status, sales.subtotal FROM media.patients JOIN media.sales ON patients.sale_id = sales.invoice_id;

[User] Restrict the output to 15 items.

[Assistant] SELECT sale_id, bio, updated_at, sales.approval_status, sales.subtotal FROM media.patients JOIN media.sales ON patients.sale_id = sales.invoice_id LIMIT 15;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE socialmedia.comments (
  message_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  published_at timestamp,
  author_id varchar NOT NULL,
  description text,
  subject varchar NOT NULL,
  thumbnail character varying(128),
  format character varying(64),
  reply_to_id char,
  post_id text NOT NULL -- reference to posts.id,
  FOREIGN KEY (post_id) REFERENCES posts(id)
)

CREATE TABLE socialmedia.posts (
  id text PRIMARY KEY -- unique identifier,
  updated_at date,
  created_at date,
  visibility varchar,
  rating character varying(128),
  image_url character varying(64),
  categories character varying(256) NOT NULL,
  subject character varying(128),
  comment_id integer -- reference to comments.message_id,
  FOREIGN KEY (comment_id) REFERENCES comments(message_id)
)

[User] What are the description, published_at, subject of each comment?

[Assistant] SELECT description, published_at, subject FROM socialmedia.comments;

[User] Show me comments that were created in the last 30 days.

[Assistant] SELECT description, published_at, subject FROM socialmedia.comments WHERE created_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Arrange the results with description in descending order.

[Assistant] SELECT description, published_at, subject FROM socialmedia.comments WHERE created_at >= CURRENT_DATE - INTERVAL '30 days' ORDER BY description DESC;


[User] List all posts.

[Assistant] SELECT * FROM socialmedia.posts;

[User] Show me posts with created_at > '2023-01-01'.

[Assistant] SELECT * FROM socialmedia.posts WHERE created_at > '2023-01-01';

[User] How many posts are there per subject?

[Assistant] SELECT subject, COUNT(*) AS count FROM socialmedia.posts GROUP BY subject ORDER BY count DESC;


[User] Show me published_at, thumbnail, created_at for all comments.

[Assistant] SELECT published_at, thumbnail, created_at FROM socialmedia.comments;

[User] List comments that have thumbnail LIKE 'A%'.

[Assistant] SELECT published_at, thumbnail, created_at FROM socialmedia.comments WHERE thumbnail LIKE 'A%';

[User] Can you order these by created_at ascending?

[Assistant] SELECT published_at, thumbnail, created_at FROM socialmedia.comments WHERE thumbnail LIKE 'A%' ORDER BY created_at ASC;


[User] Retrieve updated_at, created_at, visibility for every post.

[Assistant] SELECT updated_at, created_at, visibility FROM socialmedia.posts;

[User] Find posts created yesterday.

[Assistant] SELECT updated_at, created_at, visibility FROM socialmedia.posts WHERE created_at = CURRENT_DATE - INTERVAL '1 day';

[User] Show the results sorted by subject ascending.

[Assistant] SELECT updated_at, created_at, visibility FROM socialmedia.posts WHERE created_at = CURRENT_DATE - INTERVAL '1 day' ORDER BY subject ASC;


[User] List all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] What created_at, description, comment_id, updated_at do we have for comments and their associated posts?

[Assistant] SELECT *, posts.comment_id, posts.updated_at FROM socialmedia.comments JOIN socialmedia.posts ON comments.post_id = posts.id;

[User] Count the number of comments in each thumbnail category.

[Assistant] SELECT thumbnail, COUNT(*) AS count FROM socialmedia.comments GROUP BY thumbnail ORDER BY count DESC;


[User] List all posts.

[Assistant] SELECT * FROM socialmedia.posts;

[User] Get posts that match updated_at > '2023-01-01'.

[Assistant] SELECT * FROM socialmedia.posts WHERE updated_at > '2023-01-01';

[User] Count the number of posts in each updated_at category.

[Assistant] SELECT updated_at, COUNT(*) AS count FROM socialmedia.posts GROUP BY updated_at ORDER BY count DESC;


[User] Retrieve all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] Find comments where format LIKE 'A%'.

[Assistant] SELECT * FROM socialmedia.comments WHERE format LIKE 'A%';

[User] Calculate average of description for each thumbnail in comments.

[Assistant] SELECT thumbnail, AVERAGE(description) AS average_description FROM socialmedia.comments GROUP BY thumbnail;


[User] Retrieve all posts.

[Assistant] SELECT * FROM socialmedia.posts;

[User] Get posts that match image_url LIKE 'A%'.

[Assistant] SELECT * FROM socialmedia.posts WHERE image_url LIKE 'A%';

[User] Get the distribution of posts across different categories values.

[Assistant] SELECT categories, COUNT(*) AS count FROM socialmedia.posts GROUP BY categories ORDER BY count DESC;


[User] Get all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] Sort the results by reply_to_id descending.

[Assistant] SELECT * FROM socialmedia.comments ORDER BY reply_to_id DESC;

[User] Only show the top 5 results.

[Assistant] SELECT * FROM socialmedia.comments ORDER BY reply_to_id DESC LIMIT 5;


[User] What are the subject, reply_to_id, post_id of each comment?

[Assistant] SELECT subject, reply_to_id, post_id FROM socialmedia.comments;

[User] Get comments that match format LIKE 'A%'.

[Assistant] SELECT subject, reply_to_id, post_id FROM socialmedia.comments WHERE format LIKE 'A%';

[User] Get sum of subject by post_id from comments.

[Assistant] SELECT post_id, SUM(subject) AS sum_subject FROM socialmedia.comments GROUP BY post_id;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.grades (
  transaction_id character varying(64) NOT NULL -- unique identifier,
  payment_date timestamp,
  credit character varying(256) NOT NULL,
  reference_number text,
  status character varying(128),
  vendor_id character varying(128) NOT NULL,
  debit character varying(128),
  enrollment_id text -- reference to enrollments.post_id,
  FOREIGN KEY (enrollment_id) REFERENCES enrollments(post_id)
)

CREATE TABLE education.teachers (
  transaction_id character varying(64) NOT NULL -- unique identifier,
  processed_at timestamp,
  completed_at timestamp without time zone,
  approval_status character varying(64) NOT NULL,
  status text,
  subtotal decimal NOT NULL,
  payment_method text NOT NULL,
  enrollment_id text NOT NULL -- reference to enrollments.post_id,
  FOREIGN KEY (enrollment_id) REFERENCES enrollments(post_id)
)

CREATE TABLE education.assignments (
  payment_id text PRIMARY KEY -- unique identifier,
  created_at timestamp,
  reference_number char,
  status character varying(256) NOT NULL,
  payer_id text,
  approval_status character varying(64),
  balance integer,
  exchange_rate text,
  enrollment_id text -- reference to enrollments.post_id,
  FOREIGN KEY (enrollment_id) REFERENCES enrollments(post_id)
)

CREATE TABLE education.enrollments (
  post_id text PRIMARY KEY -- unique identifier,
  published_at date,
  categories character varying(64) NOT NULL,
  image_url character varying(256) NOT NULL,
  author_id varchar NOT NULL,
  visibility text,
  title char NOT NULL,
  content varchar
)

[User] Display all grades.

[Assistant] SELECT * FROM education.grades;

[User] Show the results sorted by reference_number descending.

[Assistant] SELECT * FROM education.grades ORDER BY reference_number DESC;

[User] Return just 5 rows.

[Assistant] SELECT * FROM education.grades ORDER BY reference_number DESC LIMIT 5;


[User] Display all grades.

[Assistant] SELECT * FROM education.grades;

[User] Can you order these by debit ascending?

[Assistant] SELECT * FROM education.grades ORDER BY debit ASC;

[User] Sort the results by transaction_id descending.

[Assistant] SELECT * FROM education.grades ORDER BY transaction_id DESC;


[User] Get all grades.

[Assistant] SELECT * FROM education.grades;

[User] Show the results sorted by status descending.

[Assistant] SELECT * FROM education.grades ORDER BY status DESC;

[User] Show the results sorted by enrollment_id descending.

[Assistant] SELECT * FROM education.grades ORDER BY enrollment_id DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.courses (
  product_id varchar PRIMARY KEY -- unique identifier,
  expires_at timestamp,
  description character varying(256),
  popularity_score character varying(128),
  quantity character varying(256) NOT NULL
)

CREATE TABLE education.enrollments (
  transaction_id character varying(64) NOT NULL -- unique identifier,
  completed_at date,
  traded_at date,
  customer_id varchar -- identifier for customer,
  amount bigint,
  currency character varying(64),
  course_id text NOT NULL -- reference to courses.product_id,
  FOREIGN KEY (course_id) REFERENCES courses(product_id)
)

[User] Display all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Get all enrollments modified within the last hour.

[Assistant] SELECT * FROM education.enrollments WHERE completed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Limit the results to 25 rows.

[Assistant] SELECT * FROM education.enrollments WHERE completed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 25;


[User] Show me all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Order the output by traded_at descending.

[Assistant] SELECT * FROM education.enrollments ORDER BY traded_at DESC;

[User] Sort the results by completed_at ascending.

[Assistant] SELECT * FROM education.enrollments ORDER BY completed_at ASC;


[User] Get all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Show me enrollments that were from last week.

[Assistant] SELECT * FROM education.enrollments WHERE traded_at >= CURRENT_DATE - INTERVAL '7 days';

[User] How many enrollments are there per customer_id?

[Assistant] SELECT customer_id, COUNT(*) AS count FROM education.enrollments GROUP BY customer_id ORDER BY count DESC;


[User] Get all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] List enrollments that have traded_at > '2023-01-01'.

[Assistant] SELECT * FROM education.enrollments WHERE traded_at > '2023-01-01';

[User] Only show the top 50 results.

[Assistant] SELECT * FROM education.enrollments WHERE traded_at > '2023-01-01' LIMIT 50;


[User] Show me customer_id, completed_at, amount for all enrollments.

[Assistant] SELECT customer_id, completed_at, amount FROM education.enrollments;

[User] Retrieve enrollments where transaction_id LIKE 'A%'.

[Assistant] SELECT customer_id, completed_at, amount FROM education.enrollments WHERE transaction_id LIKE 'A%';

[User] Get min of customer_id by course_id from enrollments.

[Assistant] SELECT course_id, MIN(customer_id) AS min_customer_id FROM education.enrollments GROUP BY course_id;


[User] Get transaction_id, course_id, currency from all enrollments.

[Assistant] SELECT transaction_id, course_id, currency FROM education.enrollments;

[User] Show the results sorted by traded_at descending.

[Assistant] SELECT transaction_id, course_id, currency FROM education.enrollments ORDER BY traded_at DESC;

[User] Calculate min of currency for each course_id in enrollments.

[Assistant] SELECT course_id, MIN(currency) AS min_currency FROM education.enrollments GROUP BY course_id;


[User] Retrieve course_id, amount, completed_at for every enrollment.

[Assistant] SELECT course_id, amount, completed_at FROM education.enrollments;

[User] List enrollments with dates created yesterday.

[Assistant] SELECT course_id, amount, completed_at FROM education.enrollments WHERE traded_at = CURRENT_DATE - INTERVAL '1 day';

[User] Show me max of currency grouped by amount for enrollments.

[Assistant] SELECT amount, MAX(currency) AS max_currency FROM education.enrollments GROUP BY amount;


[User] Show me traded_at, completed_at, customer_id for all enrollments.

[Assistant] SELECT traded_at, completed_at, customer_id FROM education.enrollments;

[User] List enrollments with dates created yesterday.

[Assistant] SELECT traded_at, completed_at, customer_id FROM education.enrollments WHERE traded_at = CURRENT_DATE - INTERVAL '1 day';

[User] Calculate min of customer_id for each completed_at in enrollments.

[Assistant] SELECT completed_at, MIN(customer_id) AS min_customer_id FROM education.enrollments GROUP BY completed_at;


[User] Get traded_at, completed_at, currency from all enrollments.

[Assistant] SELECT traded_at, completed_at, currency FROM education.enrollments;

[User] What course_id, currency, quantity, expires_at do we have for enrollments and their associated courses?

[Assistant] SELECT traded_at, completed_at, currency, courses.quantity, courses.expires_at FROM education.enrollments JOIN education.courses ON enrollments.course_id = courses.product_id;

[User] Show me the count of enrollments grouped by amount.

[Assistant] SELECT amount, COUNT(*) AS count FROM education.enrollments GROUP BY amount ORDER BY count DESC;


[User] Show me customer_id, amount, completed_at for all enrollments.

[Assistant] SELECT customer_id, amount, completed_at FROM education.enrollments;

[User] Find enrollments from 2023.

[Assistant] SELECT customer_id, amount, completed_at FROM education.enrollments WHERE completed_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Restrict the output to 100 items.

[Assistant] SELECT customer_id, amount, completed_at FROM education.enrollments WHERE completed_at BETWEEN '2023-01-01' AND '2023-12-31' LIMIT 100;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.departments (
  payment_id character varying(64) NOT NULL -- unique identifier,
  updated_at date,
  credit character varying(256),
  debit varchar NOT NULL,
  verification_status char,
  category character varying(128) NOT NULL,
  reconciliation_status char,
  assignment_id text NOT NULL -- reference to assignments.transaction_id,
  FOREIGN KEY (assignment_id) REFERENCES assignments(transaction_id)
)

CREATE TABLE education.courses (
  sku text PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  created_at date,
  rating character varying(128),
  featured_rank varchar,
  image_url varchar,
  price decimal,
  thumbnail_url text NOT NULL,
  category char NOT NULL,
  assignment_id text NOT NULL -- reference to assignments.transaction_id,
  FOREIGN KEY (assignment_id) REFERENCES assignments(transaction_id)
)

CREATE TABLE education.assignments (
  transaction_id text PRIMARY KEY -- unique identifier,
  traded_at date,
  created_at timestamp without time zone,
  delivery_status character varying(128),
  quantity varchar,
  seller_id character varying(64) -- identifier for seller,
  course_id text NOT NULL -- reference to courses.sku,
  FOREIGN KEY (course_id) REFERENCES courses(sku)
)

[User] Get category, price, created_at from all courses.

[Assistant] SELECT category, price, created_at FROM education.courses;

[User] Find courses where thumbnail_url LIKE 'A%'.

[Assistant] SELECT category, price, created_at FROM education.courses WHERE thumbnail_url LIKE 'A%';

[User] Calculate count of price for each price in courses.

[Assistant] SELECT price, COUNT(price) AS count_price FROM education.courses GROUP BY price;


[User] List created_at, image_url, price from courses.

[Assistant] SELECT created_at, image_url, price FROM education.courses;

[User] Find courses where assignment_id LIKE 'A%'.

[Assistant] SELECT created_at, image_url, price FROM education.courses WHERE assignment_id LIKE 'A%';

[User] How many courses are there per featured_rank?

[Assistant] SELECT featured_rank, COUNT(*) AS count FROM education.courses GROUP BY featured_rank ORDER BY count DESC;


[User] Display all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Retrieve quantity, course_id, assignment_id, image_url showing the relationship between assignments and courses.

[Assistant] SELECT *, courses.assignment_id, courses.image_url FROM education.assignments JOIN education.courses ON assignments.course_id = courses.sku;

[User] Show me sum of traded_at grouped by seller_id for assignments.

[Assistant] SELECT seller_id, SUM(traded_at) AS sum_traded_at FROM education.assignments GROUP BY seller_id;


[User] List created_at, delivery_status, seller_id from assignments.

[Assistant] SELECT created_at, delivery_status, seller_id FROM education.assignments;

[User] Retrieve assignments where the date is older than 6 months.

[Assistant] SELECT created_at, delivery_status, seller_id FROM education.assignments WHERE traded_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Restrict the output to 20 items.

[Assistant] SELECT created_at, delivery_status, seller_id FROM education.assignments WHERE traded_at <= CURRENT_DATE - INTERVAL '6 months' LIMIT 20;


[User] List updated_at, image_url, assignment_id from courses.

[Assistant] SELECT updated_at, image_url, assignment_id FROM education.courses;

[User] List courses that have thumbnail_url LIKE 'A%'.

[Assistant] SELECT updated_at, image_url, assignment_id FROM education.courses WHERE thumbnail_url LIKE 'A%';

[User] What is the sum category for each updated_at in courses?

[Assistant] SELECT updated_at, SUM(category) AS sum_category FROM education.courses GROUP BY updated_at;


[User] Display all courses.

[Assistant] SELECT * FROM education.courses;

[User] Show the results sorted by image_url ascending.

[Assistant] SELECT * FROM education.courses ORDER BY image_url ASC;

[User] Show me the count of courses grouped by featured_rank.

[Assistant] SELECT featured_rank, COUNT(*) AS count FROM education.courses GROUP BY featured_rank ORDER BY count DESC;


[User] Display all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Get assignments that match traded_at > '2023-01-01'.

[Assistant] SELECT * FROM education.assignments WHERE traded_at > '2023-01-01';

[User] What is the min traded_at for each created_at in assignments?

[Assistant] SELECT created_at, MIN(traded_at) AS min_traded_at FROM education.assignments GROUP BY created_at;


[User] Display all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Show the results sorted by course_id ascending.

[Assistant] SELECT * FROM education.assignments ORDER BY course_id ASC;

[User] Restrict the output to 10 items.

[Assistant] SELECT * FROM education.assignments ORDER BY course_id ASC LIMIT 10;


[User] What are the debit, category, payment_id of each department?

[Assistant] SELECT debit, category, payment_id FROM education.departments;

[User] Retrieve departments where the date is created after December 1st, 2023.

[Assistant] SELECT debit, category, payment_id FROM education.departments WHERE updated_at > '2023-12-01';

[User] Count the number of departments in each verification_status category.

[Assistant] SELECT verification_status, COUNT(*) AS count FROM education.departments GROUP BY verification_status ORDER BY count DESC;


[User] Retrieve created_at, seller_id, quantity for every assignment.

[Assistant] SELECT created_at, seller_id, quantity FROM education.assignments;

[User] List assignments with dates from 2023.

[Assistant] SELECT created_at, seller_id, quantity FROM education.assignments WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Show me max of quantity grouped by course_id for assignments.

[Assistant] SELECT course_id, MAX(quantity) AS max_quantity FROM education.assignments GROUP BY course_id;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE restaurant.finances (
  payment_id varchar PRIMARY KEY -- unique identifier,
  payment_date date,
  category character varying(256),
  payee_id char NOT NULL -- identifier for payee,
  invoice_number character varying(256),
  description char,
  debit character varying(128),
  purchase_id text NOT NULL -- reference to purchases.id,
  FOREIGN KEY (purchase_id) REFERENCES purchases(id)
)

CREATE TABLE restaurant.purchases (
  id text PRIMARY KEY -- unique identifier,
  completed_at timestamp without time zone,
  delivery_status char,
  price decimal NOT NULL,
  approval_status char NOT NULL,
  exchange_rate char,
  payment_method text NOT NULL,
  finance_id text -- reference to finances.payment_id,
  FOREIGN KEY (finance_id) REFERENCES finances(payment_id)
)

[User] Get all purchases.

[Assistant] SELECT * FROM restaurant.purchases;

[User] Can you order these by payment_method ascending?

[Assistant] SELECT * FROM restaurant.purchases ORDER BY payment_method ASC;

[User] Return just 25 rows.

[Assistant] SELECT * FROM restaurant.purchases ORDER BY payment_method ASC LIMIT 25;


[User] Show me debit, category, payee_id for all finances.

[Assistant] SELECT debit, category, payee_id FROM restaurant.finances;

[User] Show me finances that were modified within the last hour.

[Assistant] SELECT debit, category, payee_id FROM restaurant.finances WHERE payment_date >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Return just 100 rows.

[Assistant] SELECT debit, category, payee_id FROM restaurant.finances WHERE payment_date >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 100;


[User] List delivery_status, exchange_rate, payment_method from purchases.

[Assistant] SELECT delivery_status, exchange_rate, payment_method FROM restaurant.purchases;

[User] Arrange the results with price in ascending order.

[Assistant] SELECT delivery_status, exchange_rate, payment_method FROM restaurant.purchases ORDER BY price ASC;

[User] Show me the count of purchases grouped by payment_method.

[Assistant] SELECT payment_method, COUNT(*) AS count FROM restaurant.purchases GROUP BY payment_method ORDER BY count DESC;


[User] Retrieve finance_id, price, payment_method for every purchase.

[Assistant] SELECT finance_id, price, payment_method FROM restaurant.purchases;

[User] List purchases that have payment_method LIKE 'A%'.

[Assistant] SELECT finance_id, price, payment_method FROM restaurant.purchases WHERE payment_method LIKE 'A%';

[User] Arrange the results with payment_method in descending order.

[Assistant] SELECT finance_id, price, payment_method FROM restaurant.purchases WHERE payment_method LIKE 'A%' ORDER BY payment_method DESC;


[User] Show me all purchases.

[Assistant] SELECT * FROM restaurant.purchases;

[User] Get all purchases modified within the last hour.

[Assistant] SELECT * FROM restaurant.purchases WHERE completed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] What is the min completed_at for each exchange_rate in purchases?

[Assistant] SELECT exchange_rate, MIN(completed_at) AS min_completed_at FROM restaurant.purchases GROUP BY exchange_rate;


[User] List finance_id, price, completed_at from purchases.

[Assistant] SELECT finance_id, price, completed_at FROM restaurant.purchases;

[User] Sort the results by approval_status ascending.

[Assistant] SELECT finance_id, price, completed_at FROM restaurant.purchases ORDER BY approval_status ASC;

[User] How many purchases are there per payment_method?

[Assistant] SELECT payment_method, COUNT(*) AS count FROM restaurant.purchases GROUP BY payment_method ORDER BY count DESC;


[User] List all finances.

[Assistant] SELECT * FROM restaurant.finances;

[User] What debit, invoice_number, finance_id, delivery_status do we have for finances and their associated purchases?

[Assistant] SELECT *, purchases.finance_id, purchases.delivery_status FROM restaurant.finances JOIN restaurant.purchases ON finances.purchase_id = purchases.id;

[User] How many finances are there per invoice_number?

[Assistant] SELECT invoice_number, COUNT(*) AS count FROM restaurant.finances GROUP BY invoice_number ORDER BY count DESC;


[User] Show me payment_method, price, completed_at for all purchases.

[Assistant] SELECT payment_method, price, completed_at FROM restaurant.purchases;

[User] Get payment_method, delivery_status, description, payee_id by joining purchases with finances.

[Assistant] SELECT payment_method, price, completed_at, finances.description, finances.payee_id FROM restaurant.purchases JOIN restaurant.finances ON purchases.finance_id = finances.payment_id;

[User] Show the results sorted by finance_id ascending.

[Assistant] SELECT payment_method, price, completed_at, finances.description, finances.payee_id FROM restaurant.purchases JOIN restaurant.finances ON purchases.finance_id = finances.payment_id ORDER BY finance_id ASC;


[User] List price, exchange_rate, approval_status from purchases.

[Assistant] SELECT price, exchange_rate, approval_status FROM restaurant.purchases;

[User] Get purchases that match exchange_rate LIKE 'A%'.

[Assistant] SELECT price, exchange_rate, approval_status FROM restaurant.purchases WHERE exchange_rate LIKE 'A%';

[User] What is the max exchange_rate for each price in purchases?

[Assistant] SELECT price, MAX(exchange_rate) AS max_exchange_rate FROM restaurant.purchases GROUP BY price;


[User] Retrieve delivery_status, completed_at, payment_method for every purchase.

[Assistant] SELECT delivery_status, completed_at, payment_method FROM restaurant.purchases;

[User] Retrieve purchases where the date is created after December 1st, 2023.

[Assistant] SELECT delivery_status, completed_at, payment_method FROM restaurant.purchases WHERE completed_at > '2023-12-01';

[User] Show only 100 records.

[Assistant] SELECT delivery_status, completed_at, payment_method FROM restaurant.purchases WHERE completed_at > '2023-12-01' LIMIT 100;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE logistics.sales (
  id integer PRIMARY KEY -- unique identifier,
  processed_at date,
  cancelled_at timestamp,
  discount numeric(38,14),
  quantity character varying(64),
  payment_status character varying(128) NOT NULL,
  store_id integer -- reference to stores.address_id,
  FOREIGN KEY (store_id) REFERENCES stores(address_id)
)

CREATE TABLE logistics.stores (
  address_id integer PRIMARY KEY -- unique identifier,
  last_inspected timestamp,
  address_line1 character varying(256) NOT NULL,
  postal_code char,
  geo_point character varying(64),
  coordinates character varying(256),
  description varchar NOT NULL,
  country char NOT NULL,
  city char,
  sale_id integer -- reference to sales.id,
  FOREIGN KEY (sale_id) REFERENCES sales(id)
)

CREATE TABLE logistics.comments (
  comment_id character varying(64) NOT NULL -- unique identifier,
  edited_at timestamp without time zone,
  body character varying(128),
  image_url text,
  user_id character varying(256) NOT NULL,
  attachment_url text,
  text varchar
)

[User] List quantity, cancelled_at, discount from sales.

[Assistant] SELECT quantity, cancelled_at, discount FROM logistics.sales;

[User] Can you order these by processed_at ascending?

[Assistant] SELECT quantity, cancelled_at, discount FROM logistics.sales ORDER BY processed_at ASC;

[User] Only show the top 5 results.

[Assistant] SELECT quantity, cancelled_at, discount FROM logistics.sales ORDER BY processed_at ASC LIMIT 5;


[User] Display all stores.

[Assistant] SELECT * FROM logistics.stores;

[User] Show me coordinates, postal_code, payment_status, discount from stores and their related sales.

[Assistant] SELECT *, sales.payment_status, sales.discount FROM logistics.stores JOIN logistics.sales ON stores.sale_id = sales.id;

[User] Calculate min of address_line1 for each postal_code in stores.

[Assistant] SELECT postal_code, MIN(address_line1) AS min_address_line1 FROM logistics.stores GROUP BY postal_code;


[User] Show me all stores.

[Assistant] SELECT * FROM logistics.stores;

[User] Show me stores with address_line1 LIKE 'A%'.

[Assistant] SELECT * FROM logistics.stores WHERE address_line1 LIKE 'A%';

[User] How many stores are there per country?

[Assistant] SELECT country, COUNT(*) AS count FROM logistics.stores GROUP BY country ORDER BY count DESC;


[User] Get all sales.

[Assistant] SELECT * FROM logistics.sales;

[User] Show me sales that were from last week.

[Assistant] SELECT * FROM logistics.sales WHERE processed_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Limit the results to 5 rows.

[Assistant] SELECT * FROM logistics.sales WHERE processed_at >= CURRENT_DATE - INTERVAL '7 days' LIMIT 5;


[User] List all sales.

[Assistant] SELECT * FROM logistics.sales;

[User] Get sales that match discount > 76.

[Assistant] SELECT * FROM logistics.sales WHERE discount > 76;

[User] Get max of processed_at by store_id from sales.

[Assistant] SELECT store_id, MAX(processed_at) AS max_processed_at FROM logistics.sales GROUP BY store_id;


[User] Get all sales.

[Assistant] SELECT * FROM logistics.sales;

[User] Get all sales modified within the last hour.

[Assistant] SELECT * FROM logistics.sales WHERE processed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Get sum of payment_status by payment_status from sales.

[Assistant] SELECT payment_status, SUM(payment_status) AS sum_payment_status FROM logistics.sales GROUP BY payment_status;


[User] Retrieve quantity, store_id, payment_status for every sale.

[Assistant] SELECT quantity, store_id, payment_status FROM logistics.sales;

[User] Get sales that match discount > 18.

[Assistant] SELECT quantity, store_id, payment_status FROM logistics.sales WHERE discount > 18;

[User] Get the distribution of sales across different quantity values.

[Assistant] SELECT quantity, COUNT(*) AS count FROM logistics.sales GROUP BY quantity ORDER BY count DESC;


[User] Get all stores.

[Assistant] SELECT * FROM logistics.stores;

[User] Get stores that match geo_point LIKE 'A%'.

[Assistant] SELECT * FROM logistics.stores WHERE geo_point LIKE 'A%';

[User] Group stores by city and show the max of address_line1.

[Assistant] SELECT city, MAX(address_line1) AS max_address_line1 FROM logistics.stores GROUP BY city;


[User] List discount, store_id, processed_at from sales.

[Assistant] SELECT discount, store_id, processed_at FROM logistics.sales;

[User] Find sales created in the last 30 days.

[Assistant] SELECT discount, store_id, processed_at FROM logistics.sales WHERE cancelled_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Only show the top 50 results.

[Assistant] SELECT discount, store_id, processed_at FROM logistics.sales WHERE cancelled_at >= CURRENT_DATE - INTERVAL '30 days' LIMIT 50;


[User] List city, description, country from stores.

[Assistant] SELECT city, description, country FROM logistics.stores;

[User] Show me stores with coordinates LIKE 'A%'.

[Assistant] SELECT city, description, country FROM logistics.stores WHERE coordinates LIKE 'A%';

[User] Show me sum of postal_code grouped by sale_id for stores.

[Assistant] SELECT sale_id, SUM(postal_code) AS sum_postal_code FROM logistics.stores GROUP BY sale_id;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.transactions (
  order_id varchar PRIMARY KEY -- unique identifier,
  processed_at timestamp without time zone,
  payment_status character varying(64),
  exchange_rate char NOT NULL,
  approval_status character varying(128),
  card_type varchar,
  account_id text NOT NULL -- reference to accounts.transaction_id,
  investment_id integer NOT NULL -- reference to investments.person_id,
  FOREIGN KEY (account_id) REFERENCES accounts(transaction_id),
  FOREIGN KEY (investment_id) REFERENCES investments(person_id)
)

CREATE TABLE finance.investments (
  person_id integer PRIMARY KEY -- unique identifier,
  last_active timestamp,
  state text NOT NULL,
  website text,
  country char,
  transaction_id text -- reference to transactions.order_id,
  FOREIGN KEY (transaction_id) REFERENCES transactions(order_id)
)

CREATE TABLE finance.payments (
  invoice_id integer PRIMARY KEY -- unique identifier,
  cancelled_at date,
  created_at timestamp without time zone,
  status character varying(256),
  subtotal decimal,
  price numeric(38,14)
)

CREATE TABLE finance.accounts (
  transaction_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  currency character varying(128),
  description text,
  debit char,
  customer_id character varying(64) -- identifier for customer,
  verification_status varchar,
  category varchar
)

[User] Get all investments.

[Assistant] SELECT * FROM finance.investments;

[User] Find investments modified within the last hour.

[Assistant] SELECT * FROM finance.investments WHERE last_active >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Limit the results to 10 rows.

[Assistant] SELECT * FROM finance.investments WHERE last_active >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 10;


[User] Show me all investments.

[Assistant] SELECT * FROM finance.investments;

[User] Retrieve investments where transaction_id LIKE 'A%'.

[Assistant] SELECT * FROM finance.investments WHERE transaction_id LIKE 'A%';

[User] Can you order these by state descending?

[Assistant] SELECT * FROM finance.investments WHERE transaction_id LIKE 'A%' ORDER BY state DESC;


[User] Retrieve all transactions.

[Assistant] SELECT * FROM finance.transactions;

[User] Can you order these by approval_status descending?

[Assistant] SELECT * FROM finance.transactions ORDER BY approval_status DESC;

[User] Get sum of processed_at by investment_id from transactions.

[Assistant] SELECT investment_id, SUM(processed_at) AS sum_processed_at FROM finance.transactions GROUP BY investment_id;


[User] Retrieve country, website, last_active for every investment.

[Assistant] SELECT country, website, last_active FROM finance.investments;

[User] Show the results sorted by last_active ascending.

[Assistant] SELECT country, website, last_active FROM finance.investments ORDER BY last_active ASC;

[User] Arrange the results with state in descending order.

[Assistant] SELECT country, website, last_active FROM finance.investments ORDER BY state DESC;


[User] What are the transaction_id, country, website of each investment?

[Assistant] SELECT transaction_id, country, website FROM finance.investments;

[User] Show me investments with last_active > '2023-01-01'.

[Assistant] SELECT transaction_id, country, website FROM finance.investments WHERE last_active > '2023-01-01';

[User] Return just 100 rows.

[Assistant] SELECT transaction_id, country, website FROM finance.investments WHERE last_active > '2023-01-01' LIMIT 100;


[User] Show me all investments.

[Assistant] SELECT * FROM finance.investments;

[User] Arrange the results with transaction_id in ascending order.

[Assistant] SELECT * FROM finance.investments ORDER BY transaction_id ASC;

[User] Get the distribution of investments across different website values.

[Assistant] SELECT website, COUNT(*) AS count FROM finance.investments GROUP BY website ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE events.locations (
  location_id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp without time zone,
  parking_available text NOT NULL,
  coordinates char NOT NULL,
  accessibility character varying(64),
  longitude text,
  customer_id integer NOT NULL -- reference to customers.user_id,
  FOREIGN KEY (customer_id) REFERENCES customers(user_id)
)

CREATE TABLE events.customers (
  user_id integer PRIMARY KEY -- unique identifier,
  last_active date,
  website text,
  status text,
  zip_code character varying(256),
  birth_date timestamp,
  email varchar,
  account_status character varying(128)
)

CREATE TABLE events.articles (
  content_id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp without time zone,
  description text NOT NULL,
  reply_to_id char NOT NULL -- identifier for reply_to,
  thumbnail char
)

[User] List customer_id, accessibility, location_id from locations.

[Assistant] SELECT customer_id, accessibility, location_id FROM events.locations;

[User] Show me parking_available, customer_id, status, email from locations and their related customers.

[Assistant] SELECT customer_id, accessibility, location_id, customers.status, customers.email FROM events.locations JOIN events.customers ON locations.customer_id = customers.user_id;

[User] Get the distribution of locations across different longitude values.

[Assistant] SELECT longitude, COUNT(*) AS count FROM events.locations GROUP BY longitude ORDER BY count DESC;


[User] Get created_at, location_id, parking_available from all locations.

[Assistant] SELECT created_at, location_id, parking_available FROM events.locations;

[User] List longitude, coordinates, account_status, email for each location along with their customer information.

[Assistant] SELECT created_at, location_id, parking_available, customers.account_status, customers.email FROM events.locations JOIN events.customers ON locations.customer_id = customers.user_id;

[User] Group locations by location_id and show the average of created_at.

[Assistant] SELECT location_id, AVERAGE(created_at) AS average_created_at FROM events.locations GROUP BY location_id;


[User] Show me all locations.

[Assistant] SELECT * FROM events.locations;

[User] List locations with dates created in the last 30 days.

[Assistant] SELECT * FROM events.locations WHERE created_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Get the distribution of locations across different created_at values.

[Assistant] SELECT created_at, COUNT(*) AS count FROM events.locations GROUP BY created_at ORDER BY count DESC;