[User] Show me all billing.

[Assistant] SELECT * FROM healthcare.billing;

[User] Show the results sorted by customer_id descending.

[Assistant] SELECT * FROM healthcare.billing ORDER BY customer_id DESC;

[User] Sort the results by notes descending.

[Assistant] SELECT * FROM healthcare.billing ORDER BY notes 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.doctors (
  venue_id text PRIMARY KEY -- unique identifier,
  created_at date,
  last_inspected timestamp without time zone,
  street character varying(128),
  country character varying(128) NOT NULL,
  type text,
  capacity text,
  billin_id integer NOT NULL -- reference to billing.invoice_id,
  appointment_id text -- reference to appointments.customer_id,
  FOREIGN KEY (billin_id) REFERENCES billing(invoice_id),
  FOREIGN KEY (appointment_id) REFERENCES appointments(customer_id)
)

CREATE TABLE healthcare.billing (
  invoice_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  due_date timestamp,
  notes char,
  exchange_rate character varying(256),
  reference_number varchar,
  balance bigint,
  customer_id character varying(128) -- identifier for customer,
  appointment_id text NOT NULL -- reference to appointments.customer_id,
  patient_id text NOT NULL -- reference to patients.id,
  FOREIGN KEY (appointment_id) REFERENCES appointments(customer_id),
  FOREIGN KEY (patient_id) REFERENCES patients(id)
)

CREATE TABLE healthcare.appointments (
  customer_id varchar PRIMARY KEY -- unique identifier,
  last_active timestamp,
  created_at timestamp without time zone,
  last_login timestamp,
  age text,
  status character varying(256) NOT NULL
)

CREATE TABLE healthcare.patients (
  id text PRIMARY KEY -- unique identifier,
  joined_at date,
  status varchar,
  last_login date NOT NULL,
  salt text,
  api_key char,
  first_name character varying(64) NOT NULL
)

[User] List all doctors.

[Assistant] SELECT * FROM healthcare.doctors;

[User] Can you order these by created_at descending?

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

[User] Restrict the output to 50 items.

[Assistant] SELECT * FROM healthcare.doctors ORDER BY created_at DESC LIMIT 50;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE tradingplatform.orders (
  id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp,
  cancelled_at date,
  subtotal integer,
  buyer_id varchar -- identifier for buyer,
  account_id varchar,
  currency text NOT NULL,
  approval_status character varying(64),
  user_id integer -- reference to users.employee_id,
  FOREIGN KEY (user_id) REFERENCES users(employee_id)
)

CREATE TABLE tradingplatform.trades (
  payment_id text PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  processed_at date,
  approval_status character varying(256),
  card_type character varying(256),
  delivery_status varchar,
  currency varchar,
  subtotal numeric,
  exchange_rate character varying(256) NOT NULL,
  order_id text NOT NULL -- reference to orders.id,
  user_id integer NOT NULL -- reference to users.employee_id,
  FOREIGN KEY (order_id) REFERENCES orders(id),
  FOREIGN KEY (user_id) REFERENCES users(employee_id)
)

CREATE TABLE tradingplatform.users (
  employee_id integer PRIMARY KEY -- unique identifier,
  joined_at timestamp without time zone,
  is_active boolean -- indicates if active is true,
  is_verified boolean NOT NULL,
  password_hash varchar,
  last_login date NOT NULL
)

[User] Show me user_id, approval_status, subtotal for all orders.

[Assistant] SELECT user_id, approval_status, subtotal FROM tradingplatform.orders;

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

[Assistant] SELECT user_id, approval_status, subtotal FROM tradingplatform.orders WHERE currency LIKE 'A%';

[User] What is the count user_id for each subtotal in orders?

[Assistant] SELECT subtotal, COUNT(user_id) AS count_user_id FROM tradingplatform.orders GROUP BY subtotal;


[User] Get all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

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

[Assistant] SELECT * FROM tradingplatform.trades WHERE processed_at <= CURRENT_DATE - INTERVAL '6 months';

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

[Assistant] SELECT * FROM tradingplatform.trades WHERE processed_at <= CURRENT_DATE - INTERVAL '6 months' ORDER BY card_type ASC;


[User] Retrieve approval_status, exchange_rate, subtotal for every trade.

[Assistant] SELECT approval_status, exchange_rate, subtotal FROM tradingplatform.trades;

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

[Assistant] SELECT approval_status, exchange_rate, subtotal FROM tradingplatform.trades ORDER BY user_id ASC;

[User] Show me the count of trades grouped by delivery_status.

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


[User] Retrieve buyer_id, cancelled_at, account_id for every order.

[Assistant] SELECT buyer_id, cancelled_at, account_id FROM tradingplatform.orders;

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

[Assistant] SELECT buyer_id, cancelled_at, account_id FROM tradingplatform.orders WHERE cancelled_at <= CURRENT_DATE - INTERVAL '6 months';

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

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


[User] Show me created_at, account_id, approval_status for all orders.

[Assistant] SELECT created_at, account_id, approval_status FROM tradingplatform.orders;

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

[Assistant] SELECT created_at, account_id, approval_status FROM tradingplatform.orders WHERE created_at > '2023-12-01';

[User] Show the results sorted by buyer_id ascending.

[Assistant] SELECT created_at, account_id, approval_status FROM tradingplatform.orders WHERE created_at > '2023-12-01' ORDER BY buyer_id ASC;


[User] Display all orders.

[Assistant] SELECT * FROM tradingplatform.orders;

[User] Show the results sorted by account_id ascending.

[Assistant] SELECT * FROM tradingplatform.orders ORDER BY account_id ASC;

[User] Sort the results by user_id descending.

[Assistant] SELECT * FROM tradingplatform.orders ORDER BY user_id DESC;


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

[Assistant] SELECT created_at, approval_status, subtotal FROM tradingplatform.orders;

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

[Assistant] SELECT created_at, approval_status, subtotal FROM tradingplatform.orders WHERE cancelled_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Tally up orders by cancelled_at.

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


[User] Get all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

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

[Assistant] SELECT * FROM tradingplatform.trades ORDER BY user_id ASC;

[User] Get the distribution of trades across different approval_status values.

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


[User] What are the subtotal, created_at, processed_at of each trade?

[Assistant] SELECT subtotal, created_at, processed_at FROM tradingplatform.trades;

[User] Find trades between January and March.

[Assistant] SELECT subtotal, created_at, processed_at FROM tradingplatform.trades WHERE created_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Show only 100 records.

[Assistant] SELECT subtotal, created_at, processed_at FROM tradingplatform.trades WHERE created_at BETWEEN '2023-01-01' AND '2023-03-31' LIMIT 100;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE socialmedia.messages (
  comment_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  user_id character varying(256) NOT NULL -- identifier for user,
  categories text,
  media_url character varying(256) NOT NULL,
  tags character varying(128) NOT NULL,
  keywords text,
  like_id text NOT NULL -- reference to likes.id,
  FOREIGN KEY (like_id) REFERENCES likes(id)
)

CREATE TABLE socialmedia.likes (
  id varchar PRIMARY KEY -- unique identifier,
  last_active date,
  display_name text,
  avatar character varying(256),
  state char,
  website character varying(256),
  api_key character varying(64) NOT NULL
)

CREATE TABLE socialmedia.posts (
  content_id character varying(64) NOT NULL -- unique identifier,
  published_at timestamp without time zone,
  parent_id varchar,
  attachment_url character varying(128),
  media_url char,
  score char NOT NULL,
  message_id integer -- reference to messages.comment_id,
  FOREIGN KEY (message_id) REFERENCES messages(comment_id)
)

[User] Show me all posts.

[Assistant] SELECT * FROM socialmedia.posts;

[User] What parent_id, media_url, media_url, keywords do we have for posts and their associated messages?

[Assistant] SELECT *, messages.media_url, messages.keywords FROM socialmedia.posts JOIN socialmedia.messages ON posts.message_id = messages.comment_id;

[User] Only show the top 5 results.

[Assistant] SELECT *, messages.media_url, messages.keywords FROM socialmedia.posts JOIN socialmedia.messages ON posts.message_id = messages.comment_id LIMIT 5;


[User] Retrieve all posts.

[Assistant] SELECT * FROM socialmedia.posts;

[User] List published_at, message_id, like_id, media_url for each post along with their message information.

[Assistant] SELECT *, messages.like_id, messages.media_url FROM socialmedia.posts JOIN socialmedia.messages ON posts.message_id = messages.comment_id;

[User] Sort the results by score ascending.

[Assistant] SELECT *, messages.like_id, messages.media_url FROM socialmedia.posts JOIN socialmedia.messages ON posts.message_id = messages.comment_id ORDER BY score ASC;


[User] List parent_id, score, media_url from posts.

[Assistant] SELECT parent_id, score, media_url FROM socialmedia.posts;

[User] Find posts where content_id LIKE 'A%'.

[Assistant] SELECT parent_id, score, media_url FROM socialmedia.posts WHERE content_id LIKE 'A%';

[User] How many posts are there per message_id?

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


[User] Display all posts.

[Assistant] SELECT * FROM socialmedia.posts;

[User] Get all posts between January and March.

[Assistant] SELECT * FROM socialmedia.posts WHERE published_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Restrict the output to 10 items.

[Assistant] SELECT * FROM socialmedia.posts WHERE published_at BETWEEN '2023-01-01' AND '2023-03-31' LIMIT 10;


[User] List content_id, attachment_url, media_url from posts.

[Assistant] SELECT content_id, attachment_url, media_url FROM socialmedia.posts;

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

[Assistant] SELECT content_id, attachment_url, media_url FROM socialmedia.posts WHERE parent_id LIKE 'A%';

[User] Order the output by attachment_url descending.

