[User] List subtotal, customer_id, exchange_rate from purchases.

[Assistant] SELECT subtotal, customer_id, exchange_rate FROM banking.purchases;

[User] List cancelled_at, exchange_rate, city, subscription_id for each purchase along with their customer information.

[Assistant] SELECT subtotal, customer_id, exchange_rate, customers.city, customers.subscription_id FROM banking.purchases JOIN banking.customers ON purchases.customer_id = customers.employee_id;

[User] Show only 5 records.

[Assistant] SELECT subtotal, customer_id, exchange_rate, customers.city, customers.subscription_id FROM banking.purchases JOIN banking.customers ON purchases.customer_id = customers.employee_id LIMIT 5;


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 banking.customers (
  employee_id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  last_active timestamp without time zone,
  city character varying(256),
  age text NOT NULL,
  language character varying(128) NOT NULL,
  profile_picture_url character varying(128),
  subscription_id integer NOT NULL -- reference to subscriptions.transaction_id,
  FOREIGN KEY (subscription_id) REFERENCES subscriptions(transaction_id)
)

CREATE TABLE banking.subscriptions (
  transaction_id integer PRIMARY KEY -- unique identifier,
  payment_date timestamp without time zone,
  notes text,
  exchange_rate varchar,
  verification_status text,
  payee_id char NOT NULL -- identifier for payee,
  customer_id text -- reference to customers.employee_id,
  FOREIGN KEY (customer_id) REFERENCES customers(employee_id)
)

CREATE TABLE banking.purchases (
  transaction_id text PRIMARY KEY -- unique identifier,
  cancelled_at timestamp,
  status varchar,
  subtotal numeric NOT NULL,
  exchange_rate char,
  customer_id text NOT NULL -- reference to customers.employee_id,
  FOREIGN KEY (customer_id) REFERENCES customers(employee_id)
)

[User] Show me all subscriptions.

[Assistant] SELECT * FROM banking.subscriptions;

[User] Get notes, payment_date, city, language by joining subscriptions with customers.

[Assistant] SELECT *, customers.city, customers.language FROM banking.subscriptions JOIN banking.customers ON subscriptions.customer_id = customers.employee_id;

[User] Group subscriptions by notes and show the max of payment_date.

[Assistant] SELECT notes, MAX(payment_date) AS max_payment_date FROM banking.subscriptions GROUP BY notes;


[User] Get all subscriptions.

[Assistant] SELECT * FROM banking.subscriptions;

[User] Get subscriptions that match customer_id LIKE 'A%'.

[Assistant] SELECT * FROM banking.subscriptions WHERE customer_id LIKE 'A%';

[User] Limit the results to 50 rows.

[Assistant] SELECT * FROM banking.subscriptions WHERE customer_id LIKE 'A%' LIMIT 50;


[User] List cancelled_at, status, subtotal from purchases.

[Assistant] SELECT cancelled_at, status, subtotal FROM banking.purchases;

[User] Retrieve purchases where exchange_rate LIKE 'A%'.

[Assistant] SELECT cancelled_at, status, subtotal FROM banking.purchases WHERE exchange_rate LIKE 'A%';

[User] Tally up purchases by cancelled_at.

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


[User] Show me exchange_rate, customer_id, verification_status for all subscriptions.

[Assistant] SELECT exchange_rate, customer_id, verification_status FROM banking.subscriptions;

[User] Can you order these by exchange_rate descending?

[Assistant] SELECT exchange_rate, customer_id, verification_status FROM banking.subscriptions ORDER BY exchange_rate DESC;

[User] Group subscriptions by notes and show the sum of notes.

[Assistant] SELECT notes, SUM(notes) AS sum_notes FROM banking.subscriptions GROUP BY notes;


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.products (
  sku varchar PRIMARY KEY -- unique identifier,
  published_at timestamp without time zone,
  expires_at date,
  media_url character varying(256),
  discount numeric,
  image_url text,
  shippin_id integer -- reference to shipping.post_id,
  FOREIGN KEY (shippin_id) REFERENCES shipping(post_id)
)

CREATE TABLE e-commerce.categories (
  id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp,
  accessibility character varying(256),
  timezone text,
  state text
)

CREATE TABLE e-commerce.inventory (
  sku character varying(64) NOT NULL -- unique identifier,
  expires_at timestamp without time zone,
  description character varying(128),
  rating character varying(64),
  available char,
  video_url varchar NOT NULL -- identifier for video_url,
  title character varying(64),
  name varchar
)

CREATE TABLE e-commerce.shipping (
  post_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  published_at date,
  user_id character varying(128),
  categories character varying(128),
  attachment_url text,
  reply_to_id character varying(256) -- identifier for reply_to,
  keywords character varying(128) NOT NULL,
  rating char
)

[User] Retrieve shippin_id, published_at, expires_at for every product.

[Assistant] SELECT shippin_id, published_at, expires_at FROM e-commerce.products;

[User] Order the output by expires_at ascending.

[Assistant] SELECT shippin_id, published_at, expires_at FROM e-commerce.products ORDER BY expires_at ASC;

[User] Sort the results by discount descending.

[Assistant] SELECT shippin_id, published_at, expires_at FROM e-commerce.products ORDER BY discount DESC;


[User] Get all products.

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

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

[Assistant] SELECT * FROM e-commerce.products ORDER BY shippin_id DESC;

[User] What is the max discount for each image_url in products?

[Assistant] SELECT image_url, MAX(discount) AS max_discount FROM e-commerce.products GROUP BY image_url;


[User] Get all products.

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

[User] Sort the results by expires_at ascending.

[Assistant] SELECT * FROM e-commerce.products ORDER BY expires_at ASC;

[User] Only show the top 20 results.

[Assistant] SELECT * FROM e-commerce.products ORDER BY expires_at ASC LIMIT 20;


[User] Retrieve all products.

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

[User] Get products that match media_url LIKE 'A%'.

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

[User] Show me count of discount grouped by media_url for products.

[Assistant] SELECT media_url, COUNT(discount) AS count_discount FROM e-commerce.products GROUP BY media_url;


[User] Show me image_url, expires_at, shippin_id for all products.

[Assistant] SELECT image_url, expires_at, shippin_id FROM e-commerce.products;

[User] List products that have image_url LIKE 'A%'.

[Assistant] SELECT image_url, expires_at, shippin_id FROM e-commerce.products WHERE image_url LIKE 'A%';

[User] Only show the top 15 results.

[Assistant] SELECT image_url, expires_at, shippin_id FROM e-commerce.products WHERE image_url LIKE 'A%' LIMIT 15;


[User] Display all products.

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

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

[Assistant] SELECT * FROM e-commerce.products WHERE expires_at <= CURRENT_DATE - INTERVAL '6 months';

[User] How many products are there per expires_at?

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


[User] Retrieve all products.

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

[User] Order the output by shippin_id descending.

[Assistant] SELECT * FROM e-commerce.products ORDER BY shippin_id DESC;

[User] Order the output by expires_at ascending.

[Assistant] SELECT * FROM e-commerce.products ORDER BY expires_at ASC;


[User] Display all products.

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

[User] Sort the results by published_at ascending.

[Assistant] SELECT * FROM e-commerce.products ORDER BY published_at ASC;

[User] Can you order these by expires_at ascending?

[Assistant] SELECT * FROM e-commerce.products ORDER BY expires_at ASC;


[User] List all products.

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

[User] Can you order these by image_url ascending?

[Assistant] SELECT * FROM e-commerce.products ORDER BY image_url ASC;

[User] Show me the count of products grouped by discount.

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


[User] List all products.

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

[User] Get all products between January and March.

[Assistant] SELECT * FROM e-commerce.products WHERE expires_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Tally up products by expires_at.

[Assistant] SELECT expires_at, COUNT(*) AS count FROM e-commerce.products GROUP BY expires_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 healthcare.billing (
  transaction_id varchar PRIMARY KEY -- unique identifier,
  payment_date timestamp,
  created_at timestamp,
  status character varying(128) NOT NULL,
  amount decimal,
  description character varying(128),
  payee_id varchar,
  doctor_id text -- reference to doctors.user_id,
  FOREIGN KEY (doctor_id) REFERENCES doctors(user_id)
)

CREATE TABLE healthcare.departments (
  sku varchar PRIMARY KEY -- unique identifier,
  expires_at date,
  rating varchar NOT NULL,
  thumbnail_url character varying(128),
  billin_id text -- reference to billing.transaction_id,
  FOREIGN KEY (billin_id) REFERENCES billing(transaction_id)
)

CREATE TABLE healthcare.patients (
  customer_id varchar PRIMARY KEY -- unique identifier,
  joined_at date,
  is_verified bit,
  language character varying(128) NOT NULL,
  last_name text,
  api_key character varying(256),
  salt char,
  department_id text -- reference to departments.sku,
  FOREIGN KEY (department_id) REFERENCES departments(sku)
)

CREATE TABLE healthcare.doctors (
  user_id text PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  is_verified boolean,
  token text NOT NULL,
  salt char NOT NULL,
  full_name character varying(256),
  department_id text NOT NULL -- reference to departments.sku,
  patient_id text NOT NULL -- reference to patients.customer_id,
  FOREIGN KEY (department_id) REFERENCES departments(sku),
  FOREIGN KEY (patient_id) REFERENCES patients(customer_id)
)

[User] Show me all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

[User] Can you order these by token descending?

[Assistant] SELECT * FROM healthcare.doctors ORDER BY token DESC;

[User] Tally up doctors by patient_id.

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


[User] Retrieve all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

[User] Get doctors that match salt LIKE 'A%'.

[Assistant] SELECT * FROM healthcare.doctors WHERE salt LIKE 'A%';

[User] Tally up doctors by token.

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


[User] Display all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] Find patients from 2023.

[Assistant] SELECT * FROM healthcare.patients WHERE joined_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Show the results sorted by is_verified descending.

[Assistant] SELECT * FROM healthcare.patients WHERE joined_at BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY is_verified 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.loans (
  store_id varchar PRIMARY KEY -- unique identifier,
  last_inspected timestamp,
  timezone text,
  latitude character varying(128),
  location_lat char NOT NULL,
  longitude character varying(128) NOT NULL,
  account_id text NOT NULL -- reference to accounts.account_id,
  FOREIGN KEY (account_id) REFERENCES accounts(account_id)
)

