[User] Get score, post_id, published_at from all messages.

[Assistant] SELECT score, post_id, published_at FROM socialmedia.messages;

[User] Can you order these by post_id descending?

[Assistant] SELECT score, post_id, published_at FROM socialmedia.messages ORDER BY post_id DESC;

[User] Show me min of score grouped by score for messages.

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


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,
  published_at timestamp,
  tags character varying(64) NOT NULL,
  score character varying(256),
  author_id character varying(64) -- identifier for author,
  media_url character varying(256),
  shares character varying(128),
  post_id text -- reference to posts.comment_id,
  FOREIGN KEY (post_id) REFERENCES posts(comment_id)
)

CREATE TABLE socialmedia.posts (
  comment_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  subject character varying(64) NOT NULL,
  categories character varying(128) NOT NULL,
  description varchar
)

[User] Retrieve all messages.

[Assistant] SELECT * FROM socialmedia.messages;

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

[Assistant] SELECT * FROM socialmedia.messages WHERE published_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Get max of shares by post_id from messages.

[Assistant] SELECT post_id, MAX(shares) AS max_shares FROM socialmedia.messages GROUP BY post_id;


[User] Show me all messages.

[Assistant] SELECT * FROM socialmedia.messages;

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

[Assistant] SELECT * FROM socialmedia.messages WHERE post_id LIKE 'A%';

[User] Restrict the output to 50 items.

[Assistant] SELECT * FROM socialmedia.messages WHERE post_id LIKE 'A%' LIMIT 50;


[User] List all messages.

[Assistant] SELECT * FROM socialmedia.messages;

[User] Show me messages with published_at > '2023-01-01'.

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

[User] Show me sum of published_at grouped by media_url for messages.

[Assistant] SELECT media_url, SUM(published_at) AS sum_published_at FROM socialmedia.messages GROUP BY media_url;


[User] What are the published_at, post_id, media_url of each message?

[Assistant] SELECT published_at, post_id, media_url FROM socialmedia.messages;

[User] Get media_url, author_id, updated_at, subject by joining messages with posts.

[Assistant] SELECT published_at, post_id, media_url, posts.updated_at, posts.subject FROM socialmedia.messages JOIN socialmedia.posts ON messages.post_id = posts.comment_id;

[User] Show the results sorted by media_url descending.

[Assistant] SELECT published_at, post_id, media_url, posts.updated_at, posts.subject FROM socialmedia.messages JOIN socialmedia.posts ON messages.post_id = posts.comment_id ORDER BY media_url 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.prescriptions (
  location_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  street character varying(256),
  latitude character varying(256) NOT NULL,
  category character varying(256),
  address_line1 char,
  geo_point text,
  billin_id integer NOT NULL -- reference to billing.barcode,
  appointment_id text -- reference to appointments.user_id,
  FOREIGN KEY (billin_id) REFERENCES billing(barcode),
  FOREIGN KEY (appointment_id) REFERENCES appointments(user_id)
)

CREATE TABLE healthcare.billing (
  barcode integer PRIMARY KEY -- unique identifier,
  published_at date,
  featured_rank text NOT NULL,
  media_url varchar,
  cost decimal,
  tax_rate character varying(256),
  category character varying(256),
  stock_level text,
  prescription_id text NOT NULL -- reference to prescriptions.location_id,
  appointment_id text NOT NULL -- reference to appointments.user_id,
  FOREIGN KEY (prescription_id) REFERENCES prescriptions(location_id),
  FOREIGN KEY (appointment_id) REFERENCES appointments(user_id)
)

CREATE TABLE healthcare.appointments (
  user_id text PRIMARY KEY -- unique identifier,
  joined_at timestamp,
  gender character varying(64),
  password_hash varchar,
  is_verified boolean,
  billin_id integer NOT NULL -- reference to billing.barcode,
  FOREIGN KEY (billin_id) REFERENCES billing(barcode)
)

[User] Show me billin_id, gender, joined_at for all appointments.

[Assistant] SELECT billin_id, gender, joined_at FROM healthcare.appointments;

[User] Order the output by gender ascending.

[Assistant] SELECT billin_id, gender, joined_at FROM healthcare.appointments ORDER BY gender ASC;

[User] Restrict the output to 25 items.

[Assistant] SELECT billin_id, gender, joined_at FROM healthcare.appointments ORDER BY gender ASC LIMIT 25;


[User] Get gender, billin_id, is_verified from all appointments.

[Assistant] SELECT gender, billin_id, is_verified FROM healthcare.appointments;

[User] Show the results sorted by gender ascending.

[Assistant] SELECT gender, billin_id, is_verified FROM healthcare.appointments ORDER BY gender ASC;

[User] Group appointments by joined_at and show the average of is_verified.

[Assistant] SELECT joined_at, AVERAGE(is_verified) AS average_is_verified FROM healthcare.appointments GROUP BY joined_at;


[User] List category, prescription_id, media_url from billing.

[Assistant] SELECT category, prescription_id, media_url FROM healthcare.billing;

[User] Find billing where stock_level LIKE 'A%'.

[Assistant] SELECT category, prescription_id, media_url FROM healthcare.billing WHERE stock_level LIKE 'A%';

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

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


[User] List all billing.

[Assistant] SELECT * FROM healthcare.billing;

[User] Find billing older than 6 months.

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

[User] Restrict the output to 15 items.

[Assistant] SELECT * FROM healthcare.billing WHERE published_at <= CURRENT_DATE - INTERVAL '6 months' LIMIT 15;


[User] Show me all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Show the results sorted by is_verified ascending.

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

[User] Restrict the output to 50 items.

[Assistant] SELECT * FROM healthcare.appointments ORDER BY is_verified ASC LIMIT 50;


[User] Display all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Show the results sorted by billin_id descending.

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

[User] How many appointments are there per billin_id?

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


[User] Get media_url, published_at, stock_level from all billing.

[Assistant] SELECT media_url, published_at, stock_level FROM healthcare.billing;

[User] Get billing that match featured_rank LIKE 'A%'.

[Assistant] SELECT media_url, published_at, stock_level FROM healthcare.billing WHERE featured_rank LIKE 'A%';

[User] Tally up billing by appointment_id.

[Assistant] SELECT appointment_id, COUNT(*) AS count FROM healthcare.billing GROUP BY appointment_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 socialmedia.users (
  customer_id character varying(64) NOT NULL -- unique identifier,
  joined_at timestamp without time zone,
  updated_at date,
  membership_level char,
  status varchar NOT NULL,
  full_name text,
  username character varying(64) NOT NULL,
  website character varying(64),
  is_active boolean -- indicates if active is true,
  post_id integer NOT NULL -- reference to posts.post_id,
  FOREIGN KEY (post_id) REFERENCES posts(post_id)
)

CREATE TABLE socialmedia.posts (
  post_id integer PRIMARY KEY -- unique identifier,
  updated_at date,
  user_id character varying(256) -- identifier for user,
  categories text,
  media_url varchar NOT NULL,
  image_url varchar,
  title character varying(128)
)

[User] Retrieve status, updated_at, full_name for every user.

[Assistant] SELECT status, updated_at, full_name FROM socialmedia.users;

[User] What full_name, joined_at, media_url, updated_at do we have for users and their associated posts?

[Assistant] SELECT status, updated_at, full_name, posts.media_url, posts.updated_at FROM socialmedia.users JOIN socialmedia.posts ON users.post_id = posts.post_id;

[User] Show only 25 records.

[Assistant] SELECT status, updated_at, full_name, posts.media_url, posts.updated_at FROM socialmedia.users JOIN socialmedia.posts ON users.post_id = posts.post_id LIMIT 25;


[User] What are the updated_at, customer_id, status of each user?

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

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

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

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

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


[User] Show me all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Show the results sorted by status descending.

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

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

[Assistant] SELECT * FROM socialmedia.users ORDER BY full_name ASC;


[User] Retrieve post_id, status, updated_at for every user.

[Assistant] SELECT post_id, status, updated_at FROM socialmedia.users;

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

[Assistant] SELECT post_id, status, updated_at FROM socialmedia.users WHERE website LIKE 'A%';

[User] What is the sum username for each is_active in users?

[Assistant] SELECT is_active, SUM(username) AS sum_username FROM socialmedia.users GROUP BY is_active;


[User] What are the full_name, is_active, joined_at of each user?

[Assistant] SELECT full_name, is_active, joined_at FROM socialmedia.users;

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

[Assistant] SELECT full_name, is_active, joined_at FROM socialmedia.users WHERE updated_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Restrict the output to 5 items.

[Assistant] SELECT full_name, is_active, joined_at FROM socialmedia.users WHERE updated_at >= CURRENT_DATE - INTERVAL '7 days' LIMIT 5;


[User] Get membership_level, is_active, username from all users.

[Assistant] SELECT membership_level, is_active, username FROM socialmedia.users;

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

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

[User] Return just 15 rows.

[Assistant] SELECT membership_level, is_active, username FROM socialmedia.users WHERE updated_at > '2023-01-01' LIMIT 15;


[User] What are the status, full_name, joined_at of each user?

[Assistant] SELECT status, full_name, joined_at FROM socialmedia.users;

[User] Retrieve post_id, website, title, user_id showing the relationship between users and posts.

[Assistant] SELECT status, full_name, joined_at, posts.title, posts.user_id FROM socialmedia.users JOIN socialmedia.posts ON users.post_id = posts.post_id;

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

[Assistant] SELECT status, full_name, joined_at, posts.title, posts.user_id FROM socialmedia.users JOIN socialmedia.posts ON users.post_id = posts.post_id ORDER BY status DESC;


[User] Display all users.

[Assistant] SELECT * FROM socialmedia.users;

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

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

[User] What is the count membership_level for each username in users?