[Assistant] SELECT content_id, attachment_url, media_url FROM socialmedia.posts WHERE parent_id LIKE 'A%' ORDER BY attachment_url DESC;


[User] Get message_id, published_at, attachment_url from all posts.

[Assistant] SELECT message_id, published_at, attachment_url FROM socialmedia.posts;

[User] Can you order these by media_url ascending?

[Assistant] SELECT message_id, published_at, attachment_url FROM socialmedia.posts ORDER BY media_url ASC;

[User] Group posts by parent_id and show the min of score.

[Assistant] SELECT parent_id, MIN(score) AS min_score FROM socialmedia.posts GROUP BY parent_id;


[User] Get media_url, like_id, user_id from all messages.

[Assistant] SELECT media_url, like_id, user_id FROM socialmedia.messages;

[User] Can you order these by like_id descending?

[Assistant] SELECT media_url, like_id, user_id FROM socialmedia.messages ORDER BY like_id DESC;

[User] What is the min updated_at for each categories in messages?

[Assistant] SELECT categories, MIN(updated_at) AS min_updated_at FROM socialmedia.messages GROUP BY categories;


[User] Display all posts.

[Assistant] SELECT * FROM socialmedia.posts;

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

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

[User] Show only 50 records.

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


[User] List published_at, message_id, parent_id from posts.

[Assistant] SELECT published_at, message_id, parent_id FROM socialmedia.posts;

[User] Show me content_id, parent_id, updated_at, tags from posts and their related messages.

[Assistant] SELECT published_at, message_id, parent_id, messages.updated_at, messages.tags FROM socialmedia.posts JOIN socialmedia.messages ON posts.message_id = messages.comment_id;

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

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


[User] Show me categories, tags, media_url for all messages.

[Assistant] SELECT categories, tags, media_url FROM socialmedia.messages;

[User] What user_id, tags, avatar, state do we have for messages and their associated likes?

[Assistant] SELECT categories, tags, media_url, likes.avatar, likes.state FROM socialmedia.messages JOIN socialmedia.likes ON messages.like_id = likes.id;

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

[Assistant] SELECT user_id, COUNT(*) AS count FROM socialmedia.messages 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 finance.audits (
  id integer PRIMARY KEY -- unique identifier,
  joined_at date,
  created_at timestamp without time zone,
  address char,
  nationality varchar,
  display_name text,
  first_name character varying(256) NOT NULL,
  language character varying(128),
  payment_id text -- reference to payments.order_id,
  FOREIGN KEY (payment_id) REFERENCES payments(order_id)
)

CREATE TABLE finance.loans (
  employee_id character varying(64) NOT NULL -- unique identifier,
  last_active timestamp without time zone,
  last_login timestamp without time zone,
  age char NOT NULL,
  city character varying(256),
  payment_id text -- reference to payments.order_id,
  FOREIGN KEY (payment_id) REFERENCES payments(order_id)
)

CREATE TABLE finance.payments (
  order_id text PRIMARY KEY -- unique identifier,
  completed_at timestamp,
  cancelled_at date,
  status varchar,
  exchange_rate character varying(64),
  user_id character varying(64),
  product_id text NOT NULL -- identifier for product
)

[User] Display all loans.

[Assistant] SELECT * FROM finance.loans;

[User] List loans that have employee_id LIKE 'A%'.

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

[User] Can you order these by last_active ascending?

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


[User] List all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Show me loans with last_login > '2023-01-01'.

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

[User] Show the results sorted by city ascending.

[Assistant] SELECT * FROM finance.loans WHERE last_login > '2023-01-01' ORDER BY city ASC;


[User] Show me age, payment_id, city for all loans.

[Assistant] SELECT age, payment_id, city FROM finance.loans;

[User] What last_login, age, product_id, user_id do we have for loans and their associated payments?

[Assistant] SELECT age, payment_id, city, payments.product_id, payments.user_id FROM finance.loans JOIN finance.payments ON loans.payment_id = payments.order_id;

[User] Calculate average of city for each payment_id in loans.

[Assistant] SELECT payment_id, AVERAGE(city) AS average_city FROM finance.loans GROUP BY payment_id;


[User] What are the payment_id, last_active, city of each loan?

[Assistant] SELECT payment_id, last_active, city FROM finance.loans;

[User] List payment_id, employee_id, status, user_id for each loan along with their payment information.

[Assistant] SELECT payment_id, last_active, city, payments.status, payments.user_id FROM finance.loans JOIN finance.payments ON loans.payment_id = payments.order_id;

[User] Group loans by city and show the max of last_login.

[Assistant] SELECT city, MAX(last_login) AS max_last_login FROM finance.loans GROUP BY city;


[User] List nationality, first_name, created_at from audits.

[Assistant] SELECT nationality, first_name, created_at FROM finance.audits;

[User] Find audits from last week.

[Assistant] SELECT nationality, first_name, created_at FROM finance.audits WHERE joined_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Group audits by language and show the max of display_name.

[Assistant] SELECT language, MAX(display_name) AS max_display_name FROM finance.audits GROUP BY language;


[User] List payment_id, display_name, joined_at from audits.

[Assistant] SELECT payment_id, display_name, joined_at FROM finance.audits;

[User] Retrieve first_name, created_at, status, cancelled_at showing the relationship between audits and payments.

[Assistant] SELECT payment_id, display_name, joined_at, payments.status, payments.cancelled_at FROM finance.audits JOIN finance.payments ON audits.payment_id = payments.order_id;

[User] Can you order these by payment_id descending?

[Assistant] SELECT payment_id, display_name, joined_at, payments.status, payments.cancelled_at FROM finance.audits JOIN finance.payments ON audits.payment_id = payments.order_id ORDER BY payment_id DESC;


[User] Display all loans.

[Assistant] SELECT * FROM finance.loans;

[User] List last_active, city, exchange_rate, status for each loan along with their payment information.

[Assistant] SELECT *, payments.exchange_rate, payments.status FROM finance.loans JOIN finance.payments ON loans.payment_id = payments.order_id;

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

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


[User] List employee_id, last_active, city from loans.

[Assistant] SELECT employee_id, last_active, city FROM finance.loans;

[User] Show me last_active, employee_id, completed_at, user_id from loans and their related payments.

[Assistant] SELECT employee_id, last_active, city, payments.completed_at, payments.user_id FROM finance.loans JOIN finance.payments ON loans.payment_id = payments.order_id;

[User] Sort the results by city descending.

[Assistant] SELECT employee_id, last_active, city, payments.completed_at, payments.user_id FROM finance.loans JOIN finance.payments ON loans.payment_id = payments.order_id ORDER BY city DESC;


[User] List all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Show the results sorted by employee_id descending.

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

[User] Limit the results to 20 rows.

[Assistant] SELECT * FROM finance.loans ORDER BY employee_id DESC LIMIT 20;


[User] What are the first_name, language, created_at of each audit?

[Assistant] SELECT first_name, language, created_at FROM finance.audits;

[User] Order the output by address ascending.

[Assistant] SELECT first_name, language, created_at FROM finance.audits ORDER BY address ASC;

[User] How many audits are there per nationality?

[Assistant] SELECT nationality, COUNT(*) AS count FROM finance.audits GROUP BY nationality 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.orders (
  order_id integer PRIMARY KEY -- unique identifier,
  traded_at timestamp without time zone,
  processed_at timestamp without time zone,
  delivery_status char,
  payment_method character varying(128),
  card_type character varying(256),
  wallet_id text NOT NULL -- reference to wallets.invoice_id,
  metadat_id integer -- reference to metadata.item_id,
  FOREIGN KEY (wallet_id) REFERENCES wallets(invoice_id),
  FOREIGN KEY (metadat_id) REFERENCES metadata(item_id)
)

CREATE TABLE tradingplatform.wallets (
  invoice_id text PRIMARY KEY -- unique identifier,
  created_at timestamp,
  reconciliation_status character varying(64),
  notes char,
  description character varying(128) NOT NULL
)

CREATE TABLE tradingplatform.metadata (
  item_id integer PRIMARY KEY -- unique identifier,
  expires_at timestamp without time zone,
  updated_at timestamp,
  msrp varchar NOT NULL,
  name char,
  media_url text NOT NULL,
  price smallint,
  description character varying(64) NOT NULL,
  subcategory varchar
)

[User] Display all orders.

[Assistant] SELECT * FROM tradingplatform.orders;

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

[Assistant] SELECT * FROM tradingplatform.orders WHERE traded_at > '2023-01-01';

[User] Only show the top 10 results.

[Assistant] SELECT * FROM tradingplatform.orders WHERE traded_at > '2023-01-01' LIMIT 10;


[User] Show me all orders.

[Assistant] SELECT * FROM tradingplatform.orders;

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

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

[User] Show the results sorted by processed_at descending.

[Assistant] SELECT * FROM tradingplatform.orders WHERE processed_at > '2023-12-01' ORDER BY processed_at DESC;


[User] List all orders.

[Assistant] SELECT * FROM tradingplatform.orders;

[User] List orders with dates from 2023.

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

[User] Return just 100 rows.

[Assistant] SELECT * FROM tradingplatform.orders WHERE processed_at BETWEEN '2023-01-01' AND '2023-12-31' LIMIT 100;


[User] Retrieve card_type, wallet_id, payment_method for every order.

[Assistant] SELECT card_type, wallet_id, payment_method FROM tradingplatform.orders;

[User] Get metadat_id, payment_method, notes, created_at by joining orders with wallets.

[Assistant] SELECT card_type, wallet_id, payment_method, wallets.notes, wallets.created_at FROM tradingplatform.orders JOIN tradingplatform.wallets ON orders.wallet_id = wallets.invoice_id;

[User] How many orders are there per payment_method?

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


[User] What are the traded_at, wallet_id, payment_method of each order?

[Assistant] SELECT traded_at, wallet_id, payment_method FROM tradingplatform.orders;