CREATE TABLE finance.audits (
  id integer PRIMARY KEY -- unique identifier,
  processed_at timestamp,
  category character varying(128),
  reconciliation_status text,
  reference_number character varying(256),
  loan_id text -- reference to loans.store_id,
  account_id text -- reference to accounts.account_id,
  FOREIGN KEY (loan_id) REFERENCES loans(store_id),
  FOREIGN KEY (account_id) REFERENCES accounts(account_id)
)

CREATE TABLE finance.accounts (
  account_id text PRIMARY KEY -- unique identifier,
  due_date timestamp,
  invoice_number text,
  approval_status char,
  description character varying(128),
  currency varchar,
  payer_id character varying(256) NOT NULL,
  status char NOT NULL,
  verification_status char NOT NULL
)

[User] Retrieve account_id, loan_id, reconciliation_status for every audit.

[Assistant] SELECT account_id, loan_id, reconciliation_status FROM finance.audits;

[User] Get category, reference_number, timezone, account_id by joining audits with loans.

[Assistant] SELECT account_id, loan_id, reconciliation_status, loans.timezone, loans.account_id FROM finance.audits JOIN finance.loans ON audits.loan_id = loans.store_id;

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

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


[User] Show me reference_number, account_id, category for all audits.

[Assistant] SELECT reference_number, account_id, category FROM finance.audits;

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

[Assistant] SELECT reference_number, account_id, category FROM finance.audits ORDER BY category ASC;

[User] Calculate average of category for each reference_number in audits.

[Assistant] SELECT reference_number, AVERAGE(category) AS average_category FROM finance.audits GROUP BY reference_number;


[User] Show me last_inspected, account_id, timezone for all loans.

[Assistant] SELECT last_inspected, account_id, timezone FROM finance.loans;

[User] Order the output by latitude ascending.

[Assistant] SELECT last_inspected, account_id, timezone FROM finance.loans ORDER BY latitude ASC;

[User] Restrict the output to 5 items.

[Assistant] SELECT last_inspected, account_id, timezone FROM finance.loans ORDER BY latitude ASC LIMIT 5;


[User] Get latitude, account_id, last_inspected from all loans.

[Assistant] SELECT latitude, account_id, last_inspected FROM finance.loans;

[User] Show me loans that were between January and March.

[Assistant] SELECT latitude, account_id, last_inspected FROM finance.loans WHERE last_inspected BETWEEN '2023-01-01' AND '2023-03-31';

[User] Tally up loans by longitude.

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


[User] List all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Get all audits created after December 1st, 2023.

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

[User] What is the average category for each reference_number in audits?

[Assistant] SELECT reference_number, AVERAGE(category) AS average_category FROM finance.audits GROUP BY reference_number;


[User] List all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Retrieve account_id, reference_number, latitude, account_id showing the relationship between audits and loans.

[Assistant] SELECT *, loans.latitude, loans.account_id FROM finance.audits JOIN finance.loans ON audits.loan_id = loans.store_id;

[User] Group audits by reference_number and show the sum of account_id.

[Assistant] SELECT reference_number, SUM(account_id) AS sum_account_id FROM finance.audits GROUP BY reference_number;


[User] What are the location_lat, latitude, last_inspected of each loan?

[Assistant] SELECT location_lat, latitude, last_inspected FROM finance.loans;

[User] Retrieve longitude, latitude, due_date, verification_status showing the relationship between loans and accounts.

[Assistant] SELECT location_lat, latitude, last_inspected, accounts.due_date, accounts.verification_status FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id;

[User] Show only 15 records.

[Assistant] SELECT location_lat, latitude, last_inspected, accounts.due_date, accounts.verification_status FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id LIMIT 15;


[User] Get all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Get loans that match latitude LIKE 'A%'.

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

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

[Assistant] SELECT * FROM finance.loans WHERE latitude LIKE 'A%' ORDER BY timezone DESC;


[User] What are the category, loan_id, processed_at of each audit?

[Assistant] SELECT category, loan_id, processed_at FROM finance.audits;

[User] Show me audits with category LIKE 'A%'.

[Assistant] SELECT category, loan_id, processed_at FROM finance.audits WHERE category LIKE 'A%';

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

[Assistant] SELECT category, loan_id, processed_at FROM finance.audits WHERE category LIKE 'A%' ORDER BY category DESC;


[User] Get latitude, timezone, last_inspected from all loans.

[Assistant] SELECT latitude, timezone, last_inspected FROM finance.loans;

[User] Find loans where last_inspected > '2023-01-01'.

[Assistant] SELECT latitude, timezone, last_inspected FROM finance.loans WHERE last_inspected > '2023-01-01';

[User] How many loans are there per latitude?

[Assistant] SELECT latitude, COUNT(*) AS count FROM finance.loans GROUP BY latitude 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 tradingplatform.metadata (
  payment_id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp without time zone,
  updated_at timestamp,
  balance numeric NOT NULL,
  customer_id char -- identifier for customer,
  category character varying(64),
  description character varying(256),
  reconciliation_status character varying(128) NOT NULL,
  notification_id text NOT NULL -- reference to notifications.transaction_id,
  wallet_id text NOT NULL -- reference to wallets.transaction_id,
  FOREIGN KEY (notification_id) REFERENCES notifications(transaction_id),
  FOREIGN KEY (wallet_id) REFERENCES wallets(transaction_id)
)

CREATE TABLE tradingplatform.notifications (
  transaction_id text PRIMARY KEY -- unique identifier,
  completed_at timestamp without time zone,
  updated_at date,
  customer_id character varying(128),
  discount numeric(38,14),
  approval_status character varying(128),
  subtotal integer,
  quantity varchar
)

CREATE TABLE tradingplatform.wallets (
  transaction_id varchar PRIMARY KEY -- unique identifier,
  payment_date date,
  balance smallint,
  credit text,
  verification_status character varying(128),
  invoice_number character varying(256) NOT NULL,
  approval_status character varying(256),
  reconciliation_status character varying(128),
  notification_id text -- reference to notifications.transaction_id,
  FOREIGN KEY (notification_id) REFERENCES notifications(transaction_id)
)

[User] Display all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] Find metadata where category LIKE 'A%'.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE category LIKE 'A%';

[User] Show the results sorted by reconciliation_status descending.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE category LIKE 'A%' ORDER BY reconciliation_status 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 insurance.content (
  content_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  created_at date,
  thumbnail character varying(256) NOT NULL,
  body char,
  visibility char NOT NULL,
  user_id character varying(128) -- identifier for user,
  score text,
  views character varying(256)
)

CREATE TABLE insurance.payments (
  invoice_id character varying(64) NOT NULL -- unique identifier,
  payment_date timestamp,
  customer_id character varying(128) -- identifier for customer,
  notes text NOT NULL,
  payer_id varchar -- identifier for payer,
  approval_status character varying(256) NOT NULL,
  description character varying(128),
  debit character varying(64) NOT NULL,
  conten_id integer -- reference to content.content_id,
  client_id text NOT NULL -- reference to clients.id,
  FOREIGN KEY (conten_id) REFERENCES content(content_id),
  FOREIGN KEY (client_id) REFERENCES clients(id)
)

CREATE TABLE insurance.clients (
  id varchar PRIMARY KEY -- unique identifier,
  last_active timestamp without time zone,
  created_at timestamp,
  account_status text NOT NULL,
  phone varchar,
  display_name char NOT NULL,
  birth_date timestamp without time zone,
  conten_id integer NOT NULL -- reference to content.content_id,
  FOREIGN KEY (conten_id) REFERENCES content(content_id)
)

[User] Display all payments.

[Assistant] SELECT * FROM insurance.payments;

[User] What debit, client_id, created_at, user_id do we have for payments and their associated content?

[Assistant] SELECT *, content.created_at, content.user_id FROM insurance.payments JOIN insurance.content ON payments.conten_id = content.content_id;

[User] Calculate max of payer_id for each customer_id in payments.

[Assistant] SELECT customer_id, MAX(payer_id) AS max_payer_id FROM insurance.payments GROUP BY customer_id;


[User] Show me account_status, phone, display_name for all clients.

[Assistant] SELECT account_status, phone, display_name FROM insurance.clients;

[User] Show the results sorted by account_status ascending.

[Assistant] SELECT account_status, phone, display_name FROM insurance.clients ORDER BY account_status ASC;

[User] Count the number of clients in each birth_date category.

[Assistant] SELECT birth_date, COUNT(*) AS count FROM insurance.clients GROUP BY birth_date ORDER BY count DESC;


[User] List all clients.

[Assistant] SELECT * FROM insurance.clients;

[User] Show me clients that were between January and March.

[Assistant] SELECT * FROM insurance.clients WHERE created_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] What is the average conten_id for each conten_id in clients?

[Assistant] SELECT conten_id, AVERAGE(conten_id) AS average_conten_id FROM insurance.clients GROUP BY conten_id;


[User] Retrieve all clients.

[Assistant] SELECT * FROM insurance.clients;

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

[Assistant] SELECT * FROM insurance.clients WHERE birth_date >= CURRENT_DATE - INTERVAL '30 days';

[User] Tally up clients by conten_id.

[Assistant] SELECT conten_id, COUNT(*) AS count FROM insurance.clients GROUP BY conten_id ORDER BY count DESC;


[User] Retrieve all payments.

[Assistant] SELECT * FROM insurance.payments;

[User] Can you order these by customer_id ascending?

[Assistant] SELECT * FROM insurance.payments ORDER BY customer_id ASC;

[User] Order the output by payer_id ascending.

[Assistant] SELECT * FROM insurance.payments ORDER BY payer_id ASC;


[User] Display all clients.

[Assistant] SELECT * FROM insurance.clients;

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

[Assistant] SELECT * FROM insurance.clients ORDER BY last_active DESC;

[User] Show me min of birth_date grouped by birth_date for clients.

[Assistant] SELECT birth_date, MIN(birth_date) AS min_birth_date FROM insurance.clients GROUP BY birth_date;


[User] List all payments.

[Assistant] SELECT * FROM insurance.payments;

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

[Assistant] SELECT * FROM insurance.payments WHERE payment_date >= CURRENT_DATE - INTERVAL '7 days';

[User] Show the results sorted by invoice_id descending.