[Assistant] SELECT username, COUNT(membership_level) AS count_membership_level FROM socialmedia.users GROUP BY username;


[User] Show me all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Retrieve membership_level, is_active, media_url, categories showing the relationship between users and posts.

[Assistant] SELECT *, posts.media_url, posts.categories FROM socialmedia.users JOIN socialmedia.posts ON users.post_id = posts.post_id;

[User] Order the output by status ascending.

[Assistant] SELECT *, posts.media_url, posts.categories FROM socialmedia.users JOIN socialmedia.posts ON users.post_id = posts.post_id ORDER BY status ASC;


[User] Get is_active, status, customer_id from all users.

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

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

[Assistant] SELECT is_active, status, customer_id FROM socialmedia.users WHERE joined_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Show me sum of updated_at grouped by joined_at for users.

[Assistant] SELECT joined_at, SUM(updated_at) AS sum_updated_at FROM socialmedia.users GROUP BY joined_at;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE marketing.merchandise (
  barcode varchar PRIMARY KEY -- unique identifier,
  expires_at timestamp,
  updated_at timestamp without time zone,
  reserved char,
  popularity_score varchar,
  cost numeric(38,14) NOT NULL,
  backorder character varying(256) NOT NULL
)

CREATE TABLE marketing.accounts (
  invoice_id text PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  customer_id text NOT NULL,
  category character varying(128) NOT NULL,
  user_id character varying(256) NOT NULL -- identifier for user,
  reservation_id text NOT NULL -- reference to reservations.invoice_id,
  merchandis_id text NOT NULL -- reference to merchandise.barcode,
  FOREIGN KEY (reservation_id) REFERENCES reservations(invoice_id),
  FOREIGN KEY (merchandis_id) REFERENCES merchandise(barcode)
)

CREATE TABLE marketing.reservations (
  invoice_id varchar PRIMARY KEY -- unique identifier,
  cancelled_at date,
  card_type text,
  exchange_rate text
)

CREATE TABLE marketing.employees (
  id character varying(64) NOT NULL -- unique identifier,
  joined_at timestamp without time zone,
  api_key varchar,
  city char,
  is_verified boolean -- indicates if verified is true,
  merchandis_id text -- reference to merchandise.barcode,
  FOREIGN KEY (merchandis_id) REFERENCES merchandise(barcode)
)

[User] Display all accounts.

[Assistant] SELECT * FROM marketing.accounts;

[User] Find accounts where user_id LIKE 'A%'.

[Assistant] SELECT * FROM marketing.accounts WHERE user_id LIKE 'A%';

[User] Get sum of created_at by reservation_id from accounts.

[Assistant] SELECT reservation_id, SUM(created_at) AS sum_created_at FROM marketing.accounts GROUP BY reservation_id;


[User] List user_id, merchandis_id, reservation_id from accounts.

[Assistant] SELECT user_id, merchandis_id, reservation_id FROM marketing.accounts;

[User] Can you order these by merchandis_id descending?

[Assistant] SELECT user_id, merchandis_id, reservation_id FROM marketing.accounts ORDER BY merchandis_id DESC;

[User] Show the results sorted by merchandis_id descending.

[Assistant] SELECT user_id, merchandis_id, reservation_id FROM marketing.accounts ORDER BY merchandis_id DESC;


[User] Show me all employees.

[Assistant] SELECT * FROM marketing.employees;

[User] Show me employees that were from 2023.

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

[User] Tally up employees by api_key.

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


[User] List all employees.

[Assistant] SELECT * FROM marketing.employees;

[User] Retrieve employees where id LIKE 'A%'.

[Assistant] SELECT * FROM marketing.employees WHERE id LIKE 'A%';

[User] Get sum of merchandis_id by city from employees.

[Assistant] SELECT city, SUM(merchandis_id) AS sum_merchandis_id FROM marketing.employees GROUP BY city;


[User] Retrieve all accounts.

[Assistant] SELECT * FROM marketing.accounts;

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

[Assistant] SELECT * FROM marketing.accounts WHERE created_at > '2023-01-01';

[User] Get sum of user_id by category from accounts.

[Assistant] SELECT category, SUM(user_id) AS sum_user_id FROM marketing.accounts GROUP BY category;


[User] Show me merchandis_id, category, created_at for all accounts.

[Assistant] SELECT merchandis_id, category, created_at FROM marketing.accounts;

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

[Assistant] SELECT merchandis_id, category, created_at FROM marketing.accounts ORDER BY category DESC;

[User] Get the distribution of accounts across different category values.

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


[User] Show me all accounts.

[Assistant] SELECT * FROM marketing.accounts;

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

[Assistant] SELECT * FROM marketing.accounts WHERE reservation_id LIKE 'A%';

[User] Sort the results by created_at descending.

[Assistant] SELECT * FROM marketing.accounts WHERE reservation_id LIKE 'A%' ORDER BY created_at DESC;


[User] What are the merchandis_id, created_at, user_id of each account?

[Assistant] SELECT merchandis_id, created_at, user_id FROM marketing.accounts;

[User] Show me accounts with user_id LIKE 'A%'.

[Assistant] SELECT merchandis_id, created_at, user_id FROM marketing.accounts WHERE user_id LIKE 'A%';

[User] Order the output by customer_id ascending.

[Assistant] SELECT merchandis_id, created_at, user_id FROM marketing.accounts WHERE user_id LIKE 'A%' ORDER BY customer_id ASC;


[User] List all accounts.

[Assistant] SELECT * FROM marketing.accounts;

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

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

[User] What is the count user_id for each created_at in accounts?

[Assistant] SELECT created_at, COUNT(user_id) AS count_user_id FROM marketing.accounts GROUP BY created_at;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.billing (
  location_id text PRIMARY KEY -- unique identifier,
  last_inspected timestamp without time zone,
  parking_available character varying(128),
  capacity character varying(256),
  city character varying(64),
  appointment_id text -- reference to appointments.product_id,
  patient_id text NOT NULL -- reference to patients.id,
  FOREIGN KEY (appointment_id) REFERENCES appointments(product_id),
  FOREIGN KEY (patient_id) REFERENCES patients(id)
)

CREATE TABLE healthcare.appointments (
  product_id text PRIMARY KEY -- unique identifier,
  updated_at date,
  popularity_score varchar,
  stock_level varchar NOT NULL,
  cost numeric(38,14) NOT NULL,
  category character varying(64),
  image_url character varying(64),
  patient_id text NOT NULL -- reference to patients.id,
  FOREIGN KEY (patient_id) REFERENCES patients(id)
)

CREATE TABLE healthcare.patients (
  id varchar PRIMARY KEY -- unique identifier,
  joined_at date,
  updated_at timestamp without time zone,
  state text,
  token char,
  website character varying(256),
  username varchar,
  language text,
  appointment_id text NOT NULL -- reference to appointments.product_id,
  FOREIGN KEY (appointment_id) REFERENCES appointments(product_id)
)

[User] Get all billing.

[Assistant] SELECT * FROM healthcare.billing;

[User] Get city, patient_id, category, patient_id by joining billing with appointments.

[Assistant] SELECT *, appointments.category, appointments.patient_id FROM healthcare.billing JOIN healthcare.appointments ON billing.appointment_id = appointments.product_id;

[User] What is the count last_inspected for each patient_id in billing?

[Assistant] SELECT patient_id, COUNT(last_inspected) AS count_last_inspected FROM healthcare.billing GROUP BY patient_id;


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Show the results sorted by image_url descending.

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

[User] Calculate count of category for each popularity_score in appointments.

[Assistant] SELECT popularity_score, COUNT(category) AS count_category FROM healthcare.appointments GROUP BY popularity_score;


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Get image_url, category, token, state by joining appointments with patients.

[Assistant] SELECT *, patients.token, patients.state FROM healthcare.appointments JOIN healthcare.patients ON appointments.patient_id = patients.id;

[User] Can you order these by patient_id descending?

[Assistant] SELECT *, patients.token, patients.state FROM healthcare.appointments JOIN healthcare.patients ON appointments.patient_id = patients.id ORDER BY patient_id DESC;


[User] Retrieve last_inspected, patient_id, capacity for every billing.

[Assistant] SELECT last_inspected, patient_id, capacity FROM healthcare.billing;

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

[Assistant] SELECT last_inspected, patient_id, capacity FROM healthcare.billing WHERE city LIKE 'A%';

[User] Order the output by capacity ascending.

[Assistant] SELECT last_inspected, patient_id, capacity FROM healthcare.billing WHERE city LIKE 'A%' ORDER BY capacity ASC;


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Get all appointments between January and March.

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

[User] Show only 50 records.

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


[User] List all billing.

[Assistant] SELECT * FROM healthcare.billing;

[User] List last_inspected, city, category, image_url for each billing along with their appointment information.

[Assistant] SELECT *, appointments.category, appointments.image_url FROM healthcare.billing JOIN healthcare.appointments ON billing.appointment_id = appointments.product_id;

[User] Tally up billing by capacity.

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


[User] Get all patients.

[Assistant] SELECT * FROM healthcare.patients;

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

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

[User] Tally up patients by language.

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


[User] Retrieve all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

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

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

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

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


[User] List all appointments.

[Assistant] SELECT * FROM healthcare.appointments;

[User] Show me cost, category, username, language from appointments and their related patients.

[Assistant] SELECT *, patients.username, patients.language FROM healthcare.appointments JOIN healthcare.patients ON appointments.patient_id = patients.id;

[User] Order the output by stock_level ascending.

[Assistant] SELECT *, patients.username, patients.language FROM healthcare.appointments JOIN healthcare.patients ON appointments.patient_id = patients.id ORDER BY stock_level ASC;


[User] Show me all patients.

[Assistant] SELECT * FROM healthcare.patients;

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