[User] Show the results sorted by wallet_id ascending.

[Assistant] SELECT traded_at, wallet_id, payment_method FROM tradingplatform.orders ORDER BY wallet_id ASC;

[User] Limit the results to 10 rows.

[Assistant] SELECT traded_at, wallet_id, payment_method FROM tradingplatform.orders ORDER BY wallet_id ASC LIMIT 10;


[User] Retrieve metadat_id, delivery_status, processed_at for every order.

[Assistant] SELECT metadat_id, delivery_status, processed_at FROM tradingplatform.orders;

[User] List card_type, payment_method, created_at, description for each order along with their wallet information.

[Assistant] SELECT metadat_id, delivery_status, processed_at, wallets.created_at, wallets.description FROM tradingplatform.orders JOIN tradingplatform.wallets ON orders.wallet_id = wallets.invoice_id;

[User] Return just 10 rows.

[Assistant] SELECT metadat_id, delivery_status, processed_at, wallets.created_at, wallets.description FROM tradingplatform.orders JOIN tradingplatform.wallets ON orders.wallet_id = wallets.invoice_id LIMIT 10;


[User] Retrieve all orders.

[Assistant] SELECT * FROM tradingplatform.orders;

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

[Assistant] SELECT * FROM tradingplatform.orders WHERE wallet_id LIKE 'A%';

[User] Group orders by payment_method and show the max of card_type.

[Assistant] SELECT payment_method, MAX(card_type) AS max_card_type FROM tradingplatform.orders GROUP BY payment_method;


[User] Retrieve all orders.

[Assistant] SELECT * FROM tradingplatform.orders;

[User] Order the output by wallet_id descending.

[Assistant] SELECT * FROM tradingplatform.orders ORDER BY wallet_id DESC;

[User] Group orders by processed_at and show the average of metadat_id.

[Assistant] SELECT processed_at, AVERAGE(metadat_id) AS average_metadat_id FROM tradingplatform.orders GROUP BY processed_at;


[User] List all orders.

[Assistant] SELECT * FROM tradingplatform.orders;

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

[Assistant] SELECT * FROM tradingplatform.orders WHERE processed_at > '2023-01-01';

[User] Only show the top 50 results.

[Assistant] SELECT * FROM tradingplatform.orders WHERE processed_at > '2023-01-01' LIMIT 50;


[User] Show me card_type, payment_method, delivery_status for all orders.

[Assistant] SELECT card_type, payment_method, delivery_status FROM tradingplatform.orders;

[User] Sort the results by delivery_status descending.

[Assistant] SELECT card_type, payment_method, delivery_status FROM tradingplatform.orders ORDER BY delivery_status DESC;

[User] Get average of payment_method by metadat_id from orders.

[Assistant] SELECT metadat_id, AVERAGE(payment_method) AS average_payment_method FROM tradingplatform.orders GROUP BY metadat_id;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE socialmedia.events (
  id text PRIMARY KEY -- unique identifier,
  created_at timestamp,
  cost smallint,
  views character varying(128),
  backorder text,
  thumbnail_url character varying(64),
  comment_id text -- reference to comments.message_id,
  FOREIGN KEY (comment_id) REFERENCES comments(message_id)
)

CREATE TABLE socialmedia.comments (
  message_id text PRIMARY KEY -- unique identifier,
  published_at date,
  created_at timestamp without time zone,
  attachment_url character varying(64),
  views character varying(256) NOT NULL,
  rating character varying(64),
  user_id character varying(256) -- identifier for user,
  thumbnail varchar
)

CREATE TABLE socialmedia.groups (
  sku character varying(64) NOT NULL -- unique identifier,
  published_at date,
  expires_at timestamp,
  popularity_score char,
  media_url text
)

[User] Show me all events.

[Assistant] SELECT * FROM socialmedia.events;

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

[Assistant] SELECT * FROM socialmedia.events WHERE thumbnail_url LIKE 'A%';

[User] Restrict the output to 10 items.

[Assistant] SELECT * FROM socialmedia.events WHERE thumbnail_url LIKE 'A%' LIMIT 10;


[User] Display all events.

[Assistant] SELECT * FROM socialmedia.events;

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

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

[User] Show only 100 records.

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


[User] Retrieve thumbnail_url, comment_id, cost for every event.

[Assistant] SELECT thumbnail_url, comment_id, cost FROM socialmedia.events;

[User] Get events that match views LIKE 'A%'.

[Assistant] SELECT thumbnail_url, comment_id, cost FROM socialmedia.events WHERE views LIKE 'A%';

[User] Tally up events by created_at.

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


[User] List backorder, created_at, cost from events.

[Assistant] SELECT backorder, created_at, cost FROM socialmedia.events;

[User] Get created_at, backorder, views, published_at by joining events with comments.

[Assistant] SELECT backorder, created_at, cost, comments.views, comments.published_at FROM socialmedia.events JOIN socialmedia.comments ON events.comment_id = comments.message_id;

[User] Get average of views by comment_id from events.

[Assistant] SELECT comment_id, AVERAGE(views) AS average_views FROM socialmedia.events GROUP BY comment_id;


[User] Show me all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Order the output by created_at descending.

[Assistant] SELECT * FROM socialmedia.events ORDER BY created_at DESC;

[User] Order the output by backorder descending.

[Assistant] SELECT * FROM socialmedia.events ORDER BY backorder DESC;


[User] List views, comment_id, thumbnail_url from events.

[Assistant] SELECT views, comment_id, thumbnail_url FROM socialmedia.events;

[User] Retrieve created_at, views, thumbnail, attachment_url showing the relationship between events and comments.

[Assistant] SELECT views, comment_id, thumbnail_url, comments.thumbnail, comments.attachment_url FROM socialmedia.events JOIN socialmedia.comments ON events.comment_id = comments.message_id;

[User] Limit the results to 5 rows.

[Assistant] SELECT views, comment_id, thumbnail_url, comments.thumbnail, comments.attachment_url FROM socialmedia.events JOIN socialmedia.comments ON events.comment_id = comments.message_id LIMIT 5;


[User] Get all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Show me comment_id, thumbnail_url, user_id, views from events and their related comments.

[Assistant] SELECT *, comments.user_id, comments.views FROM socialmedia.events JOIN socialmedia.comments ON events.comment_id = comments.message_id;

[User] Show only 50 records.

[Assistant] SELECT *, comments.user_id, comments.views FROM socialmedia.events JOIN socialmedia.comments ON events.comment_id = comments.message_id LIMIT 50;


[User] Display all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Retrieve events where backorder LIKE 'A%'.

[Assistant] SELECT * FROM socialmedia.events WHERE backorder LIKE 'A%';

[User] Limit the results to 15 rows.

[Assistant] SELECT * FROM socialmedia.events WHERE backorder LIKE 'A%' LIMIT 15;


[User] Retrieve thumbnail_url, comment_id, backorder for every event.

[Assistant] SELECT thumbnail_url, comment_id, backorder FROM socialmedia.events;

[User] Order the output by backorder ascending.

[Assistant] SELECT thumbnail_url, comment_id, backorder FROM socialmedia.events ORDER BY backorder ASC;

[User] Get sum of cost by created_at from events.

[Assistant] SELECT created_at, SUM(cost) AS sum_cost FROM socialmedia.events GROUP BY created_at;


[User] Show me all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Sort the results by views ascending.

[Assistant] SELECT * FROM socialmedia.events ORDER BY views ASC;

[User] Return just 20 rows.

[Assistant] SELECT * FROM socialmedia.events ORDER BY views ASC 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 tradingplatform.trades (
  payment_id character varying(64) NOT NULL -- unique identifier,
  traded_at timestamp,
  cancelled_at timestamp without time zone,
  user_id character varying(256) -- identifier for user,
  buyer_id character varying(64) -- identifier for buyer,
  card_type varchar
)

CREATE TABLE tradingplatform.logs (
  id integer PRIMARY KEY -- unique identifier,
  updated_at date,
  created_at timestamp without time zone,
  language character varying(128),
  username character varying(64) NOT NULL,
  status varchar
)

CREATE TABLE tradingplatform.wallets (
  transaction_id character varying(64) NOT NULL -- unique identifier,
  payment_date timestamp without time zone,
  updated_at timestamp,
  invoice_number character varying(128) NOT NULL,
  vendor_id character varying(128),
  verification_status character varying(128) NOT NULL,
  exchange_rate character varying(256),
  approval_status text
)

[User] List vendor_id, verification_status, transaction_id from wallets.

[Assistant] SELECT vendor_id, verification_status, transaction_id FROM tradingplatform.wallets;

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

[Assistant] SELECT vendor_id, verification_status, transaction_id FROM tradingplatform.wallets ORDER BY transaction_id DESC;

[User] Tally up wallets by payment_date.

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


[User] Get card_type, cancelled_at, traded_at from all trades.

[Assistant] SELECT card_type, cancelled_at, traded_at FROM tradingplatform.trades;

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

[Assistant] SELECT card_type, cancelled_at, traded_at FROM tradingplatform.trades WHERE cancelled_at > '2023-12-01';

[User] Tally up trades by payment_id.

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


[User] Show me all wallets.

[Assistant] SELECT * FROM tradingplatform.wallets;

[User] List wallets with dates from 2023.

[Assistant] SELECT * FROM tradingplatform.wallets WHERE payment_date BETWEEN '2023-01-01' AND '2023-12-31';

[User] Can you order these by payment_date ascending?

[Assistant] SELECT * FROM tradingplatform.wallets WHERE payment_date BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY payment_date ASC;


[User] Retrieve all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

[User] Get all trades created yesterday.

[Assistant] SELECT * FROM tradingplatform.trades WHERE cancelled_at = CURRENT_DATE - INTERVAL '1 day';