[Assistant] SELECT * FROM insurance.payments WHERE payment_date >= CURRENT_DATE - INTERVAL '7 days' ORDER BY invoice_id DESC;


[User] Show me created_at, birth_date, account_status for all clients.

[Assistant] SELECT created_at, birth_date, account_status FROM insurance.clients;

[User] Get clients that match birth_date > '2023-01-01'.

[Assistant] SELECT created_at, birth_date, account_status FROM insurance.clients WHERE birth_date > '2023-01-01';

[User] What is the count display_name for each display_name in clients?

[Assistant] SELECT display_name, COUNT(display_name) AS count_display_name FROM insurance.clients GROUP BY display_name;


[User] Retrieve birth_date, account_status, last_active for every client.

[Assistant] SELECT birth_date, account_status, last_active FROM insurance.clients;

[User] Retrieve clients where the date is created yesterday.

[Assistant] SELECT birth_date, account_status, last_active FROM insurance.clients WHERE birth_date = CURRENT_DATE - INTERVAL '1 day';

[User] Show only 20 records.

[Assistant] SELECT birth_date, account_status, last_active FROM insurance.clients WHERE birth_date = CURRENT_DATE - INTERVAL '1 day' LIMIT 20;


[User] What are the payer_id, customer_id, debit of each payment?

[Assistant] SELECT payer_id, customer_id, debit FROM insurance.payments;

[User] Find payments older than 6 months.

[Assistant] SELECT payer_id, customer_id, debit FROM insurance.payments WHERE payment_date <= CURRENT_DATE - INTERVAL '6 months';

[User] Show the results sorted by description ascending.

[Assistant] SELECT payer_id, customer_id, debit FROM insurance.payments WHERE payment_date <= CURRENT_DATE - INTERVAL '6 months' ORDER BY description ASC;


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.products (
  item_id varchar PRIMARY KEY -- unique identifier,
  published_at timestamp without time zone,
  updated_at date,
  cost numeric,
  image_url character varying(64) NOT NULL,
  currency character varying(256) NOT NULL,
  subcategory varchar,
  tax_rate text,
  featured_rank varchar
)

CREATE TABLE e-commerce.order_items (
  message_id character varying(64) NOT NULL -- unique identifier,
  published_at timestamp,
  message character varying(128),
  format text,
  keywords character varying(64),
  order_id integer -- reference to orders.order_id,
  FOREIGN KEY (order_id) REFERENCES orders(order_id)
)

CREATE TABLE e-commerce.categories (
  item_id text PRIMARY KEY -- unique identifier,
  expires_at timestamp,
  backorder character varying(256) NOT NULL,
  cost numeric,
  thumbnail_url character varying(256),
  quantity character varying(128)
)

CREATE TABLE e-commerce.orders (
  order_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  currency text,
  payment_method character varying(64),
  status character varying(128),
  discount numeric,
  customer_id character varying(128) NOT NULL,
  approval_status character varying(64),
  quantity character varying(128),
  categorie_id text NOT NULL -- reference to categories.item_id,
  product_id text -- reference to products.item_id,
  FOREIGN KEY (categorie_id) REFERENCES categories(item_id),
  FOREIGN KEY (product_id) REFERENCES products(item_id)
)

[User] List all orders.

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

[User] Show me orders that were older than 6 months.

[Assistant] SELECT * FROM e-commerce.orders WHERE created_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Tally up orders by approval_status.

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


[User] Retrieve all order_items.

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

[User] Get all order_items from last week.

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

[User] What is the min order_id for each keywords in order_items?

[Assistant] SELECT keywords, MIN(order_id) AS min_order_id FROM e-commerce.order_items GROUP BY keywords;


[User] List discount, currency, quantity from orders.

[Assistant] SELECT discount, currency, quantity FROM e-commerce.orders;

[User] Find orders where created_at > '2023-01-01'.

[Assistant] SELECT discount, currency, quantity FROM e-commerce.orders WHERE created_at > '2023-01-01';

[User] Return just 10 rows.

[Assistant] SELECT discount, currency, quantity FROM e-commerce.orders WHERE created_at > '2023-01-01' LIMIT 10;


[User] Display all orders.

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

[User] Find orders where created_at > '2023-01-01'.

[Assistant] SELECT * FROM e-commerce.orders WHERE created_at > '2023-01-01';

[User] Sort the results by status ascending.

[Assistant] SELECT * FROM e-commerce.orders WHERE created_at > '2023-01-01' ORDER BY status ASC;


[User] Show me all order_items.

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

[User] Show the results sorted by message descending.

[Assistant] SELECT * FROM e-commerce.order_items ORDER BY message DESC;

[User] Sort the results by message ascending.

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


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 (
  id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  amount smallint,
  delivery_status character varying(64),
  quantity text,
  card_type character varying(128),
  payment_method char NOT NULL,
  customer_id text NOT NULL -- reference to customers.person_id,
  FOREIGN KEY (customer_id) REFERENCES customers(person_id)
)

CREATE TABLE finance.customers (
  person_id text PRIMARY KEY -- unique identifier,
  joined_at timestamp without time zone,
  updated_at timestamp without time zone,
  age character varying(128),
  status character varying(64) NOT NULL,
  zip_code char,
  last_name char,
  avatar char,
  transaction_id text -- reference to transactions.id,
  FOREIGN KEY (transaction_id) REFERENCES transactions(id)
)

[User] Show me all customers.

[Assistant] SELECT * FROM finance.customers;

[User] Sort the results by transaction_id descending.

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

[User] Show the results sorted by joined_at descending.

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


[User] Show me payment_method, created_at, amount for all transactions.

[Assistant] SELECT payment_method, created_at, amount FROM finance.transactions;

[User] Order the output by customer_id ascending.

[Assistant] SELECT payment_method, created_at, amount FROM finance.transactions ORDER BY customer_id ASC;

[User] Show me max of created_at grouped by created_at for transactions.

[Assistant] SELECT created_at, MAX(created_at) AS max_created_at FROM finance.transactions GROUP BY created_at;


[User] Get delivery_status, customer_id, created_at from all transactions.

[Assistant] SELECT delivery_status, customer_id, created_at FROM finance.transactions;

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

[Assistant] SELECT delivery_status, customer_id, created_at FROM finance.transactions ORDER BY quantity DESC;

[User] Restrict the output to 20 items.

[Assistant] SELECT delivery_status, customer_id, created_at FROM finance.transactions ORDER BY quantity DESC LIMIT 20;


[User] Retrieve all transactions.

[Assistant] SELECT * FROM finance.transactions;

[User] Order the output by payment_method ascending.

[Assistant] SELECT * FROM finance.transactions ORDER BY payment_method ASC;

[User] Restrict the output to 100 items.

[Assistant] SELECT * FROM finance.transactions ORDER BY payment_method ASC LIMIT 100;


[User] Retrieve all customers.

[Assistant] SELECT * FROM finance.customers;

[User] Sort the results by zip_code descending.

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

[User] Can you order these by status ascending?

[Assistant] SELECT * FROM finance.customers ORDER BY status ASC;


[User] What are the joined_at, zip_code, status of each customer?

[Assistant] SELECT joined_at, zip_code, status FROM finance.customers;

[User] What transaction_id, last_name, payment_method, delivery_status do we have for customers and their associated transactions?

[Assistant] SELECT joined_at, zip_code, status, transactions.payment_method, transactions.delivery_status FROM finance.customers JOIN finance.transactions ON customers.transaction_id = transactions.id;

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

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


[User] Display all transactions.

[Assistant] SELECT * FROM finance.transactions;

[User] What quantity, created_at, zip_code, avatar do we have for transactions and their associated customers?

[Assistant] SELECT *, customers.zip_code, customers.avatar FROM finance.transactions JOIN finance.customers ON transactions.customer_id = customers.person_id;

[User] Sort the results by created_at descending.

[Assistant] SELECT *, customers.zip_code, customers.avatar FROM finance.transactions JOIN finance.customers ON transactions.customer_id = customers.person_id ORDER BY created_at DESC;


[User] Retrieve all customers.

[Assistant] SELECT * FROM finance.customers;

[User] List customers with dates from 2023.

[Assistant] SELECT * FROM finance.customers WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] What is the average updated_at for each updated_at in customers?

[Assistant] SELECT updated_at, AVERAGE(updated_at) AS average_updated_at FROM finance.customers GROUP BY updated_at;


[User] List customer_id, created_at, card_type from transactions.

[Assistant] SELECT customer_id, created_at, card_type FROM finance.transactions;

[User] What amount, card_type, avatar, status do we have for transactions and their associated customers?

[Assistant] SELECT customer_id, created_at, card_type, customers.avatar, customers.status FROM finance.transactions JOIN finance.customers ON transactions.customer_id = customers.person_id;

[User] What is the min created_at for each amount in transactions?

[Assistant] SELECT amount, MIN(created_at) AS min_created_at FROM finance.transactions GROUP BY amount;


[User] Retrieve status, last_name, transaction_id for every customer.

[Assistant] SELECT status, last_name, transaction_id FROM finance.customers;

[User] Get customers that match joined_at > '2023-01-01'.

[Assistant] SELECT status, last_name, transaction_id FROM finance.customers WHERE joined_at > '2023-01-01';

[User] Show only 25 records.

[Assistant] SELECT status, last_name, transaction_id FROM finance.customers WHERE joined_at > '2023-01-01' LIMIT 25;


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.prescriptions (
  item_id varchar PRIMARY KEY -- unique identifier,
  expires_at timestamp without time zone,
  created_at date,
  tax_rate character varying(256) NOT NULL,
  backorder character varying(256) NOT NULL,
  thumbnail_url character varying(256),
  billin_id text -- reference to billing.invoice_id,
  FOREIGN KEY (billin_id) REFERENCES billing(invoice_id)
)

CREATE TABLE healthcare.billing (
  invoice_id varchar PRIMARY KEY -- unique identifier,
  processed_at timestamp,
  subtotal numeric,
  exchange_rate character varying(256),
  prescription_id text NOT NULL -- reference to prescriptions.item_id,
  FOREIGN KEY (prescription_id) REFERENCES prescriptions(item_id)
)

[User] What are the exchange_rate, prescription_id, processed_at of each billing?

[Assistant] SELECT exchange_rate, prescription_id, processed_at FROM healthcare.billing;

[User] Get all billing created after December 1st, 2023.