[Assistant] SELECT * FROM healthcare.patients WHERE token LIKE 'A%';

[User] Return just 15 rows.

[Assistant] SELECT * FROM healthcare.patients WHERE token LIKE 'A%' 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 e-commerce.order_items (
  item_id integer PRIMARY KEY -- unique identifier,
  created_at date,
  currency character varying(128),
  discount bigint,
  cost numeric,
  available character varying(64) NOT NULL,
  rating character varying(256),
  video_url character varying(256) NOT NULL -- identifier for video_url
)

CREATE TABLE e-commerce.products (
  item_id character varying(64) NOT NULL -- unique identifier,
  published_at timestamp,
  available character varying(256),
  currency text,
  cost numeric(38,14),
  order_item_id integer NOT NULL -- reference to order_items.item_id,
  FOREIGN KEY (order_item_id) REFERENCES order_items(item_id)
)

[User] Retrieve order_item_id, currency, item_id for every product.

[Assistant] SELECT order_item_id, currency, item_id FROM e-commerce.products;

[User] List products with dates from 2023.

[Assistant] SELECT order_item_id, currency, item_id FROM e-commerce.products WHERE published_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Count the number of products in each item_id category.

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


[User] Get cost, currency, published_at from all products.

[Assistant] SELECT cost, currency, published_at FROM e-commerce.products;

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

[Assistant] SELECT cost, currency, published_at FROM e-commerce.products WHERE published_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Can you order these by available ascending?

[Assistant] SELECT cost, currency, published_at FROM e-commerce.products WHERE published_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY available ASC;


[User] List item_id, currency, cost from products.

[Assistant] SELECT item_id, currency, cost FROM e-commerce.products;

[User] Retrieve products where available LIKE 'A%'.

[Assistant] SELECT item_id, currency, cost FROM e-commerce.products WHERE available LIKE 'A%';

[User] Return just 100 rows.

[Assistant] SELECT item_id, currency, cost FROM e-commerce.products WHERE available LIKE 'A%' LIMIT 100;


[User] Retrieve all products.

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

[User] Find products from last week.

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

[User] How many products are there per order_item_id?

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


[User] Retrieve cost, available, currency for every product.

[Assistant] SELECT cost, available, currency FROM e-commerce.products;

[User] Get products that match order_item_id > 50.

[Assistant] SELECT cost, available, currency FROM e-commerce.products WHERE order_item_id > 50;

[User] Sort the results by order_item_id descending.

[Assistant] SELECT cost, available, currency FROM e-commerce.products WHERE order_item_id > 50 ORDER BY order_item_id DESC;


[User] What are the published_at, currency, cost of each product?

[Assistant] SELECT published_at, currency, cost FROM e-commerce.products;

[User] What published_at, cost, available, created_at do we have for products and their associated order_items?

[Assistant] SELECT published_at, currency, cost, order_items.available, order_items.created_at FROM e-commerce.products JOIN e-commerce.order_items ON products.order_item_id = order_items.item_id;

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

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


[User] List all products.

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

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

[Assistant] SELECT * FROM e-commerce.products WHERE published_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

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

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


[User] Show me all products.

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

[User] Sort the results by available ascending.

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

[User] Show only 15 records.

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


[User] Display all products.

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

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

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

[User] Group products by order_item_id and show the average of currency.

[Assistant] SELECT order_item_id, AVERAGE(currency) AS average_currency FROM e-commerce.products GROUP BY order_item_id;


[User] Get all products.

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

[User] Retrieve cost, published_at, rating, cost showing the relationship between products and order_items.

[Assistant] SELECT *, order_items.rating, order_items.cost FROM e-commerce.products JOIN e-commerce.order_items ON products.order_item_id = order_items.item_id;

[User] What is the max cost for each available in products?

[Assistant] SELECT available, MAX(cost) AS max_cost FROM e-commerce.products GROUP BY available;


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 (
  order_id integer PRIMARY KEY -- unique identifier,
  completed_at date,
  processed_at timestamp,
  seller_id character varying(64) -- identifier for seller,
  total bigint NOT NULL,
  exchange_rate character varying(256) NOT NULL,
  discount numeric NOT NULL,
  status text,
  payment_status character varying(128),
  user_id integer NOT NULL -- reference to users.id,
  FOREIGN KEY (user_id) REFERENCES users(id)
)

CREATE TABLE tradingplatform.notifications (
  id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  format character varying(256),
  visibility text,
  author_id varchar,
  text char NOT NULL,
  thumbnail character varying(64),
  reply_to_id char -- identifier for reply_to,
  trade_id integer -- reference to trades.order_id,
  FOREIGN KEY (trade_id) REFERENCES trades(order_id)
)

CREATE TABLE tradingplatform.users (
  id integer PRIMARY KEY -- unique identifier,
  joined_at timestamp without time zone,
  display_name character varying(128),
  first_name char,
  language character varying(64),
  notification_id text NOT NULL -- reference to notifications.id,
  FOREIGN KEY (notification_id) REFERENCES notifications(id)
)

[User] Display all users.

[Assistant] SELECT * FROM tradingplatform.users;

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

[Assistant] SELECT * FROM tradingplatform.users WHERE notification_id LIKE 'A%';

[User] Order the output by language descending.

[Assistant] SELECT * FROM tradingplatform.users WHERE notification_id LIKE 'A%' ORDER BY language DESC;


[User] Get notification_id, joined_at, language from all users.

[Assistant] SELECT notification_id, joined_at, language FROM tradingplatform.users;

[User] Order the output by joined_at ascending.

[Assistant] SELECT notification_id, joined_at, language FROM tradingplatform.users ORDER BY joined_at ASC;

[User] Show the results sorted by joined_at descending.

[Assistant] SELECT notification_id, joined_at, language FROM tradingplatform.users ORDER BY joined_at DESC;


[User] Show me joined_at, display_name, first_name for all users.

[Assistant] SELECT joined_at, display_name, first_name FROM tradingplatform.users;

[User] Show the results sorted by joined_at descending.

[Assistant] SELECT joined_at, display_name, first_name FROM tradingplatform.users ORDER BY joined_at DESC;

[User] Restrict the output to 50 items.

[Assistant] SELECT joined_at, display_name, first_name FROM tradingplatform.users ORDER BY joined_at DESC LIMIT 50;


[User] Retrieve first_name, language, display_name for every user.

[Assistant] SELECT first_name, language, display_name FROM tradingplatform.users;

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

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

[User] Sort the results by notification_id ascending.

[Assistant] SELECT first_name, language, display_name FROM tradingplatform.users WHERE display_name LIKE 'A%' ORDER BY notification_id ASC;


[User] List all users.

[Assistant] SELECT * FROM tradingplatform.users;

[User] Find users modified within the last hour.

[Assistant] SELECT * FROM tradingplatform.users WHERE joined_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Can you order these by display_name ascending?

[Assistant] SELECT * FROM tradingplatform.users WHERE joined_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY display_name ASC;


[User] Show me all notifications.

[Assistant] SELECT * FROM tradingplatform.notifications;

[User] Order the output by reply_to_id descending.

[Assistant] SELECT * FROM tradingplatform.notifications ORDER BY reply_to_id DESC;

[User] Tally up notifications by author_id.

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


[User] Show me all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

[User] Can you order these by exchange_rate descending?

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

[User] Only show the top 5 results.

[Assistant] SELECT * FROM tradingplatform.trades ORDER BY exchange_rate DESC LIMIT 5;


[User] List payment_status, completed_at, user_id from trades.

[Assistant] SELECT payment_status, completed_at, user_id FROM tradingplatform.trades;

[User] What completed_at, payment_status, first_name, display_name do we have for trades and their associated users?

[Assistant] SELECT payment_status, completed_at, user_id, users.first_name, users.display_name FROM tradingplatform.trades JOIN tradingplatform.users ON trades.user_id = users.id;

[User] Group trades by seller_id and show the count of exchange_rate.

[Assistant] SELECT seller_id, COUNT(exchange_rate) AS count_exchange_rate FROM tradingplatform.trades GROUP BY seller_id;


[User] Get all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

[User] Retrieve completed_at, discount, notification_id, joined_at showing the relationship between trades and users.

[Assistant] SELECT *, users.notification_id, users.joined_at FROM tradingplatform.trades JOIN tradingplatform.users ON trades.user_id = users.id;

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

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


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 gaming.inventory (
  product_id text PRIMARY KEY -- unique identifier,
  published_at date,
  updated_at timestamp,
  msrp character varying(256),
  popularity_score character varying(128),
  video_url char -- identifier for video_url,
  branche_id integer -- reference to branches.location_id,
  FOREIGN KEY (branche_id) REFERENCES branches(location_id)
)

CREATE TABLE gaming.branches (
  location_id integer PRIMARY KEY -- unique identifier,
  last_inspected date,
  category character varying(128),
  timezone character varying(256),
  latitude character varying(64) NOT NULL,
  parking_available varchar NOT NULL,
  accessibility character varying(64)
)

[User] List published_at, video_url, popularity_score from inventory.

[Assistant] SELECT published_at, video_url, popularity_score FROM gaming.inventory;

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

[Assistant] SELECT published_at, video_url, popularity_score FROM gaming.inventory WHERE published_at > '2023-01-01';

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

[Assistant] SELECT published_at, video_url, popularity_score FROM gaming.inventory WHERE published_at > '2023-01-01' ORDER BY branche_id ASC;


[User] Get all inventory.

[Assistant] SELECT * FROM gaming.inventory;

[User] Can you order these by popularity_score descending?

[Assistant] SELECT * FROM gaming.inventory ORDER BY popularity_score DESC;

[User] Sort the results by published_at descending.

[Assistant] SELECT * FROM gaming.inventory ORDER BY published_at DESC;