[User] Calculate sum of user_id for each traded_at in trades.

[Assistant] SELECT traded_at, SUM(user_id) AS sum_user_id FROM tradingplatform.trades GROUP BY traded_at;


[User] Show me all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

[User] Show the results sorted by card_type descending.

[Assistant] SELECT * FROM tradingplatform.trades ORDER BY card_type DESC;

[User] Only show the top 25 results.

[Assistant] SELECT * FROM tradingplatform.trades ORDER BY card_type DESC LIMIT 25;


[User] List username, status, created_at from logs.

[Assistant] SELECT username, status, created_at FROM tradingplatform.logs;

[User] Find logs older than 6 months.

[Assistant] SELECT username, status, created_at FROM tradingplatform.logs WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Sort the results by updated_at ascending.

[Assistant] SELECT username, status, created_at FROM tradingplatform.logs WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months' ORDER BY updated_at ASC;


[User] Display all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

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

[Assistant] SELECT * FROM tradingplatform.trades WHERE traded_at > '2023-01-01';

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

[Assistant] SELECT * FROM tradingplatform.trades WHERE traded_at > '2023-01-01' ORDER BY buyer_id ASC;


[User] List card_type, traded_at, payment_id from trades.

[Assistant] SELECT card_type, traded_at, payment_id FROM tradingplatform.trades;

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

[Assistant] SELECT card_type, traded_at, payment_id FROM tradingplatform.trades ORDER BY cancelled_at DESC;

[User] Count the number of trades in each cancelled_at category.

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


[User] Show me all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

[User] Find trades from last week.

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

[User] Get the distribution of trades across different traded_at values.

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


[User] Display all logs.

[Assistant] SELECT * FROM tradingplatform.logs;

[User] List logs that have username LIKE 'A%'.

[Assistant] SELECT * FROM tradingplatform.logs WHERE username LIKE 'A%';

[User] Calculate sum of language for each username in logs.

[Assistant] SELECT username, SUM(language) AS sum_language FROM tradingplatform.logs GROUP BY username;


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 (
  invoice_id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp,
  verification_status text,
  payer_id text,
  user_id character varying(256),
  payee_id character varying(256),
  account_id text NOT NULL -- reference to accounts.account_id,
  FOREIGN KEY (account_id) REFERENCES accounts(account_id)
)

CREATE TABLE finance.accounts (
  account_id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp,
  payment_date timestamp,
  payee_id character varying(64),
  verification_status varchar,
  reference_number character varying(128)
)

CREATE TABLE finance.payments (
  transaction_id character varying(64) NOT NULL -- unique identifier,
  completed_at date,
  total integer,
  user_id varchar,
  currency text,
  tax decimal,
  approval_status varchar NOT NULL
)

[User] List created_at, user_id, payer_id from loans.

[Assistant] SELECT created_at, user_id, payer_id FROM finance.loans;

[User] Get invoice_id, created_at, payee_id, created_at by joining loans with accounts.

[Assistant] SELECT created_at, user_id, payer_id, accounts.payee_id, accounts.created_at FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id;

[User] Can you order these by created_at descending?

[Assistant] SELECT created_at, user_id, payer_id, accounts.payee_id, accounts.created_at FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id ORDER BY created_at DESC;


[User] Retrieve all loans.

[Assistant] SELECT * FROM finance.loans;

[User] What payer_id, payee_id, reference_number, payment_date do we have for loans and their associated accounts?

[Assistant] SELECT *, accounts.reference_number, accounts.payment_date FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id;

[User] Tally up loans by created_at.

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


[User] Display all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Retrieve loans where payer_id LIKE 'A%'.

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

[User] Only show the top 20 results.

[Assistant] SELECT * FROM finance.loans WHERE payer_id LIKE 'A%' LIMIT 20;


[User] Display all loans.

[Assistant] SELECT * FROM finance.loans;

[User] List invoice_id, account_id, verification_status, payee_id for each loan along with their account information.

[Assistant] SELECT *, accounts.verification_status, accounts.payee_id FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id;

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

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


[User] Show me payer_id, verification_status, invoice_id for all loans.

[Assistant] SELECT payer_id, verification_status, invoice_id FROM finance.loans;

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

[Assistant] SELECT payer_id, verification_status, invoice_id FROM finance.loans WHERE verification_status LIKE 'A%';

[User] Show me min of account_id grouped by payee_id for loans.

[Assistant] SELECT payee_id, MIN(account_id) AS min_account_id FROM finance.loans GROUP BY payee_id;


[User] Display all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Retrieve payee_id, created_at, payment_date, reference_number showing the relationship between loans and accounts.

[Assistant] SELECT *, accounts.payment_date, accounts.reference_number FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id;

[User] How many loans are there per invoice_id?

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


[User] List payee_id, created_at, invoice_id from loans.

[Assistant] SELECT payee_id, created_at, invoice_id FROM finance.loans;

[User] Get all loans between January and March.

[Assistant] SELECT payee_id, created_at, invoice_id FROM finance.loans WHERE created_at BETWEEN '2023-01-01' AND '2023-03-31';

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

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


[User] What are the payer_id, created_at, payee_id of each loan?

[Assistant] SELECT payer_id, created_at, payee_id FROM finance.loans;

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

[Assistant] SELECT payer_id, created_at, payee_id FROM finance.loans WHERE created_at = CURRENT_DATE - INTERVAL '1 day';

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

[Assistant] SELECT payer_id, created_at, payee_id FROM finance.loans WHERE created_at = CURRENT_DATE - INTERVAL '1 day' ORDER BY user_id ASC;


[User] List payer_id, verification_status, created_at from loans.

[Assistant] SELECT payer_id, verification_status, created_at FROM finance.loans;

[User] List loans with dates from 2023.

[Assistant] SELECT payer_id, verification_status, created_at FROM finance.loans WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Order the output by account_id ascending.

[Assistant] SELECT payer_id, verification_status, created_at FROM finance.loans WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY account_id ASC;


[User] Get user_id, account_id, invoice_id from all loans.

[Assistant] SELECT user_id, account_id, invoice_id FROM finance.loans;

[User] Show me invoice_id, payee_id, verification_status, reference_number from loans and their related accounts.

[Assistant] SELECT user_id, account_id, invoice_id, accounts.verification_status, accounts.reference_number FROM finance.loans JOIN finance.accounts ON loans.account_id = accounts.account_id;

[User] What is the average created_at for each payee_id in loans?

[Assistant] SELECT payee_id, AVERAGE(created_at) AS average_created_at FROM finance.loans GROUP BY payee_id;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.prescriptions (
  id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp,
  updated_at timestamp,
  reconciliation_status character varying(256),
  debit varchar,
  description char,
  invoice_number text
)

CREATE TABLE healthcare.departments (
  id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp,
  last_active date,
  website character varying(256) NOT NULL,
  nationality char,
  birth_date date
)

[User] Show me all departments.

[Assistant] SELECT * FROM healthcare.departments;

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

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

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

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


[User] Retrieve nationality, id, last_active for every department.

[Assistant] SELECT nationality, id, last_active FROM healthcare.departments;

[User] Order the output by last_active ascending.

[Assistant] SELECT nationality, id, last_active FROM healthcare.departments ORDER BY last_active ASC;

[User] What is the count nationality for each last_active in departments?

[Assistant] SELECT last_active, COUNT(nationality) AS count_nationality FROM healthcare.departments GROUP BY last_active;


[User] Get all prescriptions.

[Assistant] SELECT * FROM healthcare.prescriptions;

[User] Show the results sorted by created_at descending.

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

[User] Show the results sorted by reconciliation_status descending.

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


[User] Retrieve nationality, last_active, updated_at for every department.

[Assistant] SELECT nationality, last_active, updated_at FROM healthcare.departments;

[User] Retrieve departments where the date is modified within the last hour.

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

[User] Show the results sorted by birth_date ascending.

[Assistant] SELECT nationality, last_active, updated_at FROM healthcare.departments WHERE last_active >= CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY birth_date ASC;


[User] List all prescriptions.

[Assistant] SELECT * FROM healthcare.prescriptions;

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

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

[User] Return just 50 rows.

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


[User] Get all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Order the output by updated_at descending.

[Assistant] SELECT * FROM healthcare.departments ORDER BY updated_at DESC;

[User] How many departments are there per last_active?

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


[User] List updated_at, id, last_active from departments.

[Assistant] SELECT updated_at, id, last_active FROM healthcare.departments;

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

[Assistant] SELECT updated_at, id, last_active FROM healthcare.departments WHERE updated_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Return just 5 rows.

[Assistant] SELECT updated_at, id, last_active FROM healthcare.departments WHERE updated_at >= CURRENT_DATE - INTERVAL '30 days' LIMIT 5;


[User] List all prescriptions.

[Assistant] SELECT * FROM healthcare.prescriptions;

[User] Get prescriptions that match id LIKE 'A%'.

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

[User] Only show the top 25 results.

[Assistant] SELECT * FROM healthcare.prescriptions WHERE id LIKE 'A%' LIMIT 25;


[User] Get all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Retrieve departments where the date is modified within the last hour.

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

[User] Restrict the output to 15 items.

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


[User] Get updated_at, id, website from all departments.

[Assistant] SELECT updated_at, id, website FROM healthcare.departments;

[User] Get all departments between January and March.

[Assistant] SELECT updated_at, id, website FROM healthcare.departments WHERE birth_date BETWEEN '2023-01-01' AND '2023-03-31';

[User] Get min of nationality by id from departments.

[Assistant] SELECT id, MIN(nationality) AS min_nationality FROM healthcare.departments GROUP BY id;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.patients (
  user_id varchar PRIMARY KEY -- unique identifier,
  last_active date,
  updated_at timestamp,
  email character varying(256),
  zip_code char,
  account_status character varying(128) NOT NULL,
  country char NOT NULL,
  medical_record_id text NOT NULL -- reference to medical_records.item_id,
  FOREIGN KEY (medical_record_id) REFERENCES medical_records(item_id)
)