[Assistant] SELECT exchange_rate, prescription_id, processed_at FROM healthcare.billing WHERE processed_at > '2023-12-01';

[User] Show only 50 records.

[Assistant] SELECT exchange_rate, prescription_id, processed_at FROM healthcare.billing WHERE processed_at > '2023-12-01' LIMIT 50;


[User] Display all prescriptions.

[Assistant] SELECT * FROM healthcare.prescriptions;

[User] Order the output by billin_id descending.

[Assistant] SELECT * FROM healthcare.prescriptions ORDER BY billin_id DESC;

[User] Show me the count of prescriptions grouped by thumbnail_url.

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


[User] What are the subtotal, processed_at, prescription_id of each billing?

[Assistant] SELECT subtotal, processed_at, prescription_id FROM healthcare.billing;

[User] List billing with dates older than 6 months.

[Assistant] SELECT subtotal, processed_at, prescription_id FROM healthcare.billing WHERE processed_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Show me the count of billing grouped by subtotal.

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


[User] What are the created_at, backorder, thumbnail_url of each prescription?

[Assistant] SELECT created_at, backorder, thumbnail_url FROM healthcare.prescriptions;

[User] Retrieve expires_at, tax_rate, subtotal, prescription_id showing the relationship between prescriptions and billing.

[Assistant] SELECT created_at, backorder, thumbnail_url, billing.subtotal, billing.prescription_id FROM healthcare.prescriptions JOIN healthcare.billing ON prescriptions.billin_id = billing.invoice_id;

[User] How many prescriptions are there per tax_rate?

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


[User] Retrieve all prescriptions.

[Assistant] SELECT * FROM healthcare.prescriptions;

[User] Can you order these by expires_at ascending?

[Assistant] SELECT * FROM healthcare.prescriptions ORDER BY expires_at ASC;

[User] What is the min thumbnail_url for each billin_id in prescriptions?

[Assistant] SELECT billin_id, MIN(thumbnail_url) AS min_thumbnail_url FROM healthcare.prescriptions GROUP BY billin_id;


[User] Display all billing.

[Assistant] SELECT * FROM healthcare.billing;

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

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

[User] Calculate sum of prescription_id for each prescription_id in billing.

[Assistant] SELECT prescription_id, SUM(prescription_id) AS sum_prescription_id FROM healthcare.billing GROUP BY prescription_id;


[User] Display all billing.

[Assistant] SELECT * FROM healthcare.billing;

[User] Show me billing with prescription_id LIKE 'A%'.

[Assistant] SELECT * FROM healthcare.billing WHERE prescription_id LIKE 'A%';

[User] Show the results sorted by exchange_rate ascending.

[Assistant] SELECT * FROM healthcare.billing WHERE prescription_id LIKE 'A%' ORDER BY exchange_rate ASC;


[User] Show me all prescriptions.

[Assistant] SELECT * FROM healthcare.prescriptions;

[User] Can you order these by thumbnail_url ascending?

[Assistant] SELECT * FROM healthcare.prescriptions ORDER BY thumbnail_url ASC;

[User] Get the distribution of prescriptions across different thumbnail_url values.

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


[User] Show me subtotal, processed_at, exchange_rate for all billing.

[Assistant] SELECT subtotal, processed_at, exchange_rate FROM healthcare.billing;

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

[Assistant] SELECT subtotal, processed_at, exchange_rate FROM healthcare.billing WHERE processed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Show only 25 records.

[Assistant] SELECT subtotal, processed_at, exchange_rate FROM healthcare.billing WHERE processed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 25;


[User] Show me all prescriptions.

[Assistant] SELECT * FROM healthcare.prescriptions;

[User] List prescriptions that have billin_id LIKE 'A%'.

[Assistant] SELECT * FROM healthcare.prescriptions WHERE billin_id LIKE 'A%';

[User] Order the output by created_at ascending.

[Assistant] SELECT * FROM healthcare.prescriptions WHERE billin_id LIKE 'A%' ORDER BY created_at ASC;


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.categories (
  person_id character varying(64) NOT NULL -- unique identifier,
  updated_at date,
  age character varying(128),
  birth_date timestamp without time zone,
  city text,
  membership_level char,
  status char
)

CREATE TABLE e-commerce.order_items (
  user_id character varying(64) NOT NULL -- unique identifier,
  joined_at date,
  username text,
  profile_picture_url character varying(128),
  gender text,
  display_name text NOT NULL
)

[User] Get profile_picture_url, username, joined_at from all order_items.

[Assistant] SELECT profile_picture_url, username, joined_at FROM e-commerce.order_items;

[User] Retrieve order_items where user_id LIKE 'A%'.

[Assistant] SELECT profile_picture_url, username, joined_at FROM e-commerce.order_items WHERE user_id LIKE 'A%';

[User] How many order_items are there per joined_at?

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


[User] Retrieve updated_at, person_id, birth_date for every categorie.

[Assistant] SELECT updated_at, person_id, birth_date FROM e-commerce.categories;

[User] Sort the results by person_id ascending.

[Assistant] SELECT updated_at, person_id, birth_date FROM e-commerce.categories ORDER BY person_id ASC;

[User] How many categories are there per membership_level?

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


[User] List user_id, display_name, joined_at from order_items.

[Assistant] SELECT user_id, display_name, joined_at FROM e-commerce.order_items;

[User] Show me order_items with display_name LIKE 'A%'.

[Assistant] SELECT user_id, display_name, joined_at FROM e-commerce.order_items WHERE display_name LIKE 'A%';

[User] Get average of profile_picture_url by user_id from order_items.

[Assistant] SELECT user_id, AVERAGE(profile_picture_url) AS average_profile_picture_url FROM e-commerce.order_items GROUP BY user_id;


[User] Retrieve joined_at, profile_picture_url, display_name for every order_item.

[Assistant] SELECT joined_at, profile_picture_url, display_name FROM e-commerce.order_items;

[User] Retrieve order_items where gender LIKE 'A%'.

[Assistant] SELECT joined_at, profile_picture_url, display_name FROM e-commerce.order_items WHERE gender LIKE 'A%';

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

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


[User] Retrieve all categories.

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

[User] List categories with dates from last week.

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

[User] How many categories are there per city?

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


[User] Show me age, person_id, city for all categories.

[Assistant] SELECT age, person_id, city FROM e-commerce.categories;

[User] Retrieve categories where updated_at > '2023-01-01'.

[Assistant] SELECT age, person_id, city FROM e-commerce.categories WHERE updated_at > '2023-01-01';

[User] Get count of membership_level by person_id from categories.

[Assistant] SELECT person_id, COUNT(membership_level) AS count_membership_level FROM e-commerce.categories GROUP BY person_id;


[User] List username, display_name, joined_at from order_items.

[Assistant] SELECT username, display_name, joined_at FROM e-commerce.order_items;

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

[Assistant] SELECT username, display_name, joined_at FROM e-commerce.order_items WHERE joined_at > '2023-01-01';

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

[Assistant] SELECT username, display_name, joined_at FROM e-commerce.order_items WHERE joined_at > '2023-01-01' ORDER BY display_name ASC;


[User] Display all order_items.

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

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

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

[User] Calculate min of user_id for each profile_picture_url in order_items.

[Assistant] SELECT profile_picture_url, MIN(user_id) AS min_user_id FROM e-commerce.order_items GROUP BY profile_picture_url;


[User] Retrieve user_id, gender, profile_picture_url for every order_item.

[Assistant] SELECT user_id, gender, profile_picture_url FROM e-commerce.order_items;

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

[Assistant] SELECT user_id, gender, profile_picture_url FROM e-commerce.order_items WHERE joined_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Order the output by joined_at ascending.

[Assistant] SELECT user_id, gender, profile_picture_url FROM e-commerce.order_items WHERE joined_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY joined_at ASC;


[User] List status, person_id, birth_date from categories.

[Assistant] SELECT status, person_id, birth_date FROM e-commerce.categories;

[User] List categories with dates created yesterday.

[Assistant] SELECT status, person_id, birth_date FROM e-commerce.categories WHERE birth_date = CURRENT_DATE - INTERVAL '1 day';

[User] Return just 20 rows.

[Assistant] SELECT status, person_id, birth_date FROM e-commerce.categories WHERE birth_date = CURRENT_DATE - INTERVAL '1 day' LIMIT 20;


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 (
  payment_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  category char,
  invoice_number character varying(128) NOT NULL,
  customer_id character varying(128) NOT NULL,
  enrollment_id text -- reference to enrollments.payment_id,
  FOREIGN KEY (enrollment_id) REFERENCES enrollments(payment_id)
)

CREATE TABLE education.departments (
  sku character varying(64) NOT NULL -- unique identifier,
  created_at timestamp,
  manufacturer text,
  backorder character varying(128) NOT NULL,
  title varchar,
  course_id text NOT NULL -- reference to courses.id,
  FOREIGN KEY (course_id) REFERENCES courses(id)
)

CREATE TABLE education.courses (
  id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  manufacturer character varying(64),
  quantity character varying(128),
  popularity_score character varying(128) NOT NULL,
  cost numeric(38,14)
)

CREATE TABLE education.enrollments (
  payment_id text PRIMARY KEY -- unique identifier,
  cancelled_at date,
  traded_at date,
  subtotal numeric(38,14) NOT NULL,
  card_type character varying(128),
  fee character varying(64) NOT NULL
)

[User] Show me all grades.

[Assistant] SELECT * FROM education.grades;

[User] Sort the results by category ascending.

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

[User] Order the output by enrollment_id descending.

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


[User] Show me manufacturer, title, course_id for all departments.

[Assistant] SELECT manufacturer, title, course_id FROM education.departments;

[User] Show me departments that were from 2023.

[Assistant] SELECT manufacturer, title, course_id FROM education.departments WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Show me min of title grouped by created_at for departments.

[Assistant] SELECT created_at, MIN(title) AS min_title FROM education.departments GROUP BY created_at;


[User] Retrieve category, customer_id, invoice_number for every grade.

[Assistant] SELECT category, customer_id, invoice_number FROM education.grades;

[User] Show me grades with customer_id LIKE 'A%'.

[Assistant] SELECT category, customer_id, invoice_number FROM education.grades WHERE customer_id LIKE 'A%';

[User] How many grades are there per customer_id?

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


[User] Display all departments.