[User] List branche_id, published_at, video_url from inventory.

[Assistant] SELECT branche_id, published_at, video_url FROM gaming.inventory;

[User] List inventory that have updated_at > '2023-01-01'.

[Assistant] SELECT branche_id, published_at, video_url FROM gaming.inventory WHERE updated_at > '2023-01-01';

[User] Tally up inventory by popularity_score.

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


[User] List all inventory.

[Assistant] SELECT * FROM gaming.inventory;

[User] Order the output by popularity_score ascending.

[Assistant] SELECT * FROM gaming.inventory ORDER BY popularity_score ASC;

[User] Calculate sum of popularity_score for each popularity_score in inventory.

[Assistant] SELECT popularity_score, SUM(popularity_score) AS sum_popularity_score FROM gaming.inventory GROUP BY popularity_score;


[User] Display all inventory.

[Assistant] SELECT * FROM gaming.inventory;

[User] Order the output by popularity_score ascending.

[Assistant] SELECT * FROM gaming.inventory ORDER BY popularity_score ASC;

[User] Show only 10 records.

[Assistant] SELECT * FROM gaming.inventory ORDER BY popularity_score ASC LIMIT 10;


[User] List video_url, branche_id, published_at from inventory.

[Assistant] SELECT video_url, branche_id, published_at FROM gaming.inventory;

[User] Get inventory that match popularity_score LIKE 'A%'.

[Assistant] SELECT video_url, branche_id, published_at FROM gaming.inventory WHERE popularity_score LIKE 'A%';

[User] Group inventory by branche_id and show the average of popularity_score.

[Assistant] SELECT branche_id, AVERAGE(popularity_score) AS average_popularity_score FROM gaming.inventory GROUP BY branche_id;


[User] Get branche_id, published_at, msrp from all inventory.

[Assistant] SELECT branche_id, published_at, msrp FROM gaming.inventory;

[User] Get inventory that match popularity_score LIKE 'A%'.

[Assistant] SELECT branche_id, published_at, msrp FROM gaming.inventory WHERE popularity_score LIKE 'A%';

[User] Get the distribution of inventory across different branche_id values.

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


[User] Retrieve updated_at, video_url, published_at for every inventory.

[Assistant] SELECT updated_at, video_url, published_at FROM gaming.inventory;

[User] Get video_url, branche_id, category, timezone by joining inventory with branches.

[Assistant] SELECT updated_at, video_url, published_at, branches.category, branches.timezone FROM gaming.inventory JOIN gaming.branches ON inventory.branche_id = branches.location_id;

[User] Calculate average of updated_at for each popularity_score in inventory.

[Assistant] SELECT popularity_score, AVERAGE(updated_at) AS average_updated_at FROM gaming.inventory GROUP BY popularity_score;


[User] Display all inventory.

[Assistant] SELECT * FROM gaming.inventory;

[User] List inventory that have popularity_score LIKE 'A%'.

[Assistant] SELECT * FROM gaming.inventory WHERE popularity_score LIKE 'A%';

[User] Limit the results to 50 rows.

[Assistant] SELECT * FROM gaming.inventory WHERE popularity_score LIKE 'A%' LIMIT 50;


[User] Get all inventory.

[Assistant] SELECT * FROM gaming.inventory;

[User] Find inventory where video_url LIKE 'A%'.

[Assistant] SELECT * FROM gaming.inventory WHERE video_url LIKE 'A%';

[User] Order the output by video_url ascending.

[Assistant] SELECT * FROM gaming.inventory WHERE video_url LIKE 'A%' ORDER BY video_url 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.students (
  user_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  joined_at timestamp without time zone,
  age character varying(256),
  is_verified bit NOT NULL -- indicates if verified is true,
  birth_date timestamp without time zone NOT NULL,
  membership_level text,
  password_hash varchar,
  username character varying(64),
  zip_code character varying(128)
)

CREATE TABLE education.teachers (
  content_id character varying(64) NOT NULL -- unique identifier,
  published_at timestamp without time zone,
  shares character varying(64),
  user_id character varying(128),
  thumbnail char NOT NULL,
  message char NOT NULL,
  content character varying(64) NOT NULL,
  rating varchar
)

CREATE TABLE education.assignments (
  post_id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp,
  published_at date,
  reply_to_id character varying(128),
  message character varying(128),
  format character varying(64) NOT NULL,
  visibility varchar,
  department_id text -- reference to departments.invoice_id,
  FOREIGN KEY (department_id) REFERENCES departments(invoice_id)
)

CREATE TABLE education.departments (
  invoice_id text PRIMARY KEY -- unique identifier,
  completed_at timestamp,
  amount decimal,
  seller_id character varying(128) NOT NULL,
  price decimal,
  total decimal NOT NULL,
  currency character varying(64)
)

[User] Retrieve format, updated_at, reply_to_id for every assignment.

[Assistant] SELECT format, updated_at, reply_to_id FROM education.assignments;

[User] Find assignments where published_at > '2023-01-01'.

[Assistant] SELECT format, updated_at, reply_to_id FROM education.assignments WHERE published_at > '2023-01-01';

[User] Limit the results to 10 rows.

[Assistant] SELECT format, updated_at, reply_to_id FROM education.assignments WHERE published_at > '2023-01-01' LIMIT 10;


[User] Get all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Retrieve assignments where format LIKE 'A%'.

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

[User] Order the output by department_id descending.

[Assistant] SELECT * FROM education.assignments WHERE format LIKE 'A%' ORDER BY department_id DESC;


[User] Display all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Retrieve assignments where message LIKE 'A%'.

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

[User] Sort the results by message descending.

[Assistant] SELECT * FROM education.assignments WHERE message LIKE 'A%' ORDER BY message DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE e-commerce.reviews (
  id varchar PRIMARY KEY -- unique identifier,
  updated_at date,
  published_at timestamp without time zone,
  parent_id character varying(256),
  views text,
  media_url character varying(128),
  visibility character varying(128) NOT NULL,
  description char,
  categorie_id text -- reference to categories.post_id,
  FOREIGN KEY (categorie_id) REFERENCES categories(post_id)
)

CREATE TABLE e-commerce.categories (
  post_id text PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  created_at timestamp,
  visibility character varying(128),
  body character varying(64),
  media_url varchar NOT NULL,
  thumbnail character varying(256) NOT NULL
)

[User] Retrieve description, updated_at, media_url for every review.

[Assistant] SELECT description, updated_at, media_url FROM e-commerce.reviews;

[User] Show me description, media_url, created_at, media_url from reviews and their related categories.

[Assistant] SELECT description, updated_at, media_url, categories.created_at, categories.media_url FROM e-commerce.reviews JOIN e-commerce.categories ON reviews.categorie_id = categories.post_id;

[User] Order the output by media_url ascending.

[Assistant] SELECT description, updated_at, media_url, categories.created_at, categories.media_url FROM e-commerce.reviews JOIN e-commerce.categories ON reviews.categorie_id = categories.post_id ORDER BY media_url ASC;


[User] Retrieve all reviews.

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

[User] Show the results sorted by published_at descending.

[Assistant] SELECT * FROM e-commerce.reviews ORDER BY published_at DESC;

[User] Calculate min of views for each media_url in reviews.

[Assistant] SELECT media_url, MIN(views) AS min_views FROM e-commerce.reviews GROUP BY media_url;


[User] Retrieve all reviews.

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

[User] Retrieve published_at, parent_id, media_url, thumbnail showing the relationship between reviews and categories.

[Assistant] SELECT *, categories.media_url, categories.thumbnail FROM e-commerce.reviews JOIN e-commerce.categories ON reviews.categorie_id = categories.post_id;

[User] Show the results sorted by parent_id descending.

[Assistant] SELECT *, categories.media_url, categories.thumbnail FROM e-commerce.reviews JOIN e-commerce.categories ON reviews.categorie_id = categories.post_id ORDER BY parent_id DESC;


[User] Get all reviews.

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

[User] List reviews that have description LIKE 'A%'.

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

[User] Show the results sorted by published_at ascending.

[Assistant] SELECT * FROM e-commerce.reviews WHERE description LIKE 'A%' ORDER BY published_at ASC;


[User] Show me updated_at, categorie_id, parent_id for all reviews.

[Assistant] SELECT updated_at, categorie_id, parent_id FROM e-commerce.reviews;

[User] Can you order these by visibility ascending?

[Assistant] SELECT updated_at, categorie_id, parent_id FROM e-commerce.reviews ORDER BY visibility ASC;

[User] Show me count of media_url grouped by categorie_id for reviews.

[Assistant] SELECT categorie_id, COUNT(media_url) AS count_media_url FROM e-commerce.reviews GROUP BY categorie_id;


[User] Get all reviews.

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

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

[Assistant] SELECT * FROM e-commerce.reviews WHERE published_at > '2023-12-01';

[User] Can you order these by views descending?

[Assistant] SELECT * FROM e-commerce.reviews WHERE published_at > '2023-12-01' ORDER BY views DESC;


[User] What are the views, description, updated_at of each review?

[Assistant] SELECT views, description, updated_at FROM e-commerce.reviews;

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

[Assistant] SELECT views, description, updated_at FROM e-commerce.reviews WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Calculate min of parent_id for each updated_at in reviews.

[Assistant] SELECT updated_at, MIN(parent_id) AS min_parent_id FROM e-commerce.reviews GROUP BY updated_at;


[User] List published_at, description, media_url from reviews.

[Assistant] SELECT published_at, description, media_url FROM e-commerce.reviews;

[User] Show me reviews with visibility LIKE 'A%'.

[Assistant] SELECT published_at, description, media_url FROM e-commerce.reviews WHERE visibility LIKE 'A%';

[User] Return just 15 rows.