CREATE TABLE healthcare.prescriptions (
  comment_id text PRIMARY KEY -- unique identifier,
  published_at timestamp,
  shares char,
  content char,
  media_url varchar NOT NULL,
  author_id character varying(64) -- identifier for author,
  tags text
)

CREATE TABLE healthcare.appointments (
  item_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  expires_at timestamp,
  description text,
  media_url text NOT NULL,
  backorder varchar,
  video_url character varying(128),
  price smallint,
  rating character varying(128),
  patient_id text -- reference to patients.user_id,
  FOREIGN KEY (patient_id) REFERENCES patients(user_id)
)

CREATE TABLE healthcare.medical_records (
  item_id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp,
  video_url varchar,
  stock_level character varying(64) NOT NULL,
  category char NOT NULL,
  prescription_id text NOT NULL -- reference to prescriptions.comment_id,
  FOREIGN KEY (prescription_id) REFERENCES prescriptions(comment_id)
)

[User] Get all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

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

[Assistant] SELECT * FROM healthcare.appointments WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Calculate min of video_url for each rating in appointments.

[Assistant] SELECT rating, MIN(video_url) AS min_video_url FROM healthcare.appointments GROUP BY rating;


[User] Retrieve all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

[User] Order the output by stock_level ascending.

[Assistant] SELECT * FROM healthcare.medical_records ORDER BY stock_level ASC;

[User] Show me the count of medical_records grouped by prescription_id.

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


[User] Display all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

[User] Can you order these by stock_level descending?

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

[User] Can you order these by prescription_id ascending?

[Assistant] SELECT * FROM healthcare.medical_records ORDER BY prescription_id 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 insurance.orders (
  id integer PRIMARY KEY -- unique identifier,
  cancelled_at date,
  approval_status character varying(64),
  fee varchar,
  subtotal bigint NOT NULL,
  user_id integer -- reference to users.customer_id,
  FOREIGN KEY (user_id) REFERENCES users(customer_id)
)

CREATE TABLE insurance.users (
  customer_id integer PRIMARY KEY -- unique identifier,
  joined_at timestamp without time zone,
  created_at date,
  timezone char NOT NULL,
  language character varying(64),
  phone text NOT NULL
)

CREATE TABLE insurance.facilities (
  address_id character varying(64) NOT NULL -- unique identifier,
  last_inspected timestamp without time zone,
  coordinates text NOT NULL,
  location_lon character varying(128),
  street char NOT NULL,
  operating_hours character varying(256),
  user_id integer NOT NULL -- reference to users.customer_id,
  FOREIGN KEY (user_id) REFERENCES users(customer_id)
)

[User] Display all orders.

[Assistant] SELECT * FROM insurance.orders;

[User] Can you order these by fee ascending?

[Assistant] SELECT * FROM insurance.orders ORDER BY fee ASC;

[User] Return just 25 rows.

[Assistant] SELECT * FROM insurance.orders ORDER BY fee ASC LIMIT 25;


[User] Display all orders.

[Assistant] SELECT * FROM insurance.orders;

[User] Get orders that match user_id > 42.

[Assistant] SELECT * FROM insurance.orders WHERE user_id > 42;

[User] Group orders by approval_status and show the count of cancelled_at.

[Assistant] SELECT approval_status, COUNT(cancelled_at) AS count_cancelled_at FROM insurance.orders GROUP BY approval_status;


[User] Get last_inspected, address_id, user_id from all facilities.

[Assistant] SELECT last_inspected, address_id, user_id FROM insurance.facilities;

[User] List facilities that have address_id LIKE 'A%'.

[Assistant] SELECT last_inspected, address_id, user_id FROM insurance.facilities WHERE address_id LIKE 'A%';

[User] Calculate min of location_lon for each street in facilities.

[Assistant] SELECT street, MIN(location_lon) AS min_location_lon FROM insurance.facilities GROUP BY street;


[User] What are the cancelled_at, user_id, subtotal of each order?

[Assistant] SELECT cancelled_at, user_id, subtotal FROM insurance.orders;

[User] List cancelled_at, user_id, language, created_at for each order along with their user information.

[Assistant] SELECT cancelled_at, user_id, subtotal, users.language, users.created_at FROM insurance.orders JOIN insurance.users ON orders.user_id = users.customer_id;

[User] Restrict the output to 10 items.

[Assistant] SELECT cancelled_at, user_id, subtotal, users.language, users.created_at FROM insurance.orders JOIN insurance.users ON orders.user_id = users.customer_id LIMIT 10;


[User] List user_id, street, address_id from facilities.

[Assistant] SELECT user_id, street, address_id FROM insurance.facilities;

[User] Show me address_id, last_inspected, language, joined_at from facilities and their related users.

[Assistant] SELECT user_id, street, address_id, users.language, users.joined_at FROM insurance.facilities JOIN insurance.users ON facilities.user_id = users.customer_id;

[User] Restrict the output to 5 items.

[Assistant] SELECT user_id, street, address_id, users.language, users.joined_at FROM insurance.facilities JOIN insurance.users ON facilities.user_id = users.customer_id LIMIT 5;


[User] Display all facilities.

[Assistant] SELECT * FROM insurance.facilities;

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

[Assistant] SELECT * FROM insurance.facilities WHERE last_inspected > '2023-12-01';

[User] Return just 10 rows.

[Assistant] SELECT * FROM insurance.facilities WHERE last_inspected > '2023-12-01' LIMIT 10;


[User] List fee, approval_status, subtotal from orders.

[Assistant] SELECT fee, approval_status, subtotal FROM insurance.orders;

[User] Show me subtotal, user_id, created_at, joined_at from orders and their related users.

[Assistant] SELECT fee, approval_status, subtotal, users.created_at, users.joined_at FROM insurance.orders JOIN insurance.users ON orders.user_id = users.customer_id;

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

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


[User] Show me address_id, street, last_inspected for all facilities.

[Assistant] SELECT address_id, street, last_inspected FROM insurance.facilities;

[User] What last_inspected, coordinates, joined_at, timezone do we have for facilities and their associated users?

[Assistant] SELECT address_id, street, last_inspected, users.joined_at, users.timezone FROM insurance.facilities JOIN insurance.users ON facilities.user_id = users.customer_id;

[User] How many facilities are there per street?

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


[User] Retrieve user_id, last_inspected, location_lon for every facilitie.

[Assistant] SELECT user_id, last_inspected, location_lon FROM insurance.facilities;

[User] Get location_lon, operating_hours, phone, created_at by joining facilities with users.

[Assistant] SELECT user_id, last_inspected, location_lon, users.phone, users.created_at FROM insurance.facilities JOIN insurance.users ON facilities.user_id = users.customer_id;

[User] Show me the count of facilities grouped by last_inspected.

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


[User] Display all orders.

[Assistant] SELECT * FROM insurance.orders;

[User] Get user_id, subtotal, phone, timezone by joining orders with users.

[Assistant] SELECT *, users.phone, users.timezone FROM insurance.orders JOIN insurance.users ON orders.user_id = users.customer_id;

[User] Sort the results by approval_status ascending.

[Assistant] SELECT *, users.phone, users.timezone FROM insurance.orders JOIN insurance.users ON orders.user_id = users.customer_id ORDER BY approval_status 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.events (
  invoice_id character varying(64) NOT NULL -- unique identifier,
  processed_at timestamp without time zone,
  approval_status varchar,
  customer_id character varying(64) -- identifier for customer,
  vendor_id text -- identifier for vendor,
  balance decimal,
  comment_id text -- reference to comments.message_id,
  FOREIGN KEY (comment_id) REFERENCES comments(message_id)
)

CREATE TABLE socialmedia.followers (
  order_id integer PRIMARY KEY -- unique identifier,
  completed_at date,
  fee varchar,
  payment_status char,
  subtotal smallint,
  approval_status varchar,
  card_type text NOT NULL,
  comment_id text NOT NULL -- reference to comments.message_id,
  FOREIGN KEY (comment_id) REFERENCES comments(message_id)
)

CREATE TABLE socialmedia.comments (
  message_id text PRIMARY KEY -- unique identifier,
  edited_at timestamp without time zone,
  parent_id character varying(128),
  likes text NOT NULL,
  visibility character varying(64),
  image_url varchar
)

[User] Show me customer_id, invoice_id, processed_at for all events.

[Assistant] SELECT customer_id, invoice_id, processed_at FROM socialmedia.events;

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

[Assistant] SELECT customer_id, invoice_id, processed_at FROM socialmedia.events WHERE processed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Count the number of events in each customer_id category.

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


[User] Retrieve fee, approval_status, subtotal for every follower.

[Assistant] SELECT fee, approval_status, subtotal FROM socialmedia.followers;

[User] List followers with dates created yesterday.

[Assistant] SELECT fee, approval_status, subtotal FROM socialmedia.followers WHERE completed_at = CURRENT_DATE - INTERVAL '1 day';

[User] Get the distribution of followers across different subtotal values.

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


[User] Get customer_id, vendor_id, processed_at from all events.

[Assistant] SELECT customer_id, vendor_id, processed_at FROM socialmedia.events;

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

[Assistant] SELECT customer_id, vendor_id, processed_at FROM socialmedia.events WHERE processed_at > '2023-12-01';

[User] What is the count balance for each customer_id in events?

[Assistant] SELECT customer_id, COUNT(balance) AS count_balance FROM socialmedia.events GROUP BY customer_id;


[User] Retrieve all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] What approval_status, comment_id, visibility, edited_at do we have for followers and their associated comments?