[Assistant] SELECT * FROM education.departments;

[User] Find departments where course_id LIKE 'A%'.

[Assistant] SELECT * FROM education.departments WHERE course_id LIKE 'A%';

[User] Show me sum of course_id grouped by manufacturer for departments.

[Assistant] SELECT manufacturer, SUM(course_id) AS sum_course_id FROM education.departments GROUP BY manufacturer;


[User] Get created_at, backorder, manufacturer from all departments.

[Assistant] SELECT created_at, backorder, manufacturer FROM education.departments;

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

[Assistant] SELECT created_at, backorder, manufacturer FROM education.departments WHERE created_at > '2023-12-01';

[User] Only show the top 15 results.

[Assistant] SELECT created_at, backorder, manufacturer FROM education.departments WHERE created_at > '2023-12-01' LIMIT 15;


[User] What are the enrollment_id, invoice_number, updated_at of each grade?

[Assistant] SELECT enrollment_id, invoice_number, updated_at FROM education.grades;

[User] Retrieve grades where the date is created yesterday.

[Assistant] SELECT enrollment_id, invoice_number, updated_at FROM education.grades WHERE updated_at = CURRENT_DATE - INTERVAL '1 day';

[User] Sort the results by customer_id descending.

[Assistant] SELECT enrollment_id, invoice_number, updated_at FROM education.grades WHERE updated_at = CURRENT_DATE - INTERVAL '1 day' ORDER BY customer_id DESC;


[User] Retrieve customer_id, updated_at, enrollment_id for every grade.

[Assistant] SELECT customer_id, updated_at, enrollment_id FROM education.grades;

[User] Show me grades that were from 2023.

[Assistant] SELECT customer_id, updated_at, enrollment_id FROM education.grades WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Limit the results to 50 rows.

[Assistant] SELECT customer_id, updated_at, enrollment_id FROM education.grades WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31' LIMIT 50;


[User] Retrieve enrollment_id, category, updated_at for every grade.

[Assistant] SELECT enrollment_id, category, updated_at FROM education.grades;

[User] Show me grades with invoice_number LIKE 'A%'.

[Assistant] SELECT enrollment_id, category, updated_at FROM education.grades WHERE invoice_number LIKE 'A%';

[User] Order the output by customer_id ascending.

[Assistant] SELECT enrollment_id, category, updated_at FROM education.grades WHERE invoice_number LIKE 'A%' ORDER BY customer_id ASC;


[User] Retrieve category, invoice_number, enrollment_id for every grade.

[Assistant] SELECT category, invoice_number, enrollment_id FROM education.grades;

[User] Find grades from 2023.

[Assistant] SELECT category, invoice_number, enrollment_id FROM education.grades WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Get the distribution of grades across different enrollment_id values.

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


[User] Display all grades.

[Assistant] SELECT * FROM education.grades;

[User] Find grades created yesterday.

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

[User] Sort the results by category ascending.

[Assistant] SELECT * FROM education.grades WHERE updated_at = CURRENT_DATE - INTERVAL '1 day' ORDER BY category ASC;


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.users (
  customer_id character varying(64) NOT NULL -- unique identifier,
  updated_at date,
  created_at timestamp,
  email varchar,
  age character varying(128) NOT NULL,
  password_hash varchar,
  is_active boolean,
  profile_picture_url char,
  message_id text -- reference to messages.content_id,
  FOREIGN KEY (message_id) REFERENCES messages(content_id)
)

CREATE TABLE socialmedia.messages (
  content_id varchar PRIMARY KEY -- unique identifier,
  published_at date,
  updated_at timestamp,
  body character varying(128),
  text char NOT NULL,
  attachment_url character varying(64) NOT NULL
)

[User] Get password_hash, message_id, age from all users.

[Assistant] SELECT password_hash, message_id, age FROM socialmedia.users;

[User] Retrieve users where email LIKE 'A%'.

[Assistant] SELECT password_hash, message_id, age FROM socialmedia.users WHERE email LIKE 'A%';

[User] Group users by profile_picture_url and show the sum of customer_id.

[Assistant] SELECT profile_picture_url, SUM(customer_id) AS sum_customer_id FROM socialmedia.users GROUP BY profile_picture_url;


[User] Retrieve profile_picture_url, password_hash, is_active for every user.

[Assistant] SELECT profile_picture_url, password_hash, is_active FROM socialmedia.users;

[User] Retrieve users where is_active = TRUE.

[Assistant] SELECT profile_picture_url, password_hash, is_active FROM socialmedia.users WHERE is_active = TRUE;

[User] Limit the results to 100 rows.

[Assistant] SELECT profile_picture_url, password_hash, is_active FROM socialmedia.users WHERE is_active = TRUE LIMIT 100;


[User] List is_active, customer_id, age from users.

[Assistant] SELECT is_active, customer_id, age FROM socialmedia.users;

[User] Sort the results by updated_at descending.

[Assistant] SELECT is_active, customer_id, age FROM socialmedia.users ORDER BY updated_at DESC;

[User] Tally up users by age.

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


[User] Show me all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Find users where email LIKE 'A%'.

[Assistant] SELECT * FROM socialmedia.users WHERE email LIKE 'A%';

[User] Show me average of email grouped by profile_picture_url for users.

[Assistant] SELECT profile_picture_url, AVERAGE(email) AS average_email FROM socialmedia.users GROUP BY profile_picture_url;


[User] Display all users.

[Assistant] SELECT * FROM socialmedia.users;

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

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

[User] Show me count of email grouped by is_active for users.

[Assistant] SELECT is_active, COUNT(email) AS count_email FROM socialmedia.users GROUP BY is_active;


[User] What are the message_id, password_hash, email of each user?

[Assistant] SELECT message_id, password_hash, email FROM socialmedia.users;

[User] Can you order these by age ascending?

[Assistant] SELECT message_id, password_hash, email FROM socialmedia.users ORDER BY age ASC;

[User] Show me count of created_at grouped by age for users.

[Assistant] SELECT age, COUNT(created_at) AS count_created_at FROM socialmedia.users GROUP BY age;


[User] List updated_at, is_active, customer_id from users.

[Assistant] SELECT updated_at, is_active, customer_id FROM socialmedia.users;

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

[Assistant] SELECT updated_at, is_active, customer_id FROM socialmedia.users WHERE updated_at > '2023-12-01';

[User] Limit the results to 20 rows.

[Assistant] SELECT updated_at, is_active, customer_id FROM socialmedia.users WHERE updated_at > '2023-12-01' LIMIT 20;


[User] List all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Retrieve users where the date is created yesterday.

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

[User] Tally up users by message_id.

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


[User] Retrieve profile_picture_url, customer_id, age for every user.

[Assistant] SELECT profile_picture_url, customer_id, age FROM socialmedia.users;

[User] Show me users with profile_picture_url LIKE 'A%'.

[Assistant] SELECT profile_picture_url, customer_id, age FROM socialmedia.users WHERE profile_picture_url LIKE 'A%';

[User] Tally up users by updated_at.

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


[User] Show me profile_picture_url, message_id, customer_id for all users.

[Assistant] SELECT profile_picture_url, message_id, customer_id FROM socialmedia.users;

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

[Assistant] SELECT profile_picture_url, message_id, customer_id FROM socialmedia.users ORDER BY email ASC;

[User] Get the distribution of users across different profile_picture_url values.

[Assistant] SELECT profile_picture_url, COUNT(*) AS count FROM socialmedia.users GROUP BY profile_picture_url 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 socialmedia.comments (
  id varchar PRIMARY KEY -- unique identifier,
  published_at timestamp without time zone,
  parent_id varchar,
  shares varchar,
  message character varying(128),
  visibility character varying(128),
  body text,
  user_id text NOT NULL -- reference to users.id,
  FOREIGN KEY (user_id) REFERENCES users(id)
)

CREATE TABLE socialmedia.users (
  id text PRIMARY KEY -- unique identifier,
  joined_at timestamp,
  updated_at timestamp without time zone,
  first_name character varying(256),
  last_name character varying(128) NOT NULL,
  salt varchar NOT NULL,
  token char,
  city char,
  comment_id text -- reference to comments.id,
  FOREIGN KEY (comment_id) REFERENCES comments(id)
)

CREATE TABLE socialmedia.followers (
  account_id character varying(64) NOT NULL -- unique identifier,
  due_date timestamp without time zone,
  created_at date,
  reference_number varchar,
  payee_id character varying(256),
  comment_id text -- reference to comments.id,
  user_id text -- reference to users.id,
  FOREIGN KEY (comment_id) REFERENCES comments(id),
  FOREIGN KEY (user_id) REFERENCES users(id)
)

[User] Retrieve all comments.

[Assistant] SELECT * FROM socialmedia.comments;

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

[Assistant] SELECT * FROM socialmedia.comments WHERE published_at > '2023-12-01';

[User] Can you order these by shares descending?

[Assistant] SELECT * FROM socialmedia.comments WHERE published_at > '2023-12-01' ORDER BY shares DESC;


[User] Retrieve due_date, payee_id, account_id for every follower.

[Assistant] SELECT due_date, payee_id, account_id FROM socialmedia.followers;

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

[Assistant] SELECT due_date, payee_id, account_id FROM socialmedia.followers WHERE created_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Restrict the output to 25 items.

[Assistant] SELECT due_date, payee_id, account_id FROM socialmedia.followers WHERE created_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 25;


[User] Show me token, salt, last_name for all users.

[Assistant] SELECT token, salt, last_name FROM socialmedia.users;

[User] Sort the results by first_name ascending.

[Assistant] SELECT token, salt, last_name FROM socialmedia.users ORDER BY first_name ASC;

[User] Show only 100 records.

[Assistant] SELECT token, salt, last_name FROM socialmedia.users ORDER BY first_name ASC LIMIT 100;


[User] Get all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] List comment_id, salt, message, published_at for each user along with their comment information.

[Assistant] SELECT *, comments.message, comments.published_at FROM socialmedia.users JOIN socialmedia.comments ON users.comment_id = comments.id;

[User] Tally up users by comment_id.

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


[User] List user_id, reference_number, comment_id from followers.

[Assistant] SELECT user_id, reference_number, comment_id FROM socialmedia.followers;

[User] Get all followers from 2023.