[Assistant] SELECT published_at, description, media_url FROM e-commerce.reviews WHERE visibility LIKE 'A%' LIMIT 15;


[User] Retrieve parent_id, categorie_id, media_url for every review.

[Assistant] SELECT parent_id, categorie_id, media_url FROM e-commerce.reviews;

[User] List reviews that have updated_at > '2023-01-01'.

[Assistant] SELECT parent_id, categorie_id, media_url FROM e-commerce.reviews WHERE updated_at > '2023-01-01';

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

[Assistant] SELECT parent_id, categorie_id, media_url FROM e-commerce.reviews WHERE updated_at > '2023-01-01' ORDER BY views DESC;


[User] Retrieve all reviews.

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

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

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

[User] Group reviews by parent_id and show the average of visibility.

[Assistant] SELECT parent_id, AVERAGE(visibility) AS average_visibility FROM e-commerce.reviews GROUP BY parent_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 e-commerce.order_items (
  id varchar PRIMARY KEY -- unique identifier,
  created_at date,
  postal_code character varying(128),
  latitude char,
  coordinates varchar NOT NULL,
  review_id text -- reference to reviews.id,
  FOREIGN KEY (review_id) REFERENCES reviews(id)
)

CREATE TABLE e-commerce.inventory (
  sku varchar PRIMARY KEY -- unique identifier,
  expires_at timestamp,
  updated_at timestamp without time zone,
  msrp character varying(64),
  media_url character varying(256),
  views text,
  brand text,
  name varchar NOT NULL,
  popularity_score character varying(128),
  review_id text -- reference to reviews.id,
  FOREIGN KEY (review_id) REFERENCES reviews(id)
)

CREATE TABLE e-commerce.reviews (
  id text PRIMARY KEY -- unique identifier,
  edited_at timestamp,
  image_url character varying(256),
  categories varchar,
  shares text,
  likes varchar,
  order_item_id text -- reference to order_items.id,
  FOREIGN KEY (order_item_id) REFERENCES order_items(id)
)

[User] What are the brand, review_id, expires_at of each inventory?

[Assistant] SELECT brand, review_id, expires_at FROM e-commerce.inventory;

[User] Get all inventory created yesterday.

[Assistant] SELECT brand, review_id, expires_at FROM e-commerce.inventory WHERE updated_at = CURRENT_DATE - INTERVAL '1 day';

[User] Show the results sorted by views descending.

[Assistant] SELECT brand, review_id, expires_at FROM e-commerce.inventory WHERE updated_at = CURRENT_DATE - INTERVAL '1 day' ORDER BY views DESC;


[User] List review_id, created_at, coordinates from order_items.

[Assistant] SELECT review_id, created_at, coordinates FROM e-commerce.order_items;

[User] Show the results sorted by created_at descending.

[Assistant] SELECT review_id, created_at, coordinates FROM e-commerce.order_items ORDER BY created_at DESC;

[User] Show only 50 records.

[Assistant] SELECT review_id, created_at, coordinates FROM e-commerce.order_items ORDER BY created_at DESC LIMIT 50;


[User] Get all reviews.

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

[User] What order_item_id, edited_at, postal_code, review_id do we have for reviews and their associated order_items?

[Assistant] SELECT *, order_items.postal_code, order_items.review_id FROM e-commerce.reviews JOIN e-commerce.order_items ON reviews.order_item_id = order_items.id;

[User] Can you order these by edited_at descending?

[Assistant] SELECT *, order_items.postal_code, order_items.review_id FROM e-commerce.reviews JOIN e-commerce.order_items ON reviews.order_item_id = order_items.id ORDER BY edited_at DESC;


[User] Get all order_items.

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

[User] What review_id, coordinates, likes, order_item_id do we have for order_items and their associated reviews?

[Assistant] SELECT *, reviews.likes, reviews.order_item_id FROM e-commerce.order_items JOIN e-commerce.reviews ON order_items.review_id = reviews.id;

[User] Show only 5 records.

[Assistant] SELECT *, reviews.likes, reviews.order_item_id FROM e-commerce.order_items JOIN e-commerce.reviews ON order_items.review_id = reviews.id LIMIT 5;


[User] Get categories, shares, likes from all reviews.

[Assistant] SELECT categories, shares, likes FROM e-commerce.reviews;

[User] Find reviews where shares LIKE 'A%'.

[Assistant] SELECT categories, shares, likes FROM e-commerce.reviews WHERE shares LIKE 'A%';

[User] Get max of likes by order_item_id from reviews.

[Assistant] SELECT order_item_id, MAX(likes) AS max_likes FROM e-commerce.reviews GROUP BY order_item_id;


[User] Get all inventory.

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

[User] List inventory that have updated_at > '2023-01-01'.

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

[User] Tally up inventory by brand.

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


[User] List coordinates, created_at, review_id from order_items.

[Assistant] SELECT coordinates, created_at, review_id FROM e-commerce.order_items;

[User] Find order_items where postal_code LIKE 'A%'.

[Assistant] SELECT coordinates, created_at, review_id FROM e-commerce.order_items WHERE postal_code LIKE 'A%';

[User] Order the output by review_id ascending.

[Assistant] SELECT coordinates, created_at, review_id FROM e-commerce.order_items WHERE postal_code LIKE 'A%' ORDER BY review_id ASC;


[User] Show me all inventory.

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

[User] Sort the results by msrp ascending.

[Assistant] SELECT * FROM e-commerce.inventory ORDER BY msrp ASC;

[User] Can you order these by popularity_score ascending?

[Assistant] SELECT * FROM e-commerce.inventory ORDER BY popularity_score ASC;


[User] What are the edited_at, image_url, shares of each review?

[Assistant] SELECT edited_at, image_url, shares FROM e-commerce.reviews;

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

[Assistant] SELECT edited_at, image_url, shares FROM e-commerce.reviews WHERE edited_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Group reviews by edited_at and show the min of image_url.

[Assistant] SELECT edited_at, MIN(image_url) AS min_image_url FROM e-commerce.reviews GROUP BY edited_at;


[User] What are the latitude, review_id, created_at of each order_item?

[Assistant] SELECT latitude, review_id, created_at FROM e-commerce.order_items;

[User] List postal_code, coordinates, categories, shares for each order_item along with their review information.

[Assistant] SELECT latitude, review_id, created_at, reviews.categories, reviews.shares FROM e-commerce.order_items JOIN e-commerce.reviews ON order_items.review_id = reviews.id;

[User] Tally up order_items by review_id.

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.departments (
  transaction_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  notes varchar NOT NULL,
  status character varying(64),
  reconciliation_status text,
  verification_status character varying(64)
)

CREATE TABLE healthcare.patients (
  employee_id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp,
  last_active timestamp without time zone,
  is_verified bit -- indicates if verified is true,
  nationality character varying(128),
  password_hash varchar NOT NULL,
  api_key char,
  bio varchar,
  last_name character varying(64),
  avatar character varying(128),
  medical_record_id integer -- reference to medical_records.barcode,
  FOREIGN KEY (medical_record_id) REFERENCES medical_records(barcode)
)

CREATE TABLE healthcare.medical_records (
  barcode integer PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  published_at timestamp without time zone,
  category character varying(64),
  tax_rate character varying(256),
  manufacturer varchar
)

[User] Show me nationality, avatar, password_hash for all patients.

[Assistant] SELECT nationality, avatar, password_hash FROM healthcare.patients;

[User] Show the results sorted by bio descending.

[Assistant] SELECT nationality, avatar, password_hash FROM healthcare.patients ORDER BY bio DESC;

[User] Calculate min of bio for each medical_record_id in patients.

[Assistant] SELECT medical_record_id, MIN(bio) AS min_bio FROM healthcare.patients GROUP BY medical_record_id;


[User] Get nationality, bio, last_name from all patients.

[Assistant] SELECT nationality, bio, last_name FROM healthcare.patients;

[User] Show me nationality, last_name, published_at, manufacturer from patients and their related medical_records.

[Assistant] SELECT nationality, bio, last_name, medical_records.published_at, medical_records.manufacturer FROM healthcare.patients JOIN healthcare.medical_records ON patients.medical_record_id = medical_records.barcode;

[User] Calculate average of nationality for each medical_record_id in patients.

[Assistant] SELECT medical_record_id, AVERAGE(nationality) AS average_nationality FROM healthcare.patients GROUP BY medical_record_id;


[User] What are the medical_record_id, bio, created_at of each patient?

[Assistant] SELECT medical_record_id, bio, created_at FROM healthcare.patients;

[User] Show me patients with is_verified = TRUE.

[Assistant] SELECT medical_record_id, bio, created_at FROM healthcare.patients WHERE is_verified = TRUE;

[User] Limit the results to 10 rows.

[Assistant] SELECT medical_record_id, bio, created_at FROM healthcare.patients WHERE is_verified = TRUE LIMIT 10;


[User] List all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] Can you order these by password_hash ascending?

[Assistant] SELECT * FROM healthcare.patients ORDER BY password_hash ASC;

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

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


[User] Retrieve all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] Sort the results by employee_id descending.

[Assistant] SELECT * FROM healthcare.patients ORDER BY employee_id DESC;

[User] Group patients by created_at and show the min of created_at.

[Assistant] SELECT created_at, MIN(created_at) AS min_created_at FROM healthcare.patients GROUP BY created_at;


[User] Get last_name, avatar, employee_id from all patients.

[Assistant] SELECT last_name, avatar, employee_id FROM healthcare.patients;

[User] Show the results sorted by api_key descending.

[Assistant] SELECT last_name, avatar, employee_id FROM healthcare.patients ORDER BY api_key DESC;

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

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


[User] What are the employee_id, created_at, password_hash of each patient?