[Assistant] SELECT *, comments.visibility, comments.edited_at FROM socialmedia.followers JOIN socialmedia.comments ON followers.comment_id = comments.message_id;

[User] Show me the count of followers grouped by card_type.

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


[User] Get all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Retrieve comment_id, card_type, edited_at, image_url showing the relationship between followers and comments.

[Assistant] SELECT *, comments.edited_at, comments.image_url FROM socialmedia.followers JOIN socialmedia.comments ON followers.comment_id = comments.message_id;

[User] Sort the results by payment_status descending.

[Assistant] SELECT *, comments.edited_at, comments.image_url FROM socialmedia.followers JOIN socialmedia.comments ON followers.comment_id = comments.message_id ORDER BY payment_status DESC;


[User] Retrieve all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Retrieve events where balance > 13.

[Assistant] SELECT * FROM socialmedia.events WHERE balance > 13;

[User] Group events by approval_status and show the max of vendor_id.

[Assistant] SELECT approval_status, MAX(vendor_id) AS max_vendor_id FROM socialmedia.events GROUP BY approval_status;


[User] Retrieve all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Show me followers with comment_id LIKE 'A%'.

[Assistant] SELECT * FROM socialmedia.followers WHERE comment_id LIKE 'A%';

[User] Restrict the output to 10 items.

[Assistant] SELECT * FROM socialmedia.followers WHERE comment_id LIKE 'A%' LIMIT 10;


[User] List all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Sort the results by processed_at descending.

[Assistant] SELECT * FROM socialmedia.events ORDER BY processed_at DESC;

[User] Can you order these by balance ascending?

[Assistant] SELECT * FROM socialmedia.events ORDER BY balance ASC;


[User] Retrieve all events.

[Assistant] SELECT * FROM socialmedia.events;

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

[Assistant] SELECT * FROM socialmedia.events ORDER BY comment_id DESC;

[User] Get the distribution of events across different vendor_id values.

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


[User] List balance, customer_id, vendor_id from events.

[Assistant] SELECT balance, customer_id, vendor_id FROM socialmedia.events;

[User] Get processed_at, vendor_id, likes, image_url by joining events with comments.

[Assistant] SELECT balance, customer_id, vendor_id, comments.likes, comments.image_url FROM socialmedia.events JOIN socialmedia.comments ON events.comment_id = comments.message_id;

[User] Order the output by comment_id ascending.

[Assistant] SELECT balance, customer_id, vendor_id, comments.likes, comments.image_url FROM socialmedia.events JOIN socialmedia.comments ON events.comment_id = comments.message_id ORDER BY comment_id 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 inventory.purchases (
  transaction_id integer PRIMARY KEY -- unique identifier,
  completed_at timestamp,
  created_at timestamp without time zone,
  tax numeric,
  total bigint NOT NULL,
  customer_id character varying(256) -- identifier for customer,
  exchange_rate character varying(128)
)

CREATE TABLE inventory.addresses (
  id character varying(64) NOT NULL -- unique identifier,
  last_inspected timestamp,
  created_at timestamp,
  description char,
  parking_available text,
  category character varying(128) NOT NULL,
  purchase_id integer NOT NULL -- reference to purchases.transaction_id,
  FOREIGN KEY (purchase_id) REFERENCES purchases(transaction_id)
)

[User] Show me all addresses.

[Assistant] SELECT * FROM inventory.addresses;

[User] List created_at, id, total, completed_at for each addresse along with their purchase information.

[Assistant] SELECT *, purchases.total, purchases.completed_at FROM inventory.addresses JOIN inventory.purchases ON addresses.purchase_id = purchases.transaction_id;

[User] Group addresses by id and show the min of id.

[Assistant] SELECT id, MIN(id) AS min_id FROM inventory.addresses GROUP BY id;


[User] What are the description, purchase_id, id of each addresse?

[Assistant] SELECT description, purchase_id, id FROM inventory.addresses;

[User] List description, last_inspected, tax, completed_at for each addresse along with their purchase information.

[Assistant] SELECT description, purchase_id, id, purchases.tax, purchases.completed_at FROM inventory.addresses JOIN inventory.purchases ON addresses.purchase_id = purchases.transaction_id;

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

[Assistant] SELECT purchase_id, AVERAGE(purchase_id) AS average_purchase_id FROM inventory.addresses GROUP BY purchase_id;


[User] Get created_at, parking_available, description from all addresses.

[Assistant] SELECT created_at, parking_available, description FROM inventory.addresses;

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

[Assistant] SELECT created_at, parking_available, description FROM inventory.addresses WHERE last_inspected <= CURRENT_DATE - INTERVAL '6 months';

[User] Sort the results by id ascending.

[Assistant] SELECT created_at, parking_available, description FROM inventory.addresses WHERE last_inspected <= CURRENT_DATE - INTERVAL '6 months' ORDER BY id ASC;


[User] Display all addresses.

[Assistant] SELECT * FROM inventory.addresses;

[User] Get last_inspected, created_at, completed_at, tax by joining addresses with purchases.

[Assistant] SELECT *, purchases.completed_at, purchases.tax FROM inventory.addresses JOIN inventory.purchases ON addresses.purchase_id = purchases.transaction_id;

[User] Only show the top 5 results.

[Assistant] SELECT *, purchases.completed_at, purchases.tax FROM inventory.addresses JOIN inventory.purchases ON addresses.purchase_id = purchases.transaction_id LIMIT 5;


[User] List all addresses.

[Assistant] SELECT * FROM inventory.addresses;

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

[Assistant] SELECT * FROM inventory.addresses ORDER BY purchase_id DESC;

[User] Can you order these by created_at descending?

[Assistant] SELECT * FROM inventory.addresses ORDER BY created_at DESC;


[User] List all addresses.

[Assistant] SELECT * FROM inventory.addresses;

[User] Show me addresses that were created yesterday.

[Assistant] SELECT * FROM inventory.addresses WHERE created_at = CURRENT_DATE - INTERVAL '1 day';

[User] Show only 25 records.

[Assistant] SELECT * FROM inventory.addresses WHERE created_at = CURRENT_DATE - INTERVAL '1 day' LIMIT 25;


[User] Get all addresses.

[Assistant] SELECT * FROM inventory.addresses;

[User] Sort the results by description ascending.

[Assistant] SELECT * FROM inventory.addresses ORDER BY description ASC;

[User] Restrict the output to 100 items.

[Assistant] SELECT * FROM inventory.addresses ORDER BY description ASC LIMIT 100;


[User] Show me all addresses.

[Assistant] SELECT * FROM inventory.addresses;

[User] Get created_at, purchase_id, tax, completed_at by joining addresses with purchases.

[Assistant] SELECT *, purchases.tax, purchases.completed_at FROM inventory.addresses JOIN inventory.purchases ON addresses.purchase_id = purchases.transaction_id;

[User] Show the results sorted by last_inspected descending.

[Assistant] SELECT *, purchases.tax, purchases.completed_at FROM inventory.addresses JOIN inventory.purchases ON addresses.purchase_id = purchases.transaction_id ORDER BY last_inspected DESC;


[User] Retrieve description, category, id for every addresse.

[Assistant] SELECT description, category, id FROM inventory.addresses;

[User] Show me addresses that were from 2023.

[Assistant] SELECT description, category, id FROM inventory.addresses WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Group addresses by id and show the average of parking_available.

[Assistant] SELECT id, AVERAGE(parking_available) AS average_parking_available FROM inventory.addresses GROUP BY id;


[User] Display all addresses.

[Assistant] SELECT * FROM inventory.addresses;

[User] List purchase_id, id, total, exchange_rate for each addresse along with their purchase information.

[Assistant] SELECT *, purchases.total, purchases.exchange_rate FROM inventory.addresses JOIN inventory.purchases ON addresses.purchase_id = purchases.transaction_id;

[User] Count the number of addresses in each last_inspected category.

[Assistant] SELECT last_inspected, COUNT(*) AS count FROM inventory.addresses GROUP BY last_inspected ORDER BY count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.audits (
  message_id text PRIMARY KEY -- unique identifier,
  created_at timestamp,
  keywords character varying(64),
  views character varying(128),
  image_url char,
  rating varchar
)

CREATE TABLE finance.accounts (
  account_id character varying(64) NOT NULL -- unique identifier,
  payment_date date,
  balance bigint,
  description char,
  category text NOT NULL,
  invoice_number character varying(256),
  audit_id text NOT NULL -- reference to audits.message_id,
  FOREIGN KEY (audit_id) REFERENCES audits(message_id)
)

[User] Get all accounts.

[Assistant] SELECT * FROM finance.accounts;

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

[Assistant] SELECT * FROM finance.accounts WHERE payment_date >= CURRENT_DATE - INTERVAL '30 days';

[User] Show me count of balance grouped by payment_date for accounts.

[Assistant] SELECT payment_date, COUNT(balance) AS count_balance FROM finance.accounts GROUP BY payment_date;


[User] Retrieve all accounts.

[Assistant] SELECT * FROM finance.accounts;

[User] List accounts that have balance > 50.

[Assistant] SELECT * FROM finance.accounts WHERE balance > 50;

[User] Show me sum of balance grouped by payment_date for accounts.

[Assistant] SELECT payment_date, SUM(balance) AS sum_balance FROM finance.accounts GROUP BY payment_date;


[User] Get audit_id, description, category from all accounts.

[Assistant] SELECT audit_id, description, category FROM finance.accounts;

[User] List description, category, created_at, keywords for each account along with their audit information.

[Assistant] SELECT audit_id, description, category, audits.created_at, audits.keywords FROM finance.accounts JOIN finance.audits ON accounts.audit_id = audits.message_id;

[User] Tally up accounts by category.

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


[User] Show me balance, account_id, description for all accounts.