[Assistant] SELECT user_id, reference_number, comment_id FROM socialmedia.followers WHERE due_date BETWEEN '2023-01-01' AND '2023-12-31';

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

[Assistant] SELECT user_id, reference_number, comment_id FROM socialmedia.followers WHERE due_date BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY reference_number DESC;


[User] List updated_at, comment_id, city from users.

[Assistant] SELECT updated_at, comment_id, city FROM socialmedia.users;

[User] Find users where first_name LIKE 'A%'.

[Assistant] SELECT updated_at, comment_id, city FROM socialmedia.users WHERE first_name LIKE 'A%';

[User] Show the results sorted by first_name ascending.

[Assistant] SELECT updated_at, comment_id, city FROM socialmedia.users WHERE first_name LIKE 'A%' ORDER BY first_name ASC;


[User] List comment_id, city, joined_at from users.

[Assistant] SELECT comment_id, city, joined_at FROM socialmedia.users;

[User] Find users between January and March.

[Assistant] SELECT comment_id, city, joined_at FROM socialmedia.users WHERE updated_at BETWEEN '2023-01-01' AND '2023-03-31';

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

[Assistant] SELECT comment_id, city, joined_at FROM socialmedia.users WHERE updated_at BETWEEN '2023-01-01' AND '2023-03-31' ORDER BY last_name DESC;


[User] Display all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Find followers from last week.

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

[User] Sort the results by payee_id ascending.

[Assistant] SELECT * FROM socialmedia.followers WHERE created_at >= CURRENT_DATE - INTERVAL '7 days' ORDER BY payee_id ASC;


[User] List all users.

[Assistant] SELECT * FROM socialmedia.users;

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

[Assistant] SELECT * FROM socialmedia.users ORDER BY updated_at DESC;

[User] Show me min of city grouped by joined_at for users.

[Assistant] SELECT joined_at, MIN(city) AS min_city FROM socialmedia.users GROUP BY joined_at;


[User] Show me all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] Show the results sorted by parent_id descending.

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

[User] Tally up comments by user_id.

[Assistant] SELECT user_id, COUNT(*) AS count FROM socialmedia.comments GROUP BY user_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 healthcare.billing (
  id text PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  longitude character varying(256),
  description character varying(128) NOT NULL,
  postal_code varchar NOT NULL,
  accessibility char NOT NULL,
  patient_id text NOT NULL -- reference to patients.employee_id,
  FOREIGN KEY (patient_id) REFERENCES patients(employee_id)
)

CREATE TABLE healthcare.departments (
  id varchar PRIMARY KEY -- unique identifier,
  expires_at timestamp without time zone,
  created_at timestamp without time zone,
  currency char,
  price numeric(38,14) NOT NULL,
  views character varying(128)
)

CREATE TABLE healthcare.medical_records (
  id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp,
  phone character varying(128),
  timezone character varying(256) NOT NULL,
  account_status text,
  username varchar NOT NULL,
  password_hash text NOT NULL,
  is_verified bit -- indicates if verified is true,
  billin_id text -- reference to billing.id,
  FOREIGN KEY (billin_id) REFERENCES billing(id)
)

CREATE TABLE healthcare.patients (
  employee_id text PRIMARY KEY -- unique identifier,
  last_active date,
  updated_at date,
  avatar text,
  display_name char NOT NULL,
  last_name char,
  department_id text -- reference to departments.id,
  FOREIGN KEY (department_id) REFERENCES departments(id)
)

[User] Get all billing.

[Assistant] SELECT * FROM healthcare.billing;

[User] Retrieve billing where the date is from 2023.

[Assistant] SELECT * FROM healthcare.billing WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] What is the count updated_at for each longitude in billing?

[Assistant] SELECT longitude, COUNT(updated_at) AS count_updated_at FROM healthcare.billing GROUP BY longitude;


[User] List all billing.

[Assistant] SELECT * FROM healthcare.billing;

[User] Find billing from last week.

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

[User] Show me the count of billing grouped by patient_id.

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


[User] What are the longitude, patient_id, updated_at of each billing?

[Assistant] SELECT longitude, patient_id, updated_at FROM healthcare.billing;

[User] Order the output by accessibility descending.

[Assistant] SELECT longitude, patient_id, updated_at FROM healthcare.billing ORDER BY accessibility DESC;

[User] Restrict the output to 20 items.

[Assistant] SELECT longitude, patient_id, updated_at FROM healthcare.billing ORDER BY accessibility DESC LIMIT 20;


[User] Retrieve created_at, account_status, password_hash for every medical_record.

[Assistant] SELECT created_at, account_status, password_hash FROM healthcare.medical_records;

[User] Show the results sorted by username ascending.

[Assistant] SELECT created_at, account_status, password_hash FROM healthcare.medical_records ORDER BY username ASC;

[User] What is the max id for each created_at in medical_records?

[Assistant] SELECT created_at, MAX(id) AS max_id FROM healthcare.medical_records GROUP BY created_at;


[User] What are the password_hash, id, created_at of each medical_record?

[Assistant] SELECT password_hash, id, created_at FROM healthcare.medical_records;

[User] Sort the results by id ascending.

[Assistant] SELECT password_hash, id, created_at FROM healthcare.medical_records ORDER BY id ASC;

[User] Calculate sum of account_status for each timezone in medical_records.

[Assistant] SELECT timezone, SUM(account_status) AS sum_account_status FROM healthcare.medical_records GROUP BY timezone;


[User] List accessibility, description, longitude from billing.

[Assistant] SELECT accessibility, description, longitude FROM healthcare.billing;

[User] Order the output by postal_code ascending.

[Assistant] SELECT accessibility, description, longitude FROM healthcare.billing ORDER BY postal_code ASC;

[User] Count the number of billing in each accessibility category.

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


[User] List display_name, updated_at, last_active from patients.

[Assistant] SELECT display_name, updated_at, last_active FROM healthcare.patients;

[User] Can you order these by last_active ascending?

[Assistant] SELECT display_name, updated_at, last_active FROM healthcare.patients ORDER BY last_active ASC;

[User] Return just 100 rows.

[Assistant] SELECT display_name, updated_at, last_active FROM healthcare.patients ORDER BY last_active ASC LIMIT 100;


[User] Retrieve all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

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

[Assistant] SELECT * FROM healthcare.medical_records ORDER BY timezone DESC;

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

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


[User] Get description, longitude, postal_code from all billing.

[Assistant] SELECT description, longitude, postal_code FROM healthcare.billing;

[User] Retrieve billing where patient_id LIKE 'A%'.

[Assistant] SELECT description, longitude, postal_code FROM healthcare.billing WHERE patient_id LIKE 'A%';

[User] Calculate max of accessibility for each accessibility in billing.

[Assistant] SELECT accessibility, MAX(accessibility) AS max_accessibility FROM healthcare.billing GROUP BY accessibility;


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 tradingplatform.users (
  user_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  birth_date date NOT NULL,
  salt character varying(256),
  first_name character varying(64),
  country char NOT NULL,
  asset_id text -- reference to assets.item_id,
  FOREIGN KEY (asset_id) REFERENCES assets(item_id)
)

CREATE TABLE tradingplatform.assets (
  item_id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp,
  title character varying(128),
  available char,
  media_url text,
  popularity_score varchar,
  discount integer,
  user_id integer NOT NULL -- reference to users.user_id,
  FOREIGN KEY (user_id) REFERENCES users(user_id)
)

[User] What are the created_at, discount, available of each asset?

[Assistant] SELECT created_at, discount, available FROM tradingplatform.assets;

[User] Retrieve user_id, media_url, birth_date, created_at showing the relationship between assets and users.

[Assistant] SELECT created_at, discount, available, users.birth_date, users.created_at FROM tradingplatform.assets JOIN tradingplatform.users ON assets.user_id = users.user_id;

[User] Show me the count of assets grouped by user_id.

[Assistant] SELECT user_id, COUNT(*) AS count FROM tradingplatform.assets GROUP BY user_id ORDER BY count DESC;


[User] Show me all users.

[Assistant] SELECT * FROM tradingplatform.users;

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

[Assistant] SELECT * FROM tradingplatform.users WHERE birth_date >= CURRENT_DATE - INTERVAL '30 days';

[User] Get average of created_at by birth_date from users.

[Assistant] SELECT birth_date, AVERAGE(created_at) AS average_created_at FROM tradingplatform.users GROUP BY birth_date;


[User] Get all assets.

[Assistant] SELECT * FROM tradingplatform.assets;

[User] Retrieve assets where user_id > 34.

[Assistant] SELECT * FROM tradingplatform.assets WHERE user_id > 34;

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

[Assistant] SELECT * FROM tradingplatform.assets WHERE user_id > 34 ORDER BY created_at ASC;


[User] Retrieve discount, title, popularity_score for every asset.

[Assistant] SELECT discount, title, popularity_score FROM tradingplatform.assets;

[User] Get assets that match user_id > 94.

[Assistant] SELECT discount, title, popularity_score FROM tradingplatform.assets WHERE user_id > 94;

[User] How many assets are there per media_url?

[Assistant] SELECT media_url, COUNT(*) AS count FROM tradingplatform.assets GROUP BY media_url ORDER BY count DESC;


[User] Retrieve available, user_id, media_url for every asset.

[Assistant] SELECT available, user_id, media_url FROM tradingplatform.assets;

[User] What user_id, created_at, salt, created_at do we have for assets and their associated users?

[Assistant] SELECT available, user_id, media_url, users.salt, users.created_at FROM tradingplatform.assets JOIN tradingplatform.users ON assets.user_id = users.user_id;

[User] Show me the count of assets grouped by media_url.

[Assistant] SELECT media_url, COUNT(*) AS count FROM tradingplatform.assets GROUP BY media_url ORDER BY count DESC;


[User] List discount, created_at, popularity_score from assets.

[Assistant] SELECT discount, created_at, popularity_score FROM tradingplatform.assets;

[User] Order the output by title descending.

[Assistant] SELECT discount, created_at, popularity_score FROM tradingplatform.assets ORDER BY title DESC;

[User] Can you order these by created_at ascending?

[Assistant] SELECT discount, created_at, popularity_score FROM tradingplatform.assets ORDER BY created_at ASC;


[User] Retrieve all users.

[Assistant] SELECT * FROM tradingplatform.users;

[User] Retrieve salt, birth_date, created_at, popularity_score showing the relationship between users and assets.