[Assistant] SELECT employee_id, created_at, password_hash FROM healthcare.patients;

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

[Assistant] SELECT employee_id, created_at, password_hash FROM healthcare.patients WHERE created_at > '2023-12-01';

[User] Return just 25 rows.

[Assistant] SELECT employee_id, created_at, password_hash FROM healthcare.patients WHERE created_at > '2023-12-01' LIMIT 25;


[User] Show me all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] Retrieve patients where password_hash LIKE 'A%'.

[Assistant] SELECT * FROM healthcare.patients WHERE password_hash LIKE 'A%';

[User] Show me the count of patients grouped by avatar.

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


[User] List employee_id, nationality, password_hash from patients.

[Assistant] SELECT employee_id, nationality, password_hash FROM healthcare.patients;

[User] List nationality, is_verified, tax_rate, updated_at for each patient along with their medical_record information.

[Assistant] SELECT employee_id, nationality, password_hash, medical_records.tax_rate, medical_records.updated_at FROM healthcare.patients JOIN healthcare.medical_records ON patients.medical_record_id = medical_records.barcode;

[User] Show me the count of patients grouped by is_verified.

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


[User] Get all patients.

[Assistant] SELECT * FROM healthcare.patients;

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

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

[User] What is the count medical_record_id for each password_hash in patients?

[Assistant] SELECT password_hash, COUNT(medical_record_id) AS count_medical_record_id FROM healthcare.patients GROUP BY password_hash;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE e-commerce.categories (
  person_id text PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  email char,
  zip_code character varying(64),
  country character varying(256),
  timezone character varying(128) NOT NULL
)

CREATE TABLE e-commerce.products (
  id character varying(64) NOT NULL -- unique identifier,
  expires_at timestamp without time zone,
  published_at timestamp,
  popularity_score character varying(256),
  available varchar,
  featured_rank character varying(256) NOT NULL,
  categorie_id text -- reference to categories.person_id,
  FOREIGN KEY (categorie_id) REFERENCES categories(person_id)
)

CREATE TABLE e-commerce.inventory (
  product_id character varying(64) NOT NULL -- unique identifier,
  published_at timestamp,
  image_url varchar,
  currency character varying(128) NOT NULL,
  name text
)

[User] List all products.

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

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

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

[User] Order the output by published_at descending.

[Assistant] SELECT * FROM e-commerce.products WHERE published_at >= CURRENT_DATE - INTERVAL '30 days' ORDER BY published_at DESC;


[User] Show me all products.

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

[User] Show me products with available LIKE 'A%'.

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

[User] Show only 10 records.

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


[User] Show me featured_rank, published_at, categorie_id for all products.

[Assistant] SELECT featured_rank, published_at, categorie_id FROM e-commerce.products;

[User] Order the output by popularity_score descending.

[Assistant] SELECT featured_rank, published_at, categorie_id FROM e-commerce.products ORDER BY popularity_score DESC;

[User] Limit the results to 25 rows.

[Assistant] SELECT featured_rank, published_at, categorie_id FROM e-commerce.products ORDER BY popularity_score DESC LIMIT 25;


[User] Retrieve all products.

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

[User] List published_at, expires_at, updated_at, timezone for each product along with their categorie information.

[Assistant] SELECT *, categories.updated_at, categories.timezone FROM e-commerce.products JOIN e-commerce.categories ON products.categorie_id = categories.person_id;

[User] Show me count of popularity_score grouped by available for products.

[Assistant] SELECT available, COUNT(popularity_score) AS count_popularity_score FROM e-commerce.products GROUP BY available;


[User] Get id, expires_at, featured_rank from all products.

[Assistant] SELECT id, expires_at, featured_rank FROM e-commerce.products;

[User] Order the output by id descending.

[Assistant] SELECT id, expires_at, featured_rank FROM e-commerce.products ORDER BY id DESC;

[User] Tally up products by featured_rank.

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


[User] List available, categorie_id, featured_rank from products.

[Assistant] SELECT available, categorie_id, featured_rank FROM e-commerce.products;

[User] Get all products between January and March.

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

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

[Assistant] SELECT available, categorie_id, featured_rank FROM e-commerce.products WHERE expires_at BETWEEN '2023-01-01' AND '2023-03-31' ORDER BY popularity_score DESC;


[User] Get categorie_id, popularity_score, id from all products.

[Assistant] SELECT categorie_id, popularity_score, id FROM e-commerce.products;

[User] Show me products that were created yesterday.

[Assistant] SELECT categorie_id, popularity_score, id FROM e-commerce.products WHERE published_at = CURRENT_DATE - INTERVAL '1 day';

[User] Show only 20 records.

[Assistant] SELECT categorie_id, popularity_score, id FROM e-commerce.products WHERE published_at = CURRENT_DATE - INTERVAL '1 day' LIMIT 20;


[User] Retrieve all products.

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

[User] Order the output by popularity_score descending.

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

[User] Can you order these by categorie_id descending?

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


[User] Display all products.

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

[User] Retrieve expires_at, available, country, updated_at showing the relationship between products and categories.

[Assistant] SELECT *, categories.country, categories.updated_at FROM e-commerce.products JOIN e-commerce.categories ON products.categorie_id = categories.person_id;

[User] Return just 5 rows.

[Assistant] SELECT *, categories.country, categories.updated_at FROM e-commerce.products JOIN e-commerce.categories ON products.categorie_id = categories.person_id LIMIT 5;


[User] List all products.

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

[User] Can you order these by published_at descending?

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE socialmedia.users (
  customer_id integer PRIMARY KEY -- unique identifier,
  joined_at date,
  created_at date,
  password_hash character varying(64),
  nationality char,
  state character varying(128),
  birth_date date NOT NULL,
  website text NOT NULL,
  avatar character varying(64),
  event_id text -- reference to events.payment_id,
  FOREIGN KEY (event_id) REFERENCES events(payment_id)
)

CREATE TABLE socialmedia.events (
  payment_id varchar PRIMARY KEY -- unique identifier,
  completed_at timestamp,
  updated_at date,
  card_type character varying(256),
  seller_id text -- identifier for seller,
  quantity text NOT NULL,
  total bigint NOT NULL,
  price numeric,
  payment_status character varying(64) NOT NULL,
  delivery_status varchar
)

[User] Get joined_at, birth_date, event_id from all users.

[Assistant] SELECT joined_at, birth_date, event_id FROM socialmedia.users;

[User] List users with dates created yesterday.

[Assistant] SELECT joined_at, birth_date, event_id FROM socialmedia.users WHERE joined_at = CURRENT_DATE - INTERVAL '1 day';

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

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


[User] Display all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Can you order these by password_hash ascending?

[Assistant] SELECT * FROM socialmedia.users ORDER BY password_hash ASC;

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

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


[User] Display all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Sort the results by joined_at descending.

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

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

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


[User] Get all users.

[Assistant] SELECT * FROM socialmedia.users;

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

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

[User] What is the sum state for each password_hash in users?

[Assistant] SELECT password_hash, SUM(state) AS sum_state FROM socialmedia.users GROUP BY password_hash;


[User] Retrieve created_at, website, event_id for every user.

[Assistant] SELECT created_at, website, event_id FROM socialmedia.users;

[User] Order the output by birth_date ascending.

[Assistant] SELECT created_at, website, event_id FROM socialmedia.users ORDER BY birth_date ASC;

[User] Calculate max of event_id for each state in users.

[Assistant] SELECT state, MAX(event_id) AS max_event_id FROM socialmedia.users GROUP BY state;


[User] Retrieve website, state, avatar for every user.

[Assistant] SELECT website, state, avatar FROM socialmedia.users;

[User] Show the results sorted by website ascending.

[Assistant] SELECT website, state, avatar FROM socialmedia.users ORDER BY website ASC;

[User] Sort the results by avatar ascending.

[Assistant] SELECT website, state, avatar FROM socialmedia.users ORDER BY avatar ASC;


[User] Get birth_date, event_id, website from all users.

[Assistant] SELECT birth_date, event_id, website FROM socialmedia.users;

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

[Assistant] SELECT birth_date, event_id, website FROM socialmedia.users WHERE created_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Get max of birth_date by joined_at from users.

[Assistant] SELECT joined_at, MAX(birth_date) AS max_birth_date FROM socialmedia.users GROUP BY joined_at;


[User] Get joined_at, birth_date, event_id from all users.

[Assistant] SELECT joined_at, birth_date, event_id FROM socialmedia.users;

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

[Assistant] SELECT joined_at, birth_date, event_id FROM socialmedia.users WHERE password_hash LIKE 'A%';

[User] How many users are there per event_id?

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


[User] Display all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] What nationality, password_hash, updated_at, payment_status do we have for users and their associated events?

[Assistant] SELECT *, events.updated_at, events.payment_status FROM socialmedia.users JOIN socialmedia.events ON users.event_id = events.payment_id;

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

[Assistant] SELECT website, MAX(created_at) AS max_created_at FROM socialmedia.users GROUP BY website;


[User] Retrieve all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] What state, password_hash, updated_at, delivery_status do we have for users and their associated events?

[Assistant] SELECT *, events.updated_at, events.delivery_status FROM socialmedia.users JOIN socialmedia.events ON users.event_id = events.payment_id;

[User] Limit the results to 25 rows.

[Assistant] SELECT *, events.updated_at, events.delivery_status FROM socialmedia.users JOIN socialmedia.events ON users.event_id = events.payment_id LIMIT 25;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.accounts (
  transaction_id integer PRIMARY KEY -- unique identifier,
  payment_date date,
  credit character varying(128) NOT NULL,
  approval_status text NOT NULL,
  customer_id varchar NOT NULL,
  verification_status text NOT NULL,
  reference_number text,
  vendor_id character varying(64) NOT NULL -- identifier for vendor
)