[Assistant] SELECT balance, account_id, description FROM finance.accounts;

[User] Get accounts that match description LIKE 'A%'.

[Assistant] SELECT balance, account_id, description FROM finance.accounts WHERE description LIKE 'A%';

[User] Group accounts by balance and show the count of audit_id.

[Assistant] SELECT balance, COUNT(audit_id) AS count_audit_id FROM finance.accounts GROUP BY balance;


[User] List all accounts.

[Assistant] SELECT * FROM finance.accounts;

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

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

[User] Show the results sorted by payment_date ascending.

[Assistant] SELECT * FROM finance.accounts WHERE payment_date = CURRENT_DATE - INTERVAL '1 day' ORDER BY payment_date ASC;


[User] Get all accounts.

[Assistant] SELECT * FROM finance.accounts;

[User] Retrieve account_id, payment_date, views, keywords showing the relationship between accounts and audits.

[Assistant] SELECT *, audits.views, audits.keywords FROM finance.accounts JOIN finance.audits ON accounts.audit_id = audits.message_id;

[User] Sort the results by payment_date ascending.

[Assistant] SELECT *, audits.views, audits.keywords FROM finance.accounts JOIN finance.audits ON accounts.audit_id = audits.message_id ORDER BY payment_date ASC;


[User] List all accounts.

[Assistant] SELECT * FROM finance.accounts;

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

[Assistant] SELECT * FROM finance.accounts WHERE payment_date >= CURRENT_DATE - INTERVAL '30 days';

[User] Sort the results by balance ascending.

[Assistant] SELECT * FROM finance.accounts WHERE payment_date >= CURRENT_DATE - INTERVAL '30 days' ORDER BY balance ASC;


[User] Display all accounts.

[Assistant] SELECT * FROM finance.accounts;

[User] Retrieve category, audit_id, keywords, rating showing the relationship between accounts and audits.

[Assistant] SELECT *, audits.keywords, audits.rating FROM finance.accounts JOIN finance.audits ON accounts.audit_id = audits.message_id;

[User] Limit the results to 50 rows.

[Assistant] SELECT *, audits.keywords, audits.rating FROM finance.accounts JOIN finance.audits ON accounts.audit_id = audits.message_id LIMIT 50;


[User] List audit_id, description, invoice_number from accounts.

[Assistant] SELECT audit_id, description, invoice_number FROM finance.accounts;

[User] Order the output by account_id descending.

[Assistant] SELECT audit_id, description, invoice_number FROM finance.accounts ORDER BY account_id DESC;

[User] Count the number of accounts in each payment_date category.

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


[User] Retrieve invoice_number, category, balance for every account.

[Assistant] SELECT invoice_number, category, balance FROM finance.accounts;

[User] Show me account_id, balance, views, rating from accounts and their related audits.

[Assistant] SELECT invoice_number, category, balance, audits.views, audits.rating FROM finance.accounts JOIN finance.audits ON accounts.audit_id = audits.message_id;

[User] Show the results sorted by account_id ascending.

[Assistant] SELECT invoice_number, category, balance, audits.views, audits.rating FROM finance.accounts JOIN finance.audits ON accounts.audit_id = audits.message_id ORDER BY account_id 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 healthcare.appointments (
  id text PRIMARY KEY -- unique identifier,
  created_at date,
  video_url character varying(64),
  image_url character varying(64),
  quantity character varying(64),
  thumbnail_url character varying(256),
  medical_record_id text -- reference to medical_records.venue_id,
  department_id integer NOT NULL -- reference to departments.person_id,
  FOREIGN KEY (medical_record_id) REFERENCES medical_records(venue_id),
  FOREIGN KEY (department_id) REFERENCES departments(person_id)
)

CREATE TABLE healthcare.departments (
  person_id integer PRIMARY KEY -- unique identifier,
  joined_at date,
  last_active timestamp,
  is_verified boolean NOT NULL,
  api_key varchar,
  email varchar,
  birth_date timestamp without time zone,
  status character varying(256) NOT NULL
)

CREATE TABLE healthcare.medical_records (
  venue_id text PRIMARY KEY -- unique identifier,
  last_inspected timestamp without time zone,
  created_at timestamp,
  category character varying(128),
  address_line2 char,
  coordinates character varying(64),
  parking_available text
)

[User] Show me all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Retrieve appointments where medical_record_id LIKE 'A%'.

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

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

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


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] List appointments that have department_id > 82.

[Assistant] SELECT * FROM healthcare.appointments WHERE department_id > 82;

[User] Restrict the output to 10 items.

[Assistant] SELECT * FROM healthcare.appointments WHERE department_id > 82 LIMIT 10;


[User] Show me all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] List video_url, department_id, address_line2, last_inspected for each appointment along with their medical_record information.

[Assistant] SELECT *, medical_records.address_line2, medical_records.last_inspected FROM healthcare.appointments JOIN healthcare.medical_records ON appointments.medical_record_id = medical_records.venue_id;

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

[Assistant] SELECT *, medical_records.address_line2, medical_records.last_inspected FROM healthcare.appointments JOIN healthcare.medical_records ON appointments.medical_record_id = medical_records.venue_id ORDER BY quantity DESC;


[User] List all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Retrieve appointments where quantity LIKE 'A%'.

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

[User] Show the results sorted by medical_record_id descending.

[Assistant] SELECT * FROM healthcare.appointments WHERE quantity LIKE 'A%' ORDER BY medical_record_id DESC;


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

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

[Assistant] SELECT * FROM healthcare.appointments ORDER BY department_id ASC;

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

[Assistant] SELECT quantity, MAX(created_at) AS max_created_at FROM healthcare.appointments GROUP BY quantity;


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

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

[Assistant] SELECT * FROM healthcare.appointments ORDER BY medical_record_id ASC;

[User] Count the number of appointments in each video_url category.

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


[User] Get all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

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

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

[User] Get sum of medical_record_id by video_url from appointments.

[Assistant] SELECT video_url, SUM(medical_record_id) AS sum_medical_record_id FROM healthcare.appointments GROUP BY video_url;


[User] Show me all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Get all appointments from last week.

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

[User] Order the output by video_url ascending.

[Assistant] SELECT * FROM healthcare.appointments WHERE created_at >= CURRENT_DATE - INTERVAL '7 days' ORDER BY video_url ASC;


[User] Get all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Retrieve appointments where medical_record_id LIKE 'A%'.

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

[User] Calculate count of quantity for each thumbnail_url in appointments.

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


[User] Display all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] List appointments with dates created yesterday.

[Assistant] SELECT * FROM healthcare.appointments WHERE created_at = CURRENT_DATE - INTERVAL '1 day';

[User] Restrict the output to 100 items.

[Assistant] SELECT * FROM healthcare.appointments WHERE created_at = CURRENT_DATE - INTERVAL '1 day' LIMIT 100;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE tradingplatform.orders (
  id character varying(64) NOT NULL -- unique identifier,
  completed_at timestamp without time zone,
  product_id char NOT NULL -- identifier for product,
  exchange_rate character varying(128),
  metadat_id text NOT NULL -- reference to metadata.order_id,
  FOREIGN KEY (metadat_id) REFERENCES metadata(order_id)
)

CREATE TABLE tradingplatform.assets (
  id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  price smallint,
  tax_rate character varying(128),
  reserved character varying(256),
  currency varchar
)

CREATE TABLE tradingplatform.metadata (
  order_id varchar PRIMARY KEY -- unique identifier,
  processed_at timestamp,
  traded_at date,
  fee char,
  price numeric(38,14),
  approval_status text,
  asset_id integer NOT NULL -- reference to assets.id,
  FOREIGN KEY (asset_id) REFERENCES assets(id)
)

CREATE TABLE tradingplatform.logs (
  order_id character varying(64) NOT NULL -- unique identifier,
  processed_at timestamp without time zone,
  approval_status character varying(64),
  buyer_id char -- identifier for buyer,
  payment_method character varying(64) NOT NULL,
  card_type varchar,
  customer_id character varying(64),
  delivery_status varchar
)

[User] Display all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] List metadata that have price > 19.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE price > 19;

[User] Get average of traded_at by approval_status from metadata.

[Assistant] SELECT approval_status, AVERAGE(traded_at) AS average_traded_at FROM tradingplatform.metadata GROUP BY approval_status;


[User] Get all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] What fee, processed_at, tax_rate, currency do we have for metadata and their associated assets?

[Assistant] SELECT *, assets.tax_rate, assets.currency FROM tradingplatform.metadata JOIN tradingplatform.assets ON metadata.asset_id = assets.id;

[User] Show only 10 records.

[Assistant] SELECT *, assets.tax_rate, assets.currency FROM tradingplatform.metadata JOIN tradingplatform.assets ON metadata.asset_id = assets.id LIMIT 10;


[User] List asset_id, price, fee from metadata.

[Assistant] SELECT asset_id, price, fee FROM tradingplatform.metadata;

[User] Show me processed_at, price, created_at, price from metadata and their related assets.

[Assistant] SELECT asset_id, price, fee, assets.created_at, assets.price FROM tradingplatform.metadata JOIN tradingplatform.assets ON metadata.asset_id = assets.id;

[User] Order the output by asset_id descending.

[Assistant] SELECT asset_id, price, fee, assets.created_at, assets.price FROM tradingplatform.metadata JOIN tradingplatform.assets ON metadata.asset_id = assets.id ORDER BY asset_id DESC;


[User] Retrieve all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] Show me metadata with processed_at > '2023-01-01'.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE processed_at > '2023-01-01';

[User] Sort the results by approval_status descending.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE processed_at > '2023-01-01' ORDER BY approval_status DESC;


[User] Show me all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] List metadata that have approval_status LIKE 'A%'.

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

[User] Show the results sorted by approval_status descending.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE approval_status LIKE 'A%' ORDER BY approval_status DESC;