[Assistant] SELECT *, assets.created_at, assets.popularity_score FROM tradingplatform.users JOIN tradingplatform.assets ON users.asset_id = assets.item_id;

[User] Count the number of users in each country category.

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


[User] List all users.

[Assistant] SELECT * FROM tradingplatform.users;

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

[Assistant] SELECT * FROM tradingplatform.users WHERE birth_date > '2023-12-01';

[User] How many users are there per first_name?

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


[User] Get country, first_name, created_at from all users.

[Assistant] SELECT country, first_name, created_at FROM tradingplatform.users;

[User] Get users that match country LIKE 'A%'.

[Assistant] SELECT country, first_name, created_at FROM tradingplatform.users WHERE country LIKE 'A%';

[User] Restrict the output to 25 items.

[Assistant] SELECT country, first_name, created_at FROM tradingplatform.users WHERE country LIKE 'A%' LIMIT 25;


[User] Show me first_name, salt, birth_date for all users.

[Assistant] SELECT first_name, salt, birth_date FROM tradingplatform.users;

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

[Assistant] SELECT first_name, salt, birth_date FROM tradingplatform.users WHERE created_at > '2023-12-01';

[User] How many users are there per created_at?

[Assistant] SELECT created_at, COUNT(*) AS count FROM tradingplatform.users 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 travel.bookings (
  payment_id text PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  card_type character varying(256),
  user_id character varying(256) NOT NULL,
  currency text NOT NULL
)

CREATE TABLE travel.facilities (
  store_id character varying(64) NOT NULL -- unique identifier,
  last_inspected date,
  geo_point character varying(128),
  city varchar,
  name character varying(128),
  postal_code char
)

CREATE TABLE travel.customers (
  id varchar PRIMARY KEY -- unique identifier,
  joined_at timestamp,
  last_active date,
  token character varying(256),
  is_active bit NOT NULL -- indicates if active is true,
  birth_date timestamp NOT NULL,
  booking_id text -- reference to bookings.payment_id,
  FOREIGN KEY (booking_id) REFERENCES bookings(payment_id)
)

[User] Retrieve birth_date, joined_at, is_active for every customer.

[Assistant] SELECT birth_date, joined_at, is_active FROM travel.customers;

[User] Can you order these by last_active descending?

[Assistant] SELECT birth_date, joined_at, is_active FROM travel.customers ORDER BY last_active DESC;

[User] Show me count of joined_at grouped by token for customers.

[Assistant] SELECT token, COUNT(joined_at) AS count_joined_at FROM travel.customers GROUP BY token;


[User] Get booking_id, last_active, birth_date from all customers.

[Assistant] SELECT booking_id, last_active, birth_date FROM travel.customers;

[User] Order the output by booking_id ascending.

[Assistant] SELECT booking_id, last_active, birth_date FROM travel.customers ORDER BY booking_id ASC;

[User] Tally up customers by last_active.

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


[User] Get all customers.

[Assistant] SELECT * FROM travel.customers;

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

[Assistant] SELECT * FROM travel.customers WHERE joined_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Restrict the output to 20 items.

[Assistant] SELECT * FROM travel.customers WHERE joined_at >= CURRENT_DATE - INTERVAL '30 days' LIMIT 20;


[User] Retrieve joined_at, token, is_active for every customer.

[Assistant] SELECT joined_at, token, is_active FROM travel.customers;

[User] Find customers modified within the last hour.

[Assistant] SELECT joined_at, token, is_active FROM travel.customers WHERE joined_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

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

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


[User] Get all customers.

[Assistant] SELECT * FROM travel.customers;

[User] Find customers where booking_id LIKE 'A%'.

[Assistant] SELECT * FROM travel.customers WHERE booking_id LIKE 'A%';

[User] Only show the top 100 results.

[Assistant] SELECT * FROM travel.customers WHERE booking_id LIKE 'A%' LIMIT 100;


[User] List birth_date, is_active, token from customers.

[Assistant] SELECT birth_date, is_active, token FROM travel.customers;

[User] What joined_at, last_active, created_at, currency do we have for customers and their associated bookings?

[Assistant] SELECT birth_date, is_active, token, bookings.created_at, bookings.currency FROM travel.customers JOIN travel.bookings ON customers.booking_id = bookings.payment_id;

[User] Can you order these by booking_id descending?

[Assistant] SELECT birth_date, is_active, token, bookings.created_at, bookings.currency FROM travel.customers JOIN travel.bookings ON customers.booking_id = bookings.payment_id ORDER BY booking_id DESC;


[User] Show me token, is_active, booking_id for all customers.

[Assistant] SELECT token, is_active, booking_id FROM travel.customers;

[User] List customers that have is_active = TRUE.

[Assistant] SELECT token, is_active, booking_id FROM travel.customers WHERE is_active = TRUE;

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

[Assistant] SELECT token, is_active, booking_id FROM travel.customers WHERE is_active = TRUE ORDER BY booking_id ASC;


[User] Display all customers.

[Assistant] SELECT * FROM travel.customers;

[User] Show me joined_at, birth_date, card_type, currency from customers and their related bookings.

[Assistant] SELECT *, bookings.card_type, bookings.currency FROM travel.customers JOIN travel.bookings ON customers.booking_id = bookings.payment_id;

[User] Only show the top 15 results.

[Assistant] SELECT *, bookings.card_type, bookings.currency FROM travel.customers JOIN travel.bookings ON customers.booking_id = bookings.payment_id LIMIT 15;


[User] List is_active, birth_date, joined_at from customers.

[Assistant] SELECT is_active, birth_date, joined_at FROM travel.customers;

[User] Order the output by token descending.

[Assistant] SELECT is_active, birth_date, joined_at FROM travel.customers ORDER BY token DESC;

[User] Show me max of last_active grouped by token for customers.

[Assistant] SELECT token, MAX(last_active) AS max_last_active FROM travel.customers GROUP BY token;


[User] Get all customers.

[Assistant] SELECT * FROM travel.customers;

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

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

[User] Group customers by birth_date and show the count of last_active.

[Assistant] SELECT birth_date, COUNT(last_active) AS count_last_active FROM travel.customers GROUP BY birth_date;


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.reviews (
  message_id text PRIMARY KEY -- unique identifier,
  published_at timestamp,
  edited_at timestamp without time zone,
  message character varying(256),
  image_url text NOT NULL
)

CREATE TABLE e-commerce.products (
  id character varying(64) NOT NULL -- unique identifier,
  published_at timestamp without time zone,
  expires_at timestamp without time zone,
  media_url text,
  stock_level varchar,
  price bigint NOT NULL,
  tax_rate char,
  rating character varying(128)
)

CREATE TABLE e-commerce.users (
  employee_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  joined_at timestamp,
  bio char,
  timezone character varying(64) NOT NULL,
  city character varying(64),
  review_id text -- reference to reviews.message_id,
  FOREIGN KEY (review_id) REFERENCES reviews(message_id)
)

[User] Retrieve timezone, city, bio for every user.

[Assistant] SELECT timezone, city, bio FROM e-commerce.users;

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

[Assistant] SELECT timezone, city, bio FROM e-commerce.users WHERE joined_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Calculate max of timezone for each updated_at in users.

[Assistant] SELECT updated_at, MAX(timezone) AS max_timezone FROM e-commerce.users GROUP BY updated_at;


[User] Show me city, bio, updated_at for all users.

[Assistant] SELECT city, bio, updated_at FROM e-commerce.users;

[User] Retrieve users where the date is from 2023.

[Assistant] SELECT city, bio, updated_at FROM e-commerce.users WHERE joined_at BETWEEN '2023-01-01' AND '2023-12-31';

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

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


[User] Get updated_at, city, timezone from all users.

[Assistant] SELECT updated_at, city, timezone FROM e-commerce.users;

[User] Get all users created after December 1st, 2023.

[Assistant] SELECT updated_at, city, timezone FROM e-commerce.users WHERE joined_at > '2023-12-01';

[User] Show me min of timezone grouped by bio for users.

[Assistant] SELECT bio, MIN(timezone) AS min_timezone FROM e-commerce.users GROUP BY bio;


[User] Display all users.

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

[User] Show the results sorted by city descending.

[Assistant] SELECT * FROM e-commerce.users ORDER BY city DESC;

[User] Can you order these by review_id ascending?

[Assistant] SELECT * FROM e-commerce.users ORDER BY review_id ASC;


[User] List all users.

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

[User] List timezone, review_id, image_url, edited_at for each user along with their review information.

[Assistant] SELECT *, reviews.image_url, reviews.edited_at FROM e-commerce.users JOIN e-commerce.reviews ON users.review_id = reviews.message_id;

[User] Limit the results to 100 rows.

[Assistant] SELECT *, reviews.image_url, reviews.edited_at FROM e-commerce.users JOIN e-commerce.reviews ON users.review_id = reviews.message_id LIMIT 100;


[User] Show me joined_at, city, timezone for all users.

[Assistant] SELECT joined_at, city, timezone FROM e-commerce.users;

[User] Show me users with updated_at > '2023-01-01'.

[Assistant] SELECT joined_at, city, timezone FROM e-commerce.users WHERE updated_at > '2023-01-01';

[User] Limit the results to 50 rows.

[Assistant] SELECT joined_at, city, timezone FROM e-commerce.users WHERE updated_at > '2023-01-01' LIMIT 50;


[User] Display all users.

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

[User] Find users created yesterday.

[Assistant] SELECT * FROM e-commerce.users WHERE updated_at = CURRENT_DATE - INTERVAL '1 day';

[User] Get sum of review_id by timezone from users.

[Assistant] SELECT timezone, SUM(review_id) AS sum_review_id FROM e-commerce.users GROUP BY timezone;


[User] Show me joined_at, city, updated_at for all users.

[Assistant] SELECT joined_at, city, updated_at FROM e-commerce.users;

[User] Show me bio, updated_at, message, edited_at from users and their related reviews.

[Assistant] SELECT joined_at, city, updated_at, reviews.message, reviews.edited_at FROM e-commerce.users JOIN e-commerce.reviews ON users.review_id = reviews.message_id;

[User] Return just 15 rows.

[Assistant] SELECT joined_at, city, updated_at, reviews.message, reviews.edited_at FROM e-commerce.users JOIN e-commerce.reviews ON users.review_id = reviews.message_id LIMIT 15;