CREATE TABLE finance.investments (
  id integer PRIMARY KEY -- unique identifier,
  due_date timestamp,
  approval_status character varying(256),
  payee_id text -- identifier for payee,
  notes character varying(64),
  vendor_id character varying(64) -- identifier for vendor,
  user_id varchar -- identifier for user
)

CREATE TABLE finance.audits (
  customer_id character varying(64) NOT NULL -- unique identifier,
  joined_at date,
  created_at timestamp,
  token character varying(256),
  zip_code character varying(128),
  nationality character varying(256)
)

[User] List user_id, approval_status, notes from investments.

[Assistant] SELECT user_id, approval_status, notes FROM finance.investments;

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

[Assistant] SELECT user_id, approval_status, notes FROM finance.investments WHERE due_date > '2023-12-01';

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

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


[User] Retrieve payment_date, vendor_id, customer_id for every account.

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

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

[Assistant] SELECT payment_date, vendor_id, customer_id FROM finance.accounts WHERE payment_date <= CURRENT_DATE - INTERVAL '6 months';

[User] Group accounts by credit and show the count of customer_id.

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


[User] Display all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Order the output by customer_id ascending.

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

[User] What is the sum created_at for each token in audits?

[Assistant] SELECT token, SUM(created_at) AS sum_created_at FROM finance.audits GROUP BY token;


[User] What are the customer_id, approval_status, verification_status of each account?

[Assistant] SELECT customer_id, approval_status, verification_status FROM finance.accounts;

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

[Assistant] SELECT customer_id, approval_status, verification_status FROM finance.accounts WHERE payment_date >= CURRENT_DATE - INTERVAL '30 days';

[User] Restrict the output to 5 items.

[Assistant] SELECT customer_id, approval_status, verification_status FROM finance.accounts WHERE payment_date >= CURRENT_DATE - INTERVAL '30 days' LIMIT 5;


[User] Get all accounts.

[Assistant] SELECT * FROM finance.accounts;

[User] Retrieve accounts where payment_date > '2023-01-01'.

[Assistant] SELECT * FROM finance.accounts WHERE payment_date > '2023-01-01';

[User] Limit the results to 10 rows.

[Assistant] SELECT * FROM finance.accounts WHERE payment_date > '2023-01-01' LIMIT 10;


[User] Retrieve all investments.

[Assistant] SELECT * FROM finance.investments;

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

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

[User] Only show the top 15 results.

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


[User] Show me all accounts.

[Assistant] SELECT * FROM finance.accounts;

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

[Assistant] SELECT * FROM finance.accounts WHERE customer_id LIKE 'A%';

[User] Get average of payment_date by payment_date from accounts.

[Assistant] SELECT payment_date, AVERAGE(payment_date) AS average_payment_date FROM finance.accounts GROUP BY payment_date;


[User] Get all accounts.

[Assistant] SELECT * FROM finance.accounts;

[User] Retrieve accounts where vendor_id LIKE 'A%'.

[Assistant] SELECT * FROM finance.accounts WHERE vendor_id LIKE 'A%';

[User] Tally up accounts by vendor_id.

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


[User] Display all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Can you order these by created_at ascending?

[Assistant] SELECT * FROM finance.audits ORDER BY created_at ASC;

[User] Order the output by created_at descending.

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


[User] Retrieve token, joined_at, created_at for every audit.

[Assistant] SELECT token, joined_at, created_at FROM finance.audits;

[User] Show the results sorted by joined_at descending.

[Assistant] SELECT token, joined_at, created_at FROM finance.audits ORDER BY joined_at DESC;

[User] How many audits are there per zip_code?

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE events.addresses (
  venue_id varchar PRIMARY KEY -- unique identifier,
  updated_at date,
  created_at timestamp without time zone,
  type character varying(256),
  location_lon char,
  postal_code character varying(64) NOT NULL,
  good_id integer NOT NULL -- reference to goods.id,
  FOREIGN KEY (good_id) REFERENCES goods(id)
)

CREATE TABLE events.goods (
  id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  published_at timestamp,
  description character varying(128),
  media_url varchar NOT NULL,
  tax_rate character varying(128),
  name varchar NOT NULL,
  views varchar NOT NULL,
  addresse_id text NOT NULL -- reference to addresses.venue_id,
  FOREIGN KEY (addresse_id) REFERENCES addresses(venue_id)
)

CREATE TABLE events.accounts (
  account_id character varying(64) NOT NULL -- unique identifier,
  processed_at date,
  vendor_id varchar NOT NULL,
  reference_number varchar,
  exchange_rate varchar,
  invoice_number varchar,
  approval_status character varying(256),
  currency text,
  payee_id char -- identifier for payee,
  good_id integer NOT NULL -- reference to goods.id,
  FOREIGN KEY (good_id) REFERENCES goods(id)
)

CREATE TABLE events.members (
  user_id integer PRIMARY KEY -- unique identifier,
  joined_at date,
  updated_at timestamp without time zone,
  gender character varying(128),
  city text,
  language text,
  zip_code character varying(128)
)

[User] Show me all addresses.

[Assistant] SELECT * FROM events.addresses;

[User] List addresses that have type LIKE 'A%'.

[Assistant] SELECT * FROM events.addresses WHERE type LIKE 'A%';

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

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


[User] Display all accounts.

[Assistant] SELECT * FROM events.accounts;

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

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

[User] Restrict the output to 50 items.

[Assistant] SELECT * FROM events.accounts WHERE processed_at > '2023-12-01' LIMIT 50;


[User] Retrieve all goods.

[Assistant] SELECT * FROM events.goods;

[User] Can you order these by name descending?

[Assistant] SELECT * FROM events.goods ORDER BY name DESC;

[User] Only show the top 5 results.

[Assistant] SELECT * FROM events.goods ORDER BY name DESC LIMIT 5;


[User] Show me tax_rate, published_at, views for all goods.

[Assistant] SELECT tax_rate, published_at, views FROM events.goods;

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

[Assistant] SELECT tax_rate, published_at, views FROM events.goods WHERE description LIKE 'A%';

[User] Show me the count of goods grouped by description.

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


[User] Show me all addresses.

[Assistant] SELECT * FROM events.addresses;

[User] Order the output by location_lon descending.

[Assistant] SELECT * FROM events.addresses ORDER BY location_lon DESC;

[User] What is the sum postal_code for each location_lon in addresses?

[Assistant] SELECT location_lon, SUM(postal_code) AS sum_postal_code FROM events.addresses GROUP BY location_lon;


[User] Get all accounts.

[Assistant] SELECT * FROM events.accounts;

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

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

[User] Show the results sorted by payee_id descending.

[Assistant] SELECT * FROM events.accounts WHERE processed_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY payee_id DESC;


[User] Show me all goods.

[Assistant] SELECT * FROM events.goods;

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

[Assistant] SELECT * FROM events.goods ORDER BY media_url DESC;

[User] Limit the results to 25 rows.

[Assistant] SELECT * FROM events.goods ORDER BY media_url DESC LIMIT 25;


[User] Retrieve all goods.

[Assistant] SELECT * FROM events.goods;

[User] Show the results sorted by name descending.

[Assistant] SELECT * FROM events.goods ORDER BY name DESC;

[User] Return just 15 rows.

[Assistant] SELECT * FROM events.goods ORDER BY name DESC 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.followers (
  content_id text PRIMARY KEY -- unique identifier,
  edited_at timestamp,
  views character varying(128),
  title text,
  attachment_url text NOT NULL,
  image_url character varying(64),
  format character varying(64),
  user_id char -- identifier for user,
  group_id text NOT NULL -- reference to groups.content_id,
  FOREIGN KEY (group_id) REFERENCES groups(content_id)
)

CREATE TABLE socialmedia.events (
  product_id character varying(64) NOT NULL -- unique identifier,
  published_at timestamp without time zone,
  updated_at timestamp,
  available text,
  cost decimal,
  backorder varchar NOT NULL,
  name text,
  description varchar
)

CREATE TABLE socialmedia.comments (
  id character varying(64) NOT NULL -- unique identifier,
  edited_at timestamp,
  shares char,
  rating text,
  media_url character varying(64),
  keywords text NOT NULL,
  content character varying(64),
  author_id character varying(64)
)

CREATE TABLE socialmedia.groups (
  content_id text PRIMARY KEY -- unique identifier,
  created_at date,
  published_at date,
  user_id character varying(256),
  likes varchar NOT NULL,
  views character varying(64) NOT NULL,
  reply_to_id varchar
)

[User] Get all followers.

[Assistant] SELECT * FROM socialmedia.followers;

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

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

[User] Count the number of followers in each title category.

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


[User] Show me all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Show the results sorted by title descending.

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

[User] Calculate count of attachment_url for each edited_at in followers.

[Assistant] SELECT edited_at, COUNT(attachment_url) AS count_attachment_url FROM socialmedia.followers GROUP BY edited_at;


[User] Retrieve edited_at, title, attachment_url for every follower.

[Assistant] SELECT edited_at, title, attachment_url FROM socialmedia.followers;

[User] Can you order these by format descending?

[Assistant] SELECT edited_at, title, attachment_url FROM socialmedia.followers ORDER BY format DESC;

[User] Group followers by edited_at and show the count of edited_at.

[Assistant] SELECT edited_at, COUNT(edited_at) AS count_edited_at FROM socialmedia.followers GROUP BY edited_at;


[User] List views, group_id, title from followers.

[Assistant] SELECT views, group_id, title FROM socialmedia.followers;

[User] Show the results sorted by title ascending.

[Assistant] SELECT views, group_id, title FROM socialmedia.followers ORDER BY title ASC;

[User] Group followers by group_id and show the sum of edited_at.