[User] List all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

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

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

[User] Limit the results to 100 rows.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE traded_at > '2023-12-01' LIMIT 100;


[User] List all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] Retrieve metadata where the date is between January and March.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE processed_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Show the results sorted by price descending.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE processed_at BETWEEN '2023-01-01' AND '2023-03-31' ORDER BY price DESC;


[User] Retrieve price, processed_at, fee for every metadata.

[Assistant] SELECT price, processed_at, fee FROM tradingplatform.metadata;

[User] Get processed_at, price, price, tax_rate by joining metadata with assets.

[Assistant] SELECT price, processed_at, fee, assets.price, assets.tax_rate FROM tradingplatform.metadata JOIN tradingplatform.assets ON metadata.asset_id = assets.id;

[User] Count the number of metadata in each asset_id category.

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


[User] Retrieve all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

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

[Assistant] SELECT * FROM tradingplatform.metadata WHERE traded_at > '2023-01-01';

[User] Order the output by processed_at ascending.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE traded_at > '2023-01-01' ORDER BY processed_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 education.departments (
  product_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  reserved character varying(128),
  thumbnail_url varchar NOT NULL,
  subcategory varchar,
  msrp character varying(256),
  popularity_score character varying(128) NOT NULL,
  backorder character varying(256)
)

CREATE TABLE education.teachers (
  barcode varchar PRIMARY KEY -- unique identifier,
  expires_at date,
  available character varying(256) NOT NULL,
  subcategory character varying(64),
  video_url text -- identifier for video_url,
  image_url character varying(128) NOT NULL,
  thumbnail_url character varying(128) NOT NULL,
  price bigint NOT NULL
)

CREATE TABLE education.enrollments (
  product_id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp without time zone,
  published_at timestamp without time zone,
  reserved character varying(128),
  featured_rank char,
  price numeric,
  video_url character varying(256) -- identifier for video_url,
  department_id integer -- reference to departments.product_id,
  FOREIGN KEY (department_id) REFERENCES departments(product_id)
)

[User] Retrieve updated_at, video_url, price for every enrollment.

[Assistant] SELECT updated_at, video_url, price FROM education.enrollments;

[User] List enrollments with dates from 2023.

[Assistant] SELECT updated_at, video_url, price FROM education.enrollments WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Show only 15 records.

[Assistant] SELECT updated_at, video_url, price FROM education.enrollments WHERE updated_at BETWEEN '2023-01-01' AND '2023-12-31' LIMIT 15;


[User] Get all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Show me enrollments with reserved LIKE 'A%'.

[Assistant] SELECT * FROM education.enrollments WHERE reserved LIKE 'A%';

[User] Get max of updated_at by updated_at from enrollments.

[Assistant] SELECT updated_at, MAX(updated_at) AS max_updated_at FROM education.enrollments GROUP BY updated_at;


[User] Retrieve product_id, video_url, updated_at for every enrollment.

[Assistant] SELECT product_id, video_url, updated_at FROM education.enrollments;

[User] Get enrollments that match published_at > '2023-01-01'.

[Assistant] SELECT product_id, video_url, updated_at FROM education.enrollments WHERE published_at > '2023-01-01';

[User] Count the number of enrollments in each video_url category.

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


[User] Display all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Order the output by reserved ascending.

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

[User] Can you order these by updated_at ascending?

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


[User] Get updated_at, reserved, featured_rank from all enrollments.

[Assistant] SELECT updated_at, reserved, featured_rank FROM education.enrollments;

[User] Show me enrollments with reserved LIKE 'A%'.

[Assistant] SELECT updated_at, reserved, featured_rank FROM education.enrollments WHERE reserved LIKE 'A%';

[User] Restrict the output to 10 items.

[Assistant] SELECT updated_at, reserved, featured_rank FROM education.enrollments WHERE reserved LIKE 'A%' LIMIT 10;


[User] List all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] What reserved, updated_at, popularity_score, backorder do we have for enrollments and their associated departments?

[Assistant] SELECT *, departments.popularity_score, departments.backorder FROM education.enrollments JOIN education.departments ON enrollments.department_id = departments.product_id;

[User] Only show the top 25 results.

[Assistant] SELECT *, departments.popularity_score, departments.backorder FROM education.enrollments JOIN education.departments ON enrollments.department_id = departments.product_id LIMIT 25;


[User] Retrieve all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] Get all enrollments older than 6 months.

[Assistant] SELECT * FROM education.enrollments WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months';

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

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


[User] What are the published_at, product_id, featured_rank of each enrollment?

[Assistant] SELECT published_at, product_id, featured_rank FROM education.enrollments;

[User] Get enrollments that match price > 71.

[Assistant] SELECT published_at, product_id, featured_rank FROM education.enrollments WHERE price > 71;

[User] Only show the top 15 results.

[Assistant] SELECT published_at, product_id, featured_rank FROM education.enrollments WHERE price > 71 LIMIT 15;


[User] Get all enrollments.

[Assistant] SELECT * FROM education.enrollments;

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

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

[User] Calculate average of updated_at for each updated_at in enrollments.

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


[User] Get all enrollments.

[Assistant] SELECT * FROM education.enrollments;

[User] List enrollments that have department_id > 53.

[Assistant] SELECT * FROM education.enrollments WHERE department_id > 53;

[User] Only show the top 15 results.

[Assistant] SELECT * FROM education.enrollments WHERE department_id > 53 LIMIT 15;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE socialmedia.groups (
  payment_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  traded_at date,
  account_id text,
  payment_method character varying(128),
  exchange_rate character varying(64) NOT NULL,
  subtotal integer,
  payment_status character varying(256)
)

CREATE TABLE socialmedia.comments (
  post_id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp,
  published_at date,
  likes character varying(64),
  shares char,
  categories varchar,
  image_url character varying(128),
  body character varying(64),
  group_id integer NOT NULL -- reference to groups.payment_id,
  FOREIGN KEY (group_id) REFERENCES groups(payment_id)
)

[User] Show me all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] What body, image_url, payment_method, exchange_rate do we have for comments and their associated groups?

[Assistant] SELECT *, groups.payment_method, groups.exchange_rate FROM socialmedia.comments JOIN socialmedia.groups ON comments.group_id = groups.payment_id;

[User] Can you order these by body descending?

[Assistant] SELECT *, groups.payment_method, groups.exchange_rate FROM socialmedia.comments JOIN socialmedia.groups ON comments.group_id = groups.payment_id ORDER BY body DESC;


[User] Show me shares, post_id, created_at for all comments.

[Assistant] SELECT shares, post_id, created_at FROM socialmedia.comments;

[User] Retrieve comments where post_id LIKE 'A%'.

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

[User] Calculate min of likes for each image_url in comments.

[Assistant] SELECT image_url, MIN(likes) AS min_likes FROM socialmedia.comments GROUP BY image_url;


[User] Retrieve likes, post_id, body for every comment.

[Assistant] SELECT likes, post_id, body FROM socialmedia.comments;

[User] Sort the results by post_id ascending.

[Assistant] SELECT likes, post_id, body FROM socialmedia.comments ORDER BY post_id ASC;

[User] What is the sum likes for each likes in comments?

[Assistant] SELECT likes, SUM(likes) AS sum_likes FROM socialmedia.comments GROUP BY likes;


[User] Retrieve post_id, created_at, shares for every comment.

[Assistant] SELECT post_id, created_at, shares FROM socialmedia.comments;

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

[Assistant] SELECT post_id, created_at, shares FROM socialmedia.comments WHERE body LIKE 'A%';

[User] What is the sum post_id for each shares in comments?

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


[User] List likes, group_id, body from comments.

[Assistant] SELECT likes, group_id, body FROM socialmedia.comments;

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

[Assistant] SELECT likes, group_id, body FROM socialmedia.comments WHERE created_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Get count of group_id by group_id from comments.

[Assistant] SELECT group_id, COUNT(group_id) AS count_group_id FROM socialmedia.comments GROUP BY group_id;


[User] Show me all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] Can you order these by group_id ascending?

[Assistant] SELECT * FROM socialmedia.comments ORDER BY group_id ASC;

[User] How many comments are there per shares?

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


[User] List all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] List published_at, body, created_at, payment_status for each comment along with their group information.

[Assistant] SELECT *, groups.created_at, groups.payment_status FROM socialmedia.comments JOIN socialmedia.groups ON comments.group_id = groups.payment_id;

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

[Assistant] SELECT *, groups.created_at, groups.payment_status FROM socialmedia.comments JOIN socialmedia.groups ON comments.group_id = groups.payment_id ORDER BY image_url ASC;


[User] Get group_id, created_at, published_at from all comments.

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

[User] List comments that have group_id > 86.

[Assistant] SELECT group_id, created_at, published_at FROM socialmedia.comments WHERE group_id > 86;

[User] Sort the results by image_url ascending.

[Assistant] SELECT group_id, created_at, published_at FROM socialmedia.comments WHERE group_id > 86 ORDER BY image_url ASC;


[User] What are the categories, post_id, body of each comment?

[Assistant] SELECT categories, post_id, body FROM socialmedia.comments;

[User] Find comments from 2023.

[Assistant] SELECT categories, post_id, body FROM socialmedia.comments WHERE published_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] What is the average likes for each post_id in comments?

[Assistant] SELECT post_id, AVERAGE(likes) AS average_likes FROM socialmedia.comments GROUP BY post_id;


[User] Retrieve all comments.

[Assistant] SELECT * FROM socialmedia.comments;

[User] Get shares, created_at, account_id, subtotal by joining comments with groups.

[Assistant] SELECT *, groups.account_id, groups.subtotal FROM socialmedia.comments JOIN socialmedia.groups ON comments.group_id = groups.payment_id;

[User] Tally up comments by likes.

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