[User] Show me updated_at, city, review_id for all users.

[Assistant] SELECT updated_at, city, review_id FROM e-commerce.users;

[User] Retrieve review_id, timezone, image_url, published_at showing the relationship between users and reviews.

[Assistant] SELECT updated_at, city, review_id, reviews.image_url, reviews.published_at FROM e-commerce.users JOIN e-commerce.reviews ON users.review_id = reviews.message_id;

[User] Return just 5 rows.

[Assistant] SELECT updated_at, city, review_id, reviews.image_url, reviews.published_at FROM e-commerce.users JOIN e-commerce.reviews ON users.review_id = reviews.message_id LIMIT 5;


[User] Retrieve updated_at, bio, review_id for every user.

[Assistant] SELECT updated_at, bio, review_id FROM e-commerce.users;

[User] List review_id, updated_at, edited_at, message for each user along with their review information.

[Assistant] SELECT updated_at, bio, review_id, reviews.edited_at, reviews.message FROM e-commerce.users JOIN e-commerce.reviews ON users.review_id = reviews.message_id;

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

[Assistant] SELECT timezone, COUNT(*) AS count FROM e-commerce.users GROUP BY timezone 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 socialmedia.likes (
  transaction_id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp,
  customer_id varchar -- identifier for customer,
  approval_status character varying(64) NOT NULL,
  product_id varchar NOT NULL,
  seller_id character varying(256) NOT NULL -- identifier for seller,
  payment_status character varying(128)
)

CREATE TABLE socialmedia.followers (
  id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp without time zone,
  last_inspected timestamp,
  capacity char NOT NULL,
  coordinates character varying(128),
  geo_point char,
  address_line1 character varying(64),
  event_id integer NOT NULL -- reference to events.customer_id,
  FOREIGN KEY (event_id) REFERENCES events(customer_id)
)

CREATE TABLE socialmedia.events (
  customer_id integer PRIMARY KEY -- unique identifier,
  last_active timestamp,
  api_key character varying(128) NOT NULL,
  bio varchar,
  username varchar,
  last_name character varying(256)
)

[User] Retrieve last_inspected, address_line1, id for every follower.

[Assistant] SELECT last_inspected, address_line1, id FROM socialmedia.followers;

[User] Show me followers with last_inspected > '2023-01-01'.

[Assistant] SELECT last_inspected, address_line1, id FROM socialmedia.followers WHERE last_inspected > '2023-01-01';

[User] Show me count of event_id grouped by capacity for followers.

[Assistant] SELECT capacity, COUNT(event_id) AS count_event_id FROM socialmedia.followers GROUP BY capacity;


[User] Retrieve all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Show me event_id, coordinates, api_key, last_active from followers and their related events.

[Assistant] SELECT *, events.api_key, events.last_active FROM socialmedia.followers JOIN socialmedia.events ON followers.event_id = events.customer_id;

[User] How many followers are there per event_id?

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


[User] Get updated_at, coordinates, geo_point from all followers.

[Assistant] SELECT updated_at, coordinates, geo_point FROM socialmedia.followers;

[User] Order the output by address_line1 ascending.

[Assistant] SELECT updated_at, coordinates, geo_point FROM socialmedia.followers ORDER BY address_line1 ASC;

[User] Show me max of coordinates grouped by address_line1 for followers.

[Assistant] SELECT address_line1, MAX(coordinates) AS max_coordinates FROM socialmedia.followers GROUP BY address_line1;


[User] Show me all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Show the results sorted by coordinates ascending.

[Assistant] SELECT * FROM socialmedia.followers ORDER BY coordinates ASC;

[User] Can you order these by updated_at descending?

[Assistant] SELECT * FROM socialmedia.followers ORDER BY updated_at DESC;


[User] Display all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Find followers where event_id > 10.

[Assistant] SELECT * FROM socialmedia.followers WHERE event_id > 10;

[User] Show me average of id grouped by event_id for followers.

[Assistant] SELECT event_id, AVERAGE(id) AS average_id FROM socialmedia.followers GROUP BY event_id;


[User] List all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Find followers where last_inspected > '2023-01-01'.

[Assistant] SELECT * FROM socialmedia.followers WHERE last_inspected > '2023-01-01';

[User] Can you order these by id descending?

[Assistant] SELECT * FROM socialmedia.followers WHERE last_inspected > '2023-01-01' ORDER BY id DESC;


[User] Get coordinates, capacity, updated_at from all followers.

[Assistant] SELECT coordinates, capacity, updated_at FROM socialmedia.followers;

[User] What last_inspected, address_line1, username, last_name do we have for followers and their associated events?

[Assistant] SELECT coordinates, capacity, updated_at, events.username, events.last_name FROM socialmedia.followers JOIN socialmedia.events ON followers.event_id = events.customer_id;

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

[Assistant] SELECT coordinates, capacity, updated_at, events.username, events.last_name FROM socialmedia.followers JOIN socialmedia.events ON followers.event_id = events.customer_id ORDER BY last_inspected DESC;


[User] List geo_point, coordinates, address_line1 from followers.

[Assistant] SELECT geo_point, coordinates, address_line1 FROM socialmedia.followers;

[User] Order the output by last_inspected descending.

[Assistant] SELECT geo_point, coordinates, address_line1 FROM socialmedia.followers ORDER BY last_inspected DESC;

[User] Show the results sorted by updated_at descending.

[Assistant] SELECT geo_point, coordinates, address_line1 FROM socialmedia.followers ORDER BY updated_at DESC;


[User] Get all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Retrieve followers where the date is created in the last 30 days.

[Assistant] SELECT * FROM socialmedia.followers WHERE updated_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Limit the results to 50 rows.

[Assistant] SELECT * FROM socialmedia.followers WHERE updated_at >= CURRENT_DATE - INTERVAL '30 days' LIMIT 50;


[User] Retrieve all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Show me followers that were created yesterday.

[Assistant] SELECT * FROM socialmedia.followers WHERE last_inspected = CURRENT_DATE - INTERVAL '1 day';

[User] Get min of id by coordinates from followers.

[Assistant] SELECT coordinates, MIN(id) AS min_id FROM socialmedia.followers GROUP BY coordinates;


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.doctors (
  user_id character varying(64) NOT NULL -- unique identifier,
  joined_at timestamp,
  avatar character varying(128),
  status character varying(64) NOT NULL,
  account_status character varying(128),
  department_id text NOT NULL -- reference to departments.store_id,
  FOREIGN KEY (department_id) REFERENCES departments(store_id)
)

CREATE TABLE healthcare.departments (
  store_id varchar PRIMARY KEY -- unique identifier,
  last_inspected timestamp,
  created_at timestamp without time zone,
  parking_available text,
  description char,
  zip_code character varying(64),
  name character varying(128)
)

[User] What are the user_id, joined_at, account_status of each doctor?

[Assistant] SELECT user_id, joined_at, account_status FROM healthcare.doctors;

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

[Assistant] SELECT user_id, joined_at, account_status FROM healthcare.doctors WHERE joined_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Group doctors by account_status and show the average of joined_at.

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


[User] Get all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

[User] Show me doctors that were from 2023.

[Assistant] SELECT * FROM healthcare.doctors WHERE joined_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] What is the sum avatar for each account_status in doctors?

[Assistant] SELECT account_status, SUM(avatar) AS sum_avatar FROM healthcare.doctors GROUP BY account_status;


[User] Retrieve all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

[User] Get doctors that match status LIKE 'A%'.

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

[User] Show me the count of doctors grouped by department_id.

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


[User] Show me all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

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

[Assistant] SELECT * FROM healthcare.doctors ORDER BY account_status ASC;

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

[Assistant] SELECT * FROM healthcare.doctors ORDER BY status ASC;


[User] Retrieve department_id, user_id, avatar for every doctor.

[Assistant] SELECT department_id, user_id, avatar FROM healthcare.doctors;

[User] Get user_id, avatar, name, zip_code by joining doctors with departments.

[Assistant] SELECT department_id, user_id, avatar, departments.name, departments.zip_code FROM healthcare.doctors JOIN healthcare.departments ON doctors.department_id = departments.store_id;

[User] Sort the results by department_id ascending.

[Assistant] SELECT department_id, user_id, avatar, departments.name, departments.zip_code FROM healthcare.doctors JOIN healthcare.departments ON doctors.department_id = departments.store_id ORDER BY department_id ASC;


[User] Show me account_status, status, department_id for all doctors.

[Assistant] SELECT account_status, status, department_id FROM healthcare.doctors;

[User] Order the output by user_id ascending.

[Assistant] SELECT account_status, status, department_id FROM healthcare.doctors ORDER BY user_id ASC;

[User] Show the results sorted by joined_at descending.

[Assistant] SELECT account_status, status, department_id FROM healthcare.doctors ORDER BY joined_at DESC;


[User] Show me all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

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

[Assistant] SELECT * FROM healthcare.doctors WHERE joined_at >= CURRENT_DATE - INTERVAL '30 days';

[User] How many doctors are there per user_id?

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


[User] What are the account_status, status, user_id of each doctor?

[Assistant] SELECT account_status, status, user_id FROM healthcare.doctors;

[User] Show me doctors with department_id LIKE 'A%'.

[Assistant] SELECT account_status, status, user_id FROM healthcare.doctors WHERE department_id LIKE 'A%';

[User] Only show the top 10 results.

[Assistant] SELECT account_status, status, user_id FROM healthcare.doctors WHERE department_id LIKE 'A%' LIMIT 10;


[User] Get all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

[User] Retrieve account_status, status, last_inspected, description showing the relationship between doctors and departments.

[Assistant] SELECT *, departments.last_inspected, departments.description FROM healthcare.doctors JOIN healthcare.departments ON doctors.department_id = departments.store_id;

[User] Can you order these by account_status descending?

[Assistant] SELECT *, departments.last_inspected, departments.description FROM healthcare.doctors JOIN healthcare.departments ON doctors.department_id = departments.store_id ORDER BY account_status DESC;


[User] Get all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

[User] Sort the results by account_status descending.

[Assistant] SELECT * FROM healthcare.doctors ORDER BY account_status DESC;

[User] Sort the results by joined_at descending.

[Assistant] SELECT * FROM healthcare.doctors ORDER BY joined_at DESC;