[Assistant] SELECT group_id, SUM(edited_at) AS sum_edited_at FROM socialmedia.followers GROUP BY group_id;


[User] Get all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] List followers with dates from 2023.

[Assistant] SELECT * FROM socialmedia.followers WHERE edited_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Order the output by user_id descending.

[Assistant] SELECT * FROM socialmedia.followers WHERE edited_at BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY user_id DESC;


[User] What are the group_id, user_id, title of each follower?

[Assistant] SELECT group_id, user_id, title FROM socialmedia.followers;

[User] Show the results sorted by user_id ascending.

[Assistant] SELECT group_id, user_id, title FROM socialmedia.followers ORDER BY user_id ASC;

[User] Limit the results to 20 rows.

[Assistant] SELECT group_id, user_id, title FROM socialmedia.followers ORDER BY user_id ASC LIMIT 20;


[User] List all followers.

[Assistant] SELECT * FROM socialmedia.followers;

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

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

[User] Sort the results by views descending.

[Assistant] SELECT * FROM socialmedia.followers WHERE views LIKE 'A%' ORDER BY views DESC;


[User] List user_id, views, group_id from followers.

[Assistant] SELECT user_id, views, group_id FROM socialmedia.followers;

[User] Get all followers created yesterday.

[Assistant] SELECT user_id, views, group_id FROM socialmedia.followers WHERE edited_at = CURRENT_DATE - INTERVAL '1 day';

[User] Group followers by group_id and show the sum of group_id.

[Assistant] SELECT group_id, SUM(group_id) AS sum_group_id FROM socialmedia.followers GROUP BY group_id;


[User] Display all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Show the results sorted by edited_at ascending.

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

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

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


[User] What are the title, views, image_url of each follower?

[Assistant] SELECT title, views, image_url FROM socialmedia.followers;

[User] Retrieve attachment_url, image_url, published_at, user_id showing the relationship between followers and groups.

[Assistant] SELECT title, views, image_url, groups.published_at, groups.user_id FROM socialmedia.followers JOIN socialmedia.groups ON followers.group_id = groups.content_id;

[User] Calculate count of views for each user_id in followers.

[Assistant] SELECT user_id, COUNT(views) AS count_views FROM socialmedia.followers GROUP BY user_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 tradingplatform.wallets (
  account_id text PRIMARY KEY -- unique identifier,
  processed_at timestamp without time zone,
  payment_date date,
  credit character varying(256) NOT NULL,
  reconciliation_status character varying(128),
  category char,
  exchange_rate character varying(256),
  balance bigint,
  verification_status character varying(64) NOT NULL,
  log_id text -- reference to logs.customer_id,
  FOREIGN KEY (log_id) REFERENCES logs(customer_id)
)

CREATE TABLE tradingplatform.trades (
  order_id integer PRIMARY KEY -- unique identifier,
  traded_at timestamp,
  payment_method character varying(64),
  product_id character varying(128) NOT NULL -- identifier for product,
  exchange_rate character varying(128) NOT NULL,
  status character varying(64),
  quantity char NOT NULL,
  seller_id varchar,
  wallet_id text NOT NULL -- reference to wallets.account_id,
  FOREIGN KEY (wallet_id) REFERENCES wallets(account_id)
)

CREATE TABLE tradingplatform.logs (
  customer_id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp,
  timezone character varying(256),
  account_status char NOT NULL,
  is_verified boolean NOT NULL -- indicates if verified is true
)

[User] Show me balance, credit, category for all wallets.

[Assistant] SELECT balance, credit, category FROM tradingplatform.wallets;

[User] Sort the results by payment_date ascending.

[Assistant] SELECT balance, credit, category FROM tradingplatform.wallets ORDER BY payment_date ASC;

[User] Tally up wallets by verification_status.

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


[User] Show me exchange_rate, verification_status, reconciliation_status for all wallets.

[Assistant] SELECT exchange_rate, verification_status, reconciliation_status FROM tradingplatform.wallets;

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

[Assistant] SELECT exchange_rate, verification_status, reconciliation_status FROM tradingplatform.wallets WHERE processed_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Limit the results to 25 rows.

[Assistant] SELECT exchange_rate, verification_status, reconciliation_status FROM tradingplatform.wallets WHERE processed_at >= CURRENT_DATE - INTERVAL '7 days' LIMIT 25;


[User] List credit, processed_at, log_id from wallets.

[Assistant] SELECT credit, processed_at, log_id FROM tradingplatform.wallets;

[User] Can you order these by category ascending?

[Assistant] SELECT credit, processed_at, log_id FROM tradingplatform.wallets ORDER BY category ASC;

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

[Assistant] SELECT credit, processed_at, log_id FROM tradingplatform.wallets ORDER BY reconciliation_status ASC;


[User] Retrieve log_id, verification_status, credit for every wallet.

[Assistant] SELECT log_id, verification_status, credit FROM tradingplatform.wallets;

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

[Assistant] SELECT log_id, verification_status, credit FROM tradingplatform.wallets ORDER BY exchange_rate ASC;

[User] Show me max of category grouped by balance for wallets.

[Assistant] SELECT balance, MAX(category) AS max_category FROM tradingplatform.wallets GROUP BY balance;


[User] Get balance, processed_at, verification_status from all wallets.

[Assistant] SELECT balance, processed_at, verification_status FROM tradingplatform.wallets;

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

[Assistant] SELECT balance, processed_at, verification_status FROM tradingplatform.wallets WHERE payment_date >= CURRENT_DATE - INTERVAL '30 days';

[User] How many wallets are there per log_id?

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


[User] Get all wallets.

[Assistant] SELECT * FROM tradingplatform.wallets;

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

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

[User] Only show the top 100 results.

[Assistant] SELECT * FROM tradingplatform.wallets WHERE category LIKE 'A%' LIMIT 100;


[User] Show me all trades.

[Assistant] SELECT * FROM tradingplatform.trades;

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

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

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

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


[User] Retrieve verification_status, reconciliation_status, log_id for every wallet.

[Assistant] SELECT verification_status, reconciliation_status, log_id FROM tradingplatform.wallets;

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

[Assistant] SELECT verification_status, reconciliation_status, log_id FROM tradingplatform.wallets WHERE payment_date >= CURRENT_DATE - INTERVAL '30 days';

[User] How many wallets are there per processed_at?

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


[User] Show me all wallets.

[Assistant] SELECT * FROM tradingplatform.wallets;

[User] List wallets that have category LIKE 'A%'.

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

[User] Tally up wallets by exchange_rate.

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


[User] Retrieve all wallets.

[Assistant] SELECT * FROM tradingplatform.wallets;

[User] Get payment_date, log_id, timezone, is_verified by joining wallets with logs.

[Assistant] SELECT *, logs.timezone, logs.is_verified FROM tradingplatform.wallets JOIN tradingplatform.logs ON wallets.log_id = logs.customer_id;

[User] Count the number of wallets in each log_id category.

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.medical_records (
  id text PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  approval_status character varying(256) NOT NULL,
  payment_method varchar NOT NULL,
  prescription_id text -- reference to prescriptions.sku,
  FOREIGN KEY (prescription_id) REFERENCES prescriptions(sku)
)

CREATE TABLE healthcare.patients (
  customer_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  joined_at date,
  username varchar,
  last_login timestamp without time zone,
  city character varying(128) NOT NULL
)

CREATE TABLE healthcare.prescriptions (
  sku varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  featured_rank text,
  image_url character varying(256) NOT NULL,
  quantity char,
  subcategory text,
  patient_id integer -- reference to patients.customer_id,
  FOREIGN KEY (patient_id) REFERENCES patients(customer_id)
)

CREATE TABLE healthcare.billing (
  id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  thumbnail character varying(128),
  user_id character varying(64) NOT NULL -- identifier for user,
  score char,
  author_id character varying(128)
)

[User] Retrieve all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

[User] Show me updated_at, prescription_id, featured_rank, quantity from medical_records and their related prescriptions.

[Assistant] SELECT *, prescriptions.featured_rank, prescriptions.quantity FROM healthcare.medical_records JOIN healthcare.prescriptions ON medical_records.prescription_id = prescriptions.sku;

[User] What is the min approval_status for each updated_at in medical_records?

[Assistant] SELECT updated_at, MIN(approval_status) AS min_approval_status FROM healthcare.medical_records GROUP BY updated_at;


[User] List all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

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

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

[User] Restrict the output to 25 items.

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


[User] List updated_at, approval_status, payment_method from medical_records.

[Assistant] SELECT updated_at, approval_status, payment_method FROM healthcare.medical_records;

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

[Assistant] SELECT updated_at, approval_status, payment_method FROM healthcare.medical_records ORDER BY payment_method ASC;

[User] Limit the results to 15 rows.

[Assistant] SELECT updated_at, approval_status, payment_method FROM healthcare.medical_records ORDER BY payment_method ASC LIMIT 15;


[User] What are the featured_rank, image_url, subcategory of each prescription?

[Assistant] SELECT featured_rank, image_url, subcategory FROM healthcare.prescriptions;

[User] Sort the results by featured_rank descending.

[Assistant] SELECT featured_rank, image_url, subcategory FROM healthcare.prescriptions ORDER BY featured_rank DESC;

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

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


[User] Retrieve prescription_id, updated_at, payment_method for every medical_record.

[Assistant] SELECT prescription_id, updated_at, payment_method FROM healthcare.medical_records;

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

[Assistant] SELECT prescription_id, updated_at, payment_method FROM healthcare.medical_records WHERE updated_at >= CURRENT_DATE - INTERVAL '30 days';

[User] Calculate max of updated_at for each prescription_id in medical_records.

[Assistant] SELECT prescription_id, MAX(updated_at) AS max_updated_at FROM healthcare.medical_records GROUP BY prescription_id;