[User] Show me state, last_active, api_key for all students.

[Assistant] SELECT state, last_active, api_key FROM education.students;

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

[Assistant] SELECT state, last_active, api_key FROM education.students WHERE last_active >= CURRENT_DATE - INTERVAL '30 days';

[User] Order the output by last_active ascending.

[Assistant] SELECT state, last_active, api_key FROM education.students WHERE last_active >= CURRENT_DATE - INTERVAL '30 days' ORDER BY last_active 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.grades (
  post_id character varying(64) NOT NULL -- unique identifier,
  updated_at date,
  published_at date,
  shares char NOT NULL,
  attachment_url character varying(128),
  user_id varchar
)

CREATE TABLE education.students (
  id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp,
  last_active timestamp,
  state character varying(256) NOT NULL,
  api_key character varying(256),
  token character varying(64) NOT NULL,
  avatar character varying(64) NOT NULL,
  bio character varying(256)
)

[User] Show me attachment_url, published_at, post_id for all grades.

[Assistant] SELECT attachment_url, published_at, post_id FROM education.grades;

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

[Assistant] SELECT attachment_url, published_at, post_id FROM education.grades WHERE updated_at > '2023-01-01';

[User] Return just 5 rows.

[Assistant] SELECT attachment_url, published_at, post_id FROM education.grades WHERE updated_at > '2023-01-01' LIMIT 5;


[User] List all grades.

[Assistant] SELECT * FROM education.grades;

[User] Show me grades that were created yesterday.

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

[User] Sort the results by updated_at descending.

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


[User] Get published_at, updated_at, user_id from all grades.

[Assistant] SELECT published_at, updated_at, user_id FROM education.grades;

[User] Get all grades created yesterday.

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

[User] Show only 20 records.

[Assistant] SELECT published_at, updated_at, user_id FROM education.grades WHERE published_at = CURRENT_DATE - INTERVAL '1 day' LIMIT 20;


[User] What are the id, api_key, token of each student?

[Assistant] SELECT id, api_key, token FROM education.students;

[User] Get students that match state LIKE 'A%'.

[Assistant] SELECT id, api_key, token FROM education.students WHERE state LIKE 'A%';

[User] Get count of token by api_key from students.

[Assistant] SELECT api_key, COUNT(token) AS count_token FROM education.students GROUP BY api_key;


[User] Get all students.

[Assistant] SELECT * FROM education.students;

[User] Sort the results by updated_at ascending.

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

[User] Calculate count of bio for each last_active in students.

[Assistant] SELECT last_active, COUNT(bio) AS count_bio FROM education.students GROUP BY last_active;


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 (
  id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  published_at timestamp without time zone,
  text varchar,
  views varchar NOT NULL,
  body character varying(256) NOT NULL,
  title char
)

CREATE TABLE socialmedia.events (
  payment_id character varying(64) NOT NULL -- unique identifier,
  processed_at timestamp,
  exchange_rate varchar,
  user_id char,
  card_type varchar NOT NULL,
  currency character varying(256),
  group_id text NOT NULL -- reference to groups.order_id,
  message_id text NOT NULL -- reference to messages.id,
  FOREIGN KEY (group_id) REFERENCES groups(order_id),
  FOREIGN KEY (message_id) REFERENCES messages(id)
)

CREATE TABLE socialmedia.groups (
  order_id text PRIMARY KEY -- unique identifier,
  cancelled_at timestamp without time zone,
  traded_at date,
  seller_id character varying(256) -- identifier for seller,
  quantity character varying(256),
  total smallint,
  user_id character varying(256) -- identifier for user,
  payment_method character varying(64),
  delivery_status varchar NOT NULL,
  card_type char
)

[User] Show me all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] List exchange_rate, currency, card_type, payment_method for each event along with their group information.

[Assistant] SELECT *, groups.card_type, groups.payment_method FROM socialmedia.events JOIN socialmedia.groups ON events.group_id = groups.order_id;

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

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


[User] Display all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Get message_id, card_type, total, delivery_status by joining events with groups.

[Assistant] SELECT *, groups.total, groups.delivery_status FROM socialmedia.events JOIN socialmedia.groups ON events.group_id = groups.order_id;

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

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


[User] List all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Sort the results by message_id ascending.

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

[User] Tally up events by user_id.

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


[User] Show me exchange_rate, user_id, payment_id for all events.

[Assistant] SELECT exchange_rate, user_id, payment_id FROM socialmedia.events;

[User] What processed_at, group_id, payment_method, cancelled_at do we have for events and their associated groups?

[Assistant] SELECT exchange_rate, user_id, payment_id, groups.payment_method, groups.cancelled_at FROM socialmedia.events JOIN socialmedia.groups ON events.group_id = groups.order_id;

[User] Calculate max of currency for each card_type in events.

[Assistant] SELECT card_type, MAX(currency) AS max_currency FROM socialmedia.events GROUP BY card_type;


[User] Retrieve card_type, exchange_rate, payment_id for every event.

[Assistant] SELECT card_type, exchange_rate, payment_id FROM socialmedia.events;

[User] Show me exchange_rate, user_id, quantity, cancelled_at from events and their related groups.

[Assistant] SELECT card_type, exchange_rate, payment_id, groups.quantity, groups.cancelled_at FROM socialmedia.events JOIN socialmedia.groups ON events.group_id = groups.order_id;

[User] Show me min of message_id grouped by user_id for events.

[Assistant] SELECT user_id, MIN(message_id) AS min_message_id FROM socialmedia.events GROUP BY user_id;


[User] Get all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Sort the results by group_id descending.

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

[User] What is the sum processed_at for each exchange_rate in events?

[Assistant] SELECT exchange_rate, SUM(processed_at) AS sum_processed_at FROM socialmedia.events GROUP BY exchange_rate;


[User] Show me all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Show me events that were from 2023.

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

[User] Only show the top 50 results.

[Assistant] SELECT * FROM socialmedia.events WHERE processed_at BETWEEN '2023-01-01' AND '2023-12-31' LIMIT 50;


[User] Get currency, user_id, card_type from all events.

[Assistant] SELECT currency, user_id, card_type FROM socialmedia.events;

[User] List events with dates from last week.

[Assistant] SELECT currency, user_id, card_type FROM socialmedia.events WHERE processed_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Tally up events by exchange_rate.

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


[User] List exchange_rate, card_type, currency from events.

[Assistant] SELECT exchange_rate, card_type, currency FROM socialmedia.events;

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

[Assistant] SELECT exchange_rate, card_type, currency FROM socialmedia.events WHERE processed_at > '2023-12-01';

[User] Can you order these by currency ascending?

[Assistant] SELECT exchange_rate, card_type, currency FROM socialmedia.events WHERE processed_at > '2023-12-01' ORDER BY currency ASC;


[User] List card_type, user_id, processed_at from events.

[Assistant] SELECT card_type, user_id, processed_at FROM socialmedia.events;

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

[Assistant] SELECT card_type, user_id, processed_at FROM socialmedia.events WHERE currency LIKE 'A%';

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.grades (
  id integer PRIMARY KEY -- unique identifier,
  completed_at timestamp without time zone,
  payment_status char NOT NULL,
  discount numeric NOT NULL,
  quantity character varying(256) NOT NULL,
  assignment_id integer NOT NULL -- reference to assignments.id,
  FOREIGN KEY (assignment_id) REFERENCES assignments(id)
)

CREATE TABLE education.teachers (
  store_id text PRIMARY KEY -- unique identifier,
  updated_at date,
  description text,
  state character varying(128),
  street character varying(256),
  country character varying(128) NOT NULL,
  location_lat varchar,
  operating_hours varchar
)

CREATE TABLE education.assignments (
  id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  attachment_url varchar NOT NULL,
  tags text,
  user_id character varying(128) -- identifier for user,
  likes text NOT NULL,
  views text,
  grade_id integer -- reference to grades.id,
  FOREIGN KEY (grade_id) REFERENCES grades(id)
)

[User] Retrieve all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Get grade_id, attachment_url, assignment_id, discount by joining assignments with grades.

[Assistant] SELECT *, grades.assignment_id, grades.discount FROM education.assignments JOIN education.grades ON assignments.grade_id = grades.id;

[User] Limit the results to 15 rows.

[Assistant] SELECT *, grades.assignment_id, grades.discount FROM education.assignments JOIN education.grades ON assignments.grade_id = grades.id LIMIT 15;


[User] What are the quantity, completed_at, discount of each grade?

[Assistant] SELECT quantity, completed_at, discount FROM education.grades;

[User] Get assignment_id, quantity, views, likes by joining grades with assignments.

[Assistant] SELECT quantity, completed_at, discount, assignments.views, assignments.likes FROM education.grades JOIN education.assignments ON grades.assignment_id = assignments.id;

[User] What is the count payment_status for each completed_at in grades?

[Assistant] SELECT completed_at, COUNT(payment_status) AS count_payment_status FROM education.grades GROUP BY completed_at;


[User] Retrieve all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Get all assignments from 2023.

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

[User] How many assignments are there per user_id?

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


[User] Retrieve grade_id, created_at, likes for every assignment.

[Assistant] SELECT grade_id, created_at, likes FROM education.assignments;

[User] Retrieve likes, views, assignment_id, payment_status showing the relationship between assignments and grades.

[Assistant] SELECT grade_id, created_at, likes, grades.assignment_id, grades.payment_status FROM education.assignments JOIN education.grades ON assignments.grade_id = grades.id;

[User] Restrict the output to 5 items.

[Assistant] SELECT grade_id, created_at, likes, grades.assignment_id, grades.payment_status FROM education.assignments JOIN education.grades ON assignments.grade_id = grades.id LIMIT 5;


[User] Show me completed_at, payment_status, quantity for all grades.

[Assistant] SELECT completed_at, payment_status, quantity FROM education.grades;

[User] Show me grades that were from 2023.

[Assistant] SELECT completed_at, payment_status, quantity FROM education.grades WHERE completed_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Order the output by payment_status ascending.

[Assistant] SELECT completed_at, payment_status, quantity FROM education.grades WHERE completed_at BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY payment_status ASC;


[User] Get all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] Get tags, grade_id, assignment_id, completed_at by joining assignments with grades.

[Assistant] SELECT *, grades.assignment_id, grades.completed_at FROM education.assignments JOIN education.grades ON assignments.grade_id = grades.id;

[User] Get average of created_at by likes from assignments.

[Assistant] SELECT likes, AVERAGE(created_at) AS average_created_at FROM education.assignments GROUP BY likes;


[User] Retrieve all grades.

[Assistant] SELECT * FROM education.grades;

[User] List grades with dates from last week.

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

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

[Assistant] SELECT * FROM education.grades WHERE completed_at >= CURRENT_DATE - INTERVAL '7 days' ORDER BY assignment_id DESC;


[User] List attachment_url, tags, likes from assignments.

[Assistant] SELECT attachment_url, tags, likes FROM education.assignments;

[User] Get grade_id, views, payment_status, completed_at by joining assignments with grades.

[Assistant] SELECT attachment_url, tags, likes, grades.payment_status, grades.completed_at FROM education.assignments JOIN education.grades ON assignments.grade_id = grades.id;

[User] Return just 15 rows.

[Assistant] SELECT attachment_url, tags, likes, grades.payment_status, grades.completed_at FROM education.assignments JOIN education.grades ON assignments.grade_id = grades.id LIMIT 15;


[User] List grade_id, views, created_at from assignments.

[Assistant] SELECT grade_id, views, created_at FROM education.assignments;

[User] Show me assignments that were created yesterday.

[Assistant] SELECT grade_id, views, created_at FROM education.assignments WHERE created_at = CURRENT_DATE - INTERVAL '1 day';

[User] Order the output by grade_id descending.

[Assistant] SELECT grade_id, views, created_at FROM education.assignments WHERE created_at = CURRENT_DATE - INTERVAL '1 day' ORDER BY grade_id DESC;


[User] Show me attachment_url, likes, grade_id for all assignments.

[Assistant] SELECT attachment_url, likes, grade_id FROM education.assignments;

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

[Assistant] SELECT attachment_url, likes, grade_id FROM education.assignments WHERE created_at > '2023-01-01';

[User] Group assignments by created_at and show the average of grade_id.

[Assistant] SELECT created_at, AVERAGE(grade_id) AS average_grade_id FROM education.assignments 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 socialmedia.users (
  customer_id text PRIMARY KEY -- unique identifier,
  joined_at timestamp,
  last_name char NOT NULL,
  status varchar,
  timezone varchar,
  group_id integer -- reference to groups.employee_id,
  FOREIGN KEY (group_id) REFERENCES groups(employee_id)
)

CREATE TABLE socialmedia.groups (
  employee_id integer PRIMARY KEY -- unique identifier,
  last_active timestamp,
  address character varying(64) NOT NULL,
  nationality character varying(128),
  timezone character varying(64),
  country character varying(128),
  user_id text NOT NULL -- reference to users.customer_id,
  FOREIGN KEY (user_id) REFERENCES users(customer_id)
)

[User] Show me last_name, timezone, group_id for all users.

[Assistant] SELECT last_name, timezone, group_id FROM socialmedia.users;

[User] Find users between January and March.

[Assistant] SELECT last_name, timezone, group_id FROM socialmedia.users WHERE joined_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] Group users by status and show the min of joined_at.

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


[User] Retrieve all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Show the results sorted by status ascending.

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

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

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


[User] Show me all users.

[Assistant] SELECT * FROM socialmedia.users;

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

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

[User] Return just 10 rows.

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


[User] Show me nationality, country, user_id for all groups.

[Assistant] SELECT nationality, country, user_id FROM socialmedia.groups;

[User] Order the output by address descending.

[Assistant] SELECT nationality, country, user_id FROM socialmedia.groups ORDER BY address DESC;

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

[Assistant] SELECT nationality, country, user_id FROM socialmedia.groups ORDER BY last_active ASC;


[User] Show me all users.

[Assistant] SELECT * FROM socialmedia.users;

[User] Can you order these by group_id ascending?

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

[User] How many users are there per group_id?

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


[User] Show me all groups.

[Assistant] SELECT * FROM socialmedia.groups;

[User] Show me user_id, address, joined_at, last_name from groups and their related users.

[Assistant] SELECT *, users.joined_at, users.last_name FROM socialmedia.groups JOIN socialmedia.users ON groups.user_id = users.customer_id;

[User] Only show the top 25 results.

[Assistant] SELECT *, users.joined_at, users.last_name FROM socialmedia.groups JOIN socialmedia.users ON groups.user_id = users.customer_id LIMIT 25;


[User] Get user_id, country, address from all groups.

[Assistant] SELECT user_id, country, address FROM socialmedia.groups;

[User] Get nationality, address, joined_at, last_name by joining groups with users.

[Assistant] SELECT user_id, country, address, users.joined_at, users.last_name FROM socialmedia.groups JOIN socialmedia.users ON groups.user_id = users.customer_id;

[User] Show me the count of groups grouped by address.

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


[User] List nationality, timezone, last_active from groups.

[Assistant] SELECT nationality, timezone, last_active FROM socialmedia.groups;

[User] What timezone, address, joined_at, group_id do we have for groups and their associated users?

[Assistant] SELECT nationality, timezone, last_active, users.joined_at, users.group_id FROM socialmedia.groups JOIN socialmedia.users ON groups.user_id = users.customer_id;

[User] Show me max of last_active grouped by timezone for groups.

[Assistant] SELECT timezone, MAX(last_active) AS max_last_active FROM socialmedia.groups GROUP BY timezone;


[User] Get status, group_id, timezone from all users.

[Assistant] SELECT status, group_id, timezone FROM socialmedia.users;

[User] Show me group_id, joined_at, user_id, timezone from users and their related groups.

[Assistant] SELECT status, group_id, timezone, groups.user_id, groups.timezone FROM socialmedia.users JOIN socialmedia.groups ON users.group_id = groups.employee_id;

[User] Show only 5 records.

[Assistant] SELECT status, group_id, timezone, groups.user_id, groups.timezone FROM socialmedia.users JOIN socialmedia.groups ON users.group_id = groups.employee_id LIMIT 5;


[User] What are the last_name, joined_at, group_id of each user?

[Assistant] SELECT last_name, joined_at, group_id FROM socialmedia.users;

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

[Assistant] SELECT last_name, joined_at, group_id FROM socialmedia.users WHERE joined_at > '2023-01-01';

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.courses (
  location_id varchar PRIMARY KEY -- unique identifier,
  last_inspected date,
  created_at timestamp without time zone,
  capacity varchar,
  geo_point text,
  type character varying(128),
  accessibility char,
  department_id text -- reference to departments.id,
  FOREIGN KEY (department_id) REFERENCES departments(id)
)

CREATE TABLE education.departments (
  id varchar PRIMARY KEY -- unique identifier,
  created_at timestamp,
  keywords text NOT NULL,
  attachment_url character varying(64) NOT NULL,
  media_url character varying(64),
  visibility character varying(128)
)

[User] Retrieve all courses.

[Assistant] SELECT * FROM education.courses;

[User] Get all courses from 2023.

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

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

[Assistant] SELECT * FROM education.courses WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY capacity ASC;


[User] Get all courses.

[Assistant] SELECT * FROM education.courses;

[User] List type, capacity, attachment_url, created_at for each course along with their department information.

[Assistant] SELECT *, departments.attachment_url, departments.created_at FROM education.courses JOIN education.departments ON courses.department_id = departments.id;

[User] Sort the results by last_inspected ascending.

[Assistant] SELECT *, departments.attachment_url, departments.created_at FROM education.courses JOIN education.departments ON courses.department_id = departments.id ORDER BY last_inspected ASC;


[User] List all courses.

[Assistant] SELECT * FROM education.courses;

[User] Show me department_id, capacity, created_at, attachment_url from courses and their related departments.

[Assistant] SELECT *, departments.created_at, departments.attachment_url FROM education.courses JOIN education.departments ON courses.department_id = departments.id;

[User] Only show the top 20 results.

[Assistant] SELECT *, departments.created_at, departments.attachment_url FROM education.courses JOIN education.departments ON courses.department_id = departments.id LIMIT 20;


[User] Get last_inspected, accessibility, geo_point from all courses.

[Assistant] SELECT last_inspected, accessibility, geo_point FROM education.courses;

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

[Assistant] SELECT last_inspected, accessibility, geo_point FROM education.courses WHERE last_inspected >= CURRENT_DATE - INTERVAL '30 days';

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

[Assistant] SELECT last_inspected, accessibility, geo_point FROM education.courses WHERE last_inspected >= CURRENT_DATE - INTERVAL '30 days' ORDER BY capacity DESC;


[User] Get all courses.

[Assistant] SELECT * FROM education.courses;

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

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

[User] Calculate sum of last_inspected for each accessibility in courses.

[Assistant] SELECT accessibility, SUM(last_inspected) AS sum_last_inspected FROM education.courses GROUP BY accessibility;


[User] Show me all courses.

[Assistant] SELECT * FROM education.courses;

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

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

[User] Restrict the output to 5 items.

[Assistant] SELECT * FROM education.courses WHERE created_at > '2023-12-01' LIMIT 5;


[User] Retrieve all courses.

[Assistant] SELECT * FROM education.courses;

[User] Can you order these by capacity descending?

[Assistant] SELECT * FROM education.courses ORDER BY capacity DESC;

[User] Sort the results by capacity descending.

[Assistant] SELECT * FROM education.courses ORDER BY capacity DESC;


[User] Show me geo_point, created_at, type for all courses.

[Assistant] SELECT geo_point, created_at, type FROM education.courses;

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

[Assistant] SELECT geo_point, created_at, type FROM education.courses WHERE type LIKE 'A%';

[User] Order the output by last_inspected descending.

[Assistant] SELECT geo_point, created_at, type FROM education.courses WHERE type LIKE 'A%' ORDER BY last_inspected DESC;


[User] List all courses.

[Assistant] SELECT * FROM education.courses;

[User] Retrieve geo_point, last_inspected, keywords, attachment_url showing the relationship between courses and departments.

[Assistant] SELECT *, departments.keywords, departments.attachment_url FROM education.courses JOIN education.departments ON courses.department_id = departments.id;

[User] Show the results sorted by type descending.

[Assistant] SELECT *, departments.keywords, departments.attachment_url FROM education.courses JOIN education.departments ON courses.department_id = departments.id ORDER BY type DESC;


[User] List all courses.

[Assistant] SELECT * FROM education.courses;

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

[Assistant] SELECT * FROM education.courses ORDER BY capacity DESC;

[User] Show the results sorted by accessibility descending.

[Assistant] SELECT * FROM education.courses ORDER BY accessibility 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 restaurant.venues (
  address_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  location_lon character varying(64) NOT NULL,
  latitude character varying(64),
  longitude varchar,
  customer_id text NOT NULL -- reference to customers.user_id,
  FOREIGN KEY (customer_id) REFERENCES customers(user_id)
)

CREATE TABLE restaurant.reservations (
  invoice_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  updated_at date,
  approval_status character varying(64) NOT NULL,
  quantity character varying(64),
  venue_id integer -- reference to venues.address_id,
  FOREIGN KEY (venue_id) REFERENCES venues(address_id)
)

CREATE TABLE restaurant.customers (
  user_id text PRIMARY KEY -- unique identifier,
  last_active timestamp,
  nationality char NOT NULL,
  last_login date NOT NULL,
  api_key text,
  zip_code character varying(256) NOT NULL,
  timezone character varying(256) NOT NULL,
  username character varying(64) NOT NULL
)

[User] Get all reservations.

[Assistant] SELECT * FROM restaurant.reservations;

[User] Show the results sorted by venue_id ascending.

[Assistant] SELECT * FROM restaurant.reservations ORDER BY venue_id ASC;

[User] Count the number of reservations in each approval_status category.

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


[User] Get all reservations.

[Assistant] SELECT * FROM restaurant.reservations;

[User] Show me approval_status, quantity, updated_at, latitude from reservations and their related venues.

[Assistant] SELECT *, venues.updated_at, venues.latitude FROM restaurant.reservations JOIN restaurant.venues ON reservations.venue_id = venues.address_id;

[User] Group reservations by updated_at and show the max of venue_id.

[Assistant] SELECT updated_at, MAX(venue_id) AS max_venue_id FROM restaurant.reservations GROUP BY updated_at;


[User] Get all reservations.

[Assistant] SELECT * FROM restaurant.reservations;

[User] Order the output by approval_status descending.

[Assistant] SELECT * FROM restaurant.reservations ORDER BY approval_status DESC;

[User] Tally up reservations by approval_status.

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


[User] Show me all venues.

[Assistant] SELECT * FROM restaurant.venues;

[User] What updated_at, customer_id, nationality, last_active do we have for venues and their associated customers?

[Assistant] SELECT *, customers.nationality, customers.last_active FROM restaurant.venues JOIN restaurant.customers ON venues.customer_id = customers.user_id;

[User] Only show the top 5 results.

[Assistant] SELECT *, customers.nationality, customers.last_active FROM restaurant.venues JOIN restaurant.customers ON venues.customer_id = customers.user_id LIMIT 5;


[User] List all venues.

[Assistant] SELECT * FROM restaurant.venues;

[User] Retrieve customer_id, updated_at, timezone, api_key showing the relationship between venues and customers.

[Assistant] SELECT *, customers.timezone, customers.api_key FROM restaurant.venues JOIN restaurant.customers ON venues.customer_id = customers.user_id;

[User] Limit the results to 20 rows.

[Assistant] SELECT *, customers.timezone, customers.api_key FROM restaurant.venues JOIN restaurant.customers ON venues.customer_id = customers.user_id LIMIT 20;


[User] Retrieve approval_status, updated_at, venue_id for every reservation.

[Assistant] SELECT approval_status, updated_at, venue_id FROM restaurant.reservations;

[User] Find reservations where quantity LIKE 'A%'.

[Assistant] SELECT approval_status, updated_at, venue_id FROM restaurant.reservations WHERE quantity LIKE 'A%';

[User] How many reservations are there per updated_at?

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


[User] What are the customer_id, longitude, latitude of each venue?

[Assistant] SELECT customer_id, longitude, latitude FROM restaurant.venues;

[User] Show the results sorted by latitude ascending.

[Assistant] SELECT customer_id, longitude, latitude FROM restaurant.venues ORDER BY latitude ASC;

[User] Tally up venues by latitude.

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


[User] List location_lon, latitude, customer_id from venues.

[Assistant] SELECT location_lon, latitude, customer_id FROM restaurant.venues;

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

[Assistant] SELECT location_lon, latitude, customer_id FROM restaurant.venues WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Limit the results to 50 rows.

[Assistant] SELECT location_lon, latitude, customer_id FROM restaurant.venues WHERE updated_at <= CURRENT_DATE - INTERVAL '6 months' LIMIT 50;


[User] List customer_id, latitude, location_lon from venues.

[Assistant] SELECT customer_id, latitude, location_lon FROM restaurant.venues;

[User] Get venues that match longitude LIKE 'A%'.

[Assistant] SELECT customer_id, latitude, location_lon FROM restaurant.venues WHERE longitude LIKE 'A%';

[User] Sort the results by latitude ascending.

[Assistant] SELECT customer_id, latitude, location_lon FROM restaurant.venues WHERE longitude LIKE 'A%' ORDER BY latitude ASC;


[User] Display all reservations.

[Assistant] SELECT * FROM restaurant.reservations;

[User] List venue_id, created_at, longitude, updated_at for each reservation along with their venue information.

[Assistant] SELECT *, venues.longitude, venues.updated_at FROM restaurant.reservations JOIN restaurant.venues ON reservations.venue_id = venues.address_id;

[User] Show me the count of reservations grouped by approval_status.

[Assistant] SELECT approval_status, COUNT(*) AS count FROM restaurant.reservations GROUP BY approval_status 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 realestate.patients (
  user_id character varying(64) NOT NULL -- unique identifier,
  joined_at timestamp,
  updated_at timestamp without time zone,
  birth_date timestamp NOT NULL,
  membership_level varchar,
  zip_code character varying(256),
  last_login timestamp without time zone NOT NULL
)

CREATE TABLE realestate.purchases (
  payment_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  discount bigint NOT NULL,
  payment_status varchar,
  status character varying(256) NOT NULL
)

CREATE TABLE realestate.addresses (
  venue_id character varying(64) NOT NULL -- unique identifier,
  created_at date,
  postal_code character varying(256),
  accessibility character varying(256) NOT NULL,
  country varchar,
  category char NOT NULL,
  zip_code varchar NOT NULL,
  purchase_id integer -- reference to purchases.payment_id,
  FOREIGN KEY (purchase_id) REFERENCES purchases(payment_id)
)

[User] What are the postal_code, purchase_id, zip_code of each addresse?

[Assistant] SELECT postal_code, purchase_id, zip_code FROM realestate.addresses;

[User] Show the results sorted by accessibility descending.

[Assistant] SELECT postal_code, purchase_id, zip_code FROM realestate.addresses ORDER BY accessibility DESC;

[User] Order the output by country ascending.

[Assistant] SELECT postal_code, purchase_id, zip_code FROM realestate.addresses ORDER BY country ASC;


[User] List all addresses.

[Assistant] SELECT * FROM realestate.addresses;

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

[Assistant] SELECT * FROM realestate.addresses WHERE created_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Tally up addresses by country.

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


[User] List all addresses.

[Assistant] SELECT * FROM realestate.addresses;

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

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

[User] Order the output by accessibility ascending.

[Assistant] SELECT * FROM realestate.addresses WHERE created_at > '2023-12-01' ORDER BY accessibility ASC;


[User] List all addresses.

[Assistant] SELECT * FROM realestate.addresses;

[User] Get addresses that match accessibility LIKE 'A%'.

[Assistant] SELECT * FROM realestate.addresses WHERE accessibility LIKE 'A%';

[User] Show me max of postal_code grouped by category for addresses.

[Assistant] SELECT category, MAX(postal_code) AS max_postal_code FROM realestate.addresses GROUP BY category;


[User] List all addresses.

[Assistant] SELECT * FROM realestate.addresses;

[User] Get purchase_id, postal_code, status, payment_status by joining addresses with purchases.

[Assistant] SELECT *, purchases.status, purchases.payment_status FROM realestate.addresses JOIN realestate.purchases ON addresses.purchase_id = purchases.payment_id;

[User] Return just 50 rows.

[Assistant] SELECT *, purchases.status, purchases.payment_status FROM realestate.addresses JOIN realestate.purchases ON addresses.purchase_id = purchases.payment_id LIMIT 50;


[User] What are the accessibility, purchase_id, postal_code of each addresse?

[Assistant] SELECT accessibility, purchase_id, postal_code FROM realestate.addresses;

[User] Sort the results by zip_code descending.

[Assistant] SELECT accessibility, purchase_id, postal_code FROM realestate.addresses ORDER BY zip_code DESC;

[User] Order the output by venue_id descending.

[Assistant] SELECT accessibility, purchase_id, postal_code FROM realestate.addresses ORDER BY venue_id DESC;


[User] List all addresses.

[Assistant] SELECT * FROM realestate.addresses;

[User] What zip_code, venue_id, payment_status, status do we have for addresses and their associated purchases?

[Assistant] SELECT *, purchases.payment_status, purchases.status FROM realestate.addresses JOIN realestate.purchases ON addresses.purchase_id = purchases.payment_id;

[User] Sort the results by country ascending.

[Assistant] SELECT *, purchases.payment_status, purchases.status FROM realestate.addresses JOIN realestate.purchases ON addresses.purchase_id = purchases.payment_id ORDER BY country ASC;


[User] Show me all addresses.

[Assistant] SELECT * FROM realestate.addresses;

[User] Show me addresses with postal_code LIKE 'A%'.

[Assistant] SELECT * FROM realestate.addresses WHERE postal_code LIKE 'A%';

[User] Get max of venue_id by created_at from addresses.

[Assistant] SELECT created_at, MAX(venue_id) AS max_venue_id FROM realestate.addresses GROUP BY created_at;


[User] Show me all addresses.

[Assistant] SELECT * FROM realestate.addresses;

[User] Show me addresses with venue_id LIKE 'A%'.

[Assistant] SELECT * FROM realestate.addresses WHERE venue_id LIKE 'A%';

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

[Assistant] SELECT zip_code, MIN(zip_code) AS min_zip_code FROM realestate.addresses GROUP BY zip_code;


[User] Display all addresses.

[Assistant] SELECT * FROM realestate.addresses;

[User] List purchase_id, postal_code, updated_at, payment_status for each addresse along with their purchase information.

[Assistant] SELECT *, purchases.updated_at, purchases.payment_status FROM realestate.addresses JOIN realestate.purchases ON addresses.purchase_id = purchases.payment_id;

[User] Show only 10 records.

[Assistant] SELECT *, purchases.updated_at, purchases.payment_status FROM realestate.addresses JOIN realestate.purchases ON addresses.purchase_id = purchases.payment_id LIMIT 10;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.patients (
  person_id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  last_active timestamp,
  address text,
  api_key character varying(128),
  appointment_id text -- reference to appointments.payment_id,
  FOREIGN KEY (appointment_id) REFERENCES appointments(payment_id)
)

CREATE TABLE healthcare.departments (
  comment_id integer PRIMARY KEY -- unique identifier,
  published_at date,
  shares text,
  format char,
  title character varying(256),
  subject char,
  patient_id integer -- reference to patients.person_id,
  FOREIGN KEY (patient_id) REFERENCES patients(person_id)
)

CREATE TABLE healthcare.appointments (
  payment_id varchar PRIMARY KEY -- unique identifier,
  processed_at date,
  created_at timestamp without time zone,
  user_id varchar,
  customer_id char,
  reconciliation_status character varying(64)
)

[User] Get published_at, title, shares from all departments.

[Assistant] SELECT published_at, title, shares FROM healthcare.departments;

[User] Order the output by format descending.

[Assistant] SELECT published_at, title, shares FROM healthcare.departments ORDER BY format DESC;

[User] Order the output by title descending.

[Assistant] SELECT published_at, title, shares FROM healthcare.departments ORDER BY title DESC;


[User] Show me all departments.

[Assistant] SELECT * FROM healthcare.departments;

[User] Find departments where patient_id > 17.

[Assistant] SELECT * FROM healthcare.departments WHERE patient_id > 17;

[User] Show me max of shares grouped by subject for departments.

[Assistant] SELECT subject, MAX(shares) AS max_shares FROM healthcare.departments GROUP BY subject;


[User] What are the updated_at, address, last_active of each patient?

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

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

[Assistant] SELECT updated_at, address, last_active FROM healthcare.patients WHERE last_active <= CURRENT_DATE - INTERVAL '6 months';

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

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


[User] Show me all departments.

[Assistant] SELECT * FROM healthcare.departments;

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

[Assistant] SELECT * FROM healthcare.departments WHERE shares LIKE 'A%';

[User] Restrict the output to 25 items.

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


[User] Show me all departments.

[Assistant] SELECT * FROM healthcare.departments;

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

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

[User] Show me average of title grouped by shares for departments.

[Assistant] SELECT shares, AVERAGE(title) AS average_title FROM healthcare.departments GROUP BY shares;


[User] Retrieve all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] List patients with dates created yesterday.

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

[User] Sort the results by appointment_id ascending.

[Assistant] SELECT * FROM healthcare.patients WHERE last_active = CURRENT_DATE - INTERVAL '1 day' ORDER BY appointment_id ASC;


[User] Show me updated_at, last_active, api_key for all patients.

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

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

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

[User] Can you order these by address descending?

[Assistant] SELECT updated_at, last_active, api_key FROM healthcare.patients WHERE updated_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY address DESC;


[User] What are the api_key, updated_at, last_active of each patient?

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

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

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

[User] What is the max updated_at for each api_key in patients?

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


[User] Retrieve all patients.

[Assistant] SELECT * FROM healthcare.patients;

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

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

[User] What is the sum api_key for each api_key in patients?

[Assistant] SELECT api_key, SUM(api_key) AS sum_api_key FROM healthcare.patients GROUP BY api_key;


[User] Show me subject, shares, title for all departments.

[Assistant] SELECT subject, shares, title FROM healthcare.departments;

[User] Retrieve format, shares, api_key, last_active showing the relationship between departments and patients.

[Assistant] SELECT subject, shares, title, patients.api_key, patients.last_active FROM healthcare.departments JOIN healthcare.patients ON departments.patient_id = patients.person_id;

[User] Calculate average of published_at for each subject in departments.

[Assistant] SELECT subject, AVERAGE(published_at) AS average_published_at FROM healthcare.departments GROUP BY subject;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.audits (
  id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  longitude text,
  name character varying(64),
  description varchar,
  loan_id text NOT NULL -- reference to loans.invoice_id,
  transaction_id integer -- reference to transactions.invoice_id,
  FOREIGN KEY (loan_id) REFERENCES loans(invoice_id),
  FOREIGN KEY (transaction_id) REFERENCES transactions(invoice_id)
)

CREATE TABLE finance.transactions (
  invoice_id integer PRIMARY KEY -- unique identifier,
  traded_at timestamp without time zone,
  delivery_status text,
  exchange_rate varchar NOT NULL,
  customer_id varchar -- identifier for customer,
  product_id text -- identifier for product,
  discount smallint
)

CREATE TABLE finance.customers (
  person_id integer PRIMARY KEY -- unique identifier,
  created_at timestamp,
  state character varying(256),
  last_login date,
  avatar text
)

CREATE TABLE finance.loans (
  invoice_id text PRIMARY KEY -- unique identifier,
  processed_at timestamp without time zone,
  traded_at timestamp,
  status varchar,
  account_id char NOT NULL -- identifier for account,
  exchange_rate text,
  card_type character varying(128) NOT NULL,
  discount numeric(38,14),
  seller_id character varying(128)
)

[User] Display all audits.

[Assistant] SELECT * FROM finance.audits;

[User] What loan_id, updated_at, discount, exchange_rate do we have for audits and their associated loans?

[Assistant] SELECT *, loans.discount, loans.exchange_rate FROM finance.audits JOIN finance.loans ON audits.loan_id = loans.invoice_id;

[User] Only show the top 15 results.

[Assistant] SELECT *, loans.discount, loans.exchange_rate FROM finance.audits JOIN finance.loans ON audits.loan_id = loans.invoice_id LIMIT 15;


[User] List loan_id, updated_at, name from audits.

[Assistant] SELECT loan_id, updated_at, name FROM finance.audits;

[User] Show me name, transaction_id, traded_at, status from audits and their related loans.

[Assistant] SELECT loan_id, updated_at, name, loans.traded_at, loans.status FROM finance.audits JOIN finance.loans ON audits.loan_id = loans.invoice_id;

[User] Tally up audits by transaction_id.

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


[User] Display all audits.

[Assistant] SELECT * FROM finance.audits;

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

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

[User] Sort the results by updated_at descending.

[Assistant] SELECT * FROM finance.audits WHERE updated_at > '2023-01-01' ORDER BY updated_at DESC;


[User] Retrieve all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Show the results sorted by updated_at ascending.

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

[User] How many audits are there per longitude?

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


[User] Get all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Retrieve loan_id, transaction_id, seller_id, exchange_rate showing the relationship between audits and loans.

[Assistant] SELECT *, loans.seller_id, loans.exchange_rate FROM finance.audits JOIN finance.loans ON audits.loan_id = loans.invoice_id;

[User] Only show the top 20 results.

[Assistant] SELECT *, loans.seller_id, loans.exchange_rate FROM finance.audits JOIN finance.loans ON audits.loan_id = loans.invoice_id LIMIT 20;


[User] What are the name, loan_id, transaction_id of each audit?

[Assistant] SELECT name, loan_id, transaction_id FROM finance.audits;

[User] List audits that have longitude LIKE 'A%'.

[Assistant] SELECT name, loan_id, transaction_id FROM finance.audits WHERE longitude LIKE 'A%';

[User] What is the min description for each name in audits?

[Assistant] SELECT name, MIN(description) AS min_description FROM finance.audits GROUP BY name;


[User] Show me all audits.

[Assistant] SELECT * FROM finance.audits;

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

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

[User] Order the output by transaction_id descending.

[Assistant] SELECT * FROM finance.audits WHERE updated_at BETWEEN '2023-01-01' AND '2023-03-31' ORDER BY transaction_id DESC;


[User] Get all audits.

[Assistant] SELECT * FROM finance.audits;

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

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

[User] Tally up audits by updated_at.

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


[User] What are the transaction_id, description, updated_at of each audit?

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

[User] Show the results sorted by loan_id ascending.

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

[User] Sort the results by name descending.

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


[User] Display all audits.

[Assistant] SELECT * FROM finance.audits;

[User] Sort the results by name descending.

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

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

[Assistant] SELECT loan_id, SUM(description) AS sum_description FROM finance.audits GROUP BY loan_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.orders (
  payment_id text PRIMARY KEY -- unique identifier,
  created_at timestamp without time zone,
  subtotal integer,
  account_id varchar -- identifier for account,
  seller_id character varying(64) NOT NULL,
  approval_status text,
  review_id text NOT NULL -- reference to reviews.message_id,
  FOREIGN KEY (review_id) REFERENCES reviews(message_id)
)

CREATE TABLE e-commerce.inventory (
  id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp without time zone,
  expires_at date,
  popularity_score character varying(64),
  available character varying(128) NOT NULL,
  subcategory character varying(64) NOT NULL
)

CREATE TABLE e-commerce.reviews (
  message_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  parent_id char -- identifier for parent,
  user_id character varying(128) NOT NULL,
  shares character varying(128) NOT NULL,
  format char NOT NULL
)

[User] What are the review_id, seller_id, subtotal of each order?

[Assistant] SELECT review_id, seller_id, subtotal FROM e-commerce.orders;

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

[Assistant] SELECT review_id, seller_id, subtotal FROM e-commerce.orders WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Sort the results by review_id ascending.

[Assistant] SELECT review_id, seller_id, subtotal FROM e-commerce.orders WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY review_id ASC;


[User] Retrieve all orders.

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

[User] What account_id, seller_id, shares, updated_at do we have for orders and their associated reviews?

[Assistant] SELECT *, reviews.shares, reviews.updated_at FROM e-commerce.orders JOIN e-commerce.reviews ON orders.review_id = reviews.message_id;

[User] Show the results sorted by approval_status descending.

[Assistant] SELECT *, reviews.shares, reviews.updated_at FROM e-commerce.orders JOIN e-commerce.reviews ON orders.review_id = reviews.message_id ORDER BY approval_status DESC;


[User] Retrieve seller_id, review_id, account_id for every order.

[Assistant] SELECT seller_id, review_id, account_id FROM e-commerce.orders;

[User] Order the output by account_id ascending.

[Assistant] SELECT seller_id, review_id, account_id FROM e-commerce.orders ORDER BY account_id ASC;

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

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


[User] What are the created_at, subtotal, approval_status of each order?

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

[User] Retrieve review_id, seller_id, parent_id, shares showing the relationship between orders and reviews.

[Assistant] SELECT created_at, subtotal, approval_status, reviews.parent_id, reviews.shares FROM e-commerce.orders JOIN e-commerce.reviews ON orders.review_id = reviews.message_id;

[User] Can you order these by subtotal ascending?

[Assistant] SELECT created_at, subtotal, approval_status, reviews.parent_id, reviews.shares FROM e-commerce.orders JOIN e-commerce.reviews ON orders.review_id = reviews.message_id ORDER BY subtotal ASC;


[User] Retrieve review_id, subtotal, seller_id for every order.

[Assistant] SELECT review_id, subtotal, seller_id FROM e-commerce.orders;

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

[Assistant] SELECT review_id, subtotal, seller_id FROM e-commerce.orders WHERE created_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Return just 25 rows.

[Assistant] SELECT review_id, subtotal, seller_id FROM e-commerce.orders WHERE created_at >= CURRENT_DATE - INTERVAL '7 days' LIMIT 25;


[User] What are the subtotal, seller_id, review_id of each order?

[Assistant] SELECT subtotal, seller_id, review_id FROM e-commerce.orders;

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

[Assistant] SELECT subtotal, seller_id, review_id FROM e-commerce.orders WHERE created_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

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

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


[User] Get subtotal, seller_id, account_id from all orders.

[Assistant] SELECT subtotal, seller_id, account_id FROM e-commerce.orders;

[User] Order the output by seller_id ascending.

[Assistant] SELECT subtotal, seller_id, account_id FROM e-commerce.orders ORDER BY seller_id ASC;

[User] Limit the results to 5 rows.

[Assistant] SELECT subtotal, seller_id, account_id FROM e-commerce.orders ORDER BY seller_id ASC LIMIT 5;


[User] Show me all orders.

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

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

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

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

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


[User] Get account_id, created_at, approval_status from all orders.

[Assistant] SELECT account_id, created_at, approval_status FROM e-commerce.orders;

[User] Show me orders with account_id LIKE 'A%'.

[Assistant] SELECT account_id, created_at, approval_status FROM e-commerce.orders WHERE account_id LIKE 'A%';

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

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


[User] Show me all orders.

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

[User] Get approval_status, subtotal, shares, format by joining orders with reviews.

[Assistant] SELECT *, reviews.shares, reviews.format FROM e-commerce.orders JOIN e-commerce.reviews ON orders.review_id = reviews.message_id;

[User] Show only 100 records.

[Assistant] SELECT *, reviews.shares, reviews.format FROM e-commerce.orders JOIN e-commerce.reviews ON orders.review_id = reviews.message_id LIMIT 100;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE socialmedia.followers (
  payment_id character varying(64) NOT NULL -- unique identifier,
  created_at timestamp without time zone,
  exchange_rate char,
  invoice_number char NOT NULL,
  balance decimal,
  status character varying(64),
  category character varying(128) NOT NULL,
  credit character varying(256)
)

CREATE TABLE socialmedia.events (
  item_id character varying(64) NOT NULL -- unique identifier,
  expires_at timestamp without time zone,
  rating character varying(64),
  title char,
  featured_rank char,
  available character varying(64),
  views text,
  tax_rate text,
  quantity text
)

[User] Retrieve invoice_number, credit, status for every follower.

[Assistant] SELECT invoice_number, credit, status FROM socialmedia.followers;

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

[Assistant] SELECT invoice_number, credit, status FROM socialmedia.followers WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Restrict the output to 100 items.

[Assistant] SELECT invoice_number, credit, status FROM socialmedia.followers WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31' LIMIT 100;


[User] List views, featured_rank, title from events.

[Assistant] SELECT views, featured_rank, title FROM socialmedia.events;

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

[Assistant] SELECT views, featured_rank, title FROM socialmedia.events WHERE expires_at > '2023-12-01';

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

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


[User] Get all followers.

[Assistant] SELECT * FROM socialmedia.followers;

[User] Can you order these by exchange_rate ascending?

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

[User] Show the results sorted by payment_id descending.

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


[User] Get all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Sort the results by tax_rate ascending.

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

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

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


[User] List credit, exchange_rate, status from followers.

[Assistant] SELECT credit, exchange_rate, status FROM socialmedia.followers;

[User] Get all followers from 2023.

[Assistant] SELECT credit, exchange_rate, status FROM socialmedia.followers WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31';

[User] Show only 25 records.

[Assistant] SELECT credit, exchange_rate, status FROM socialmedia.followers WHERE created_at BETWEEN '2023-01-01' AND '2023-12-31' LIMIT 25;


[User] Retrieve available, tax_rate, featured_rank for every event.

[Assistant] SELECT available, tax_rate, featured_rank FROM socialmedia.events;

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

[Assistant] SELECT available, tax_rate, featured_rank FROM socialmedia.events WHERE expires_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Only show the top 100 results.

[Assistant] SELECT available, tax_rate, featured_rank FROM socialmedia.events WHERE expires_at <= CURRENT_DATE - INTERVAL '6 months' LIMIT 100;


[User] List rating, views, featured_rank from events.

[Assistant] SELECT rating, views, featured_rank FROM socialmedia.events;

[User] Get all events older than 6 months.

[Assistant] SELECT rating, views, featured_rank FROM socialmedia.events WHERE expires_at <= CURRENT_DATE - INTERVAL '6 months';

[User] Restrict the output to 20 items.

[Assistant] SELECT rating, views, featured_rank FROM socialmedia.events WHERE expires_at <= CURRENT_DATE - INTERVAL '6 months' LIMIT 20;


[User] Retrieve balance, created_at, credit for every follower.

[Assistant] SELECT balance, created_at, credit FROM socialmedia.followers;

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

[Assistant] SELECT balance, created_at, credit FROM socialmedia.followers ORDER BY status ASC;

[User] What is the max exchange_rate for each credit in followers?

[Assistant] SELECT credit, MAX(exchange_rate) AS max_exchange_rate FROM socialmedia.followers GROUP BY credit;


[User] Display all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] List events that have expires_at > '2023-01-01'.

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

[User] Get count of title by tax_rate from events.

[Assistant] SELECT tax_rate, COUNT(title) AS count_title FROM socialmedia.events GROUP BY tax_rate;


[User] Show me tax_rate, quantity, views for all events.

[Assistant] SELECT tax_rate, quantity, views FROM socialmedia.events;

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

[Assistant] SELECT tax_rate, quantity, views FROM socialmedia.events WHERE item_id LIKE 'A%';

[User] Restrict the output to 15 items.

[Assistant] SELECT tax_rate, quantity, views FROM socialmedia.events WHERE item_id 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 socialmedia.comments (
  id character varying(64) NOT NULL -- unique identifier,
  edited_at timestamp,
  updated_at timestamp without time zone,
  views character varying(64),
  parent_id character varying(128),
  visibility varchar NOT NULL,
  user_id integer -- reference to users.id,
  FOREIGN KEY (user_id) REFERENCES users(id)
)

CREATE TABLE socialmedia.messages (
  message_id text PRIMARY KEY -- unique identifier,
  updated_at date,
  score text,
  user_id character varying(64),
  thumbnail varchar,
  format text,
  author_id character varying(128) -- identifier for author
)

CREATE TABLE socialmedia.events (
  person_id varchar PRIMARY KEY -- unique identifier,
  updated_at timestamp without time zone,
  joined_at timestamp without time zone,
  email character varying(64) NOT NULL,
  country text,
  message_id text -- reference to messages.message_id,
  FOREIGN KEY (message_id) REFERENCES messages(message_id)
)

CREATE TABLE socialmedia.users (
  id integer PRIMARY KEY -- unique identifier,
  updated_at timestamp,
  salt character varying(64) NOT NULL,
  last_name character varying(128),
  full_name varchar,
  event_id text NOT NULL -- reference to events.person_id,
  FOREIGN KEY (event_id) REFERENCES events(person_id)
)

CREATE TABLE socialmedia.followers (
  employee_id character varying(64) NOT NULL -- unique identifier,
  last_active date,
  gender varchar NOT NULL,
  website char,
  api_key character varying(128) NOT NULL,
  token character varying(256) NOT NULL
)

[User] List all events.

[Assistant] SELECT * FROM socialmedia.events;

[User] Show the results sorted by country descending.

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

[User] Show the results sorted by joined_at ascending.

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.doctors (
  location_id varchar PRIMARY KEY -- unique identifier,
  last_inspected timestamp,
  updated_at timestamp,
  description character varying(128),
  street character varying(256),
  location_lon character varying(64),
  capacity char,
  longitude text NOT NULL
)

CREATE TABLE healthcare.patients (
  user_id varchar PRIMARY KEY -- unique identifier,
  last_active timestamp without time zone,
  updated_at date,
  password_hash character varying(64),
  first_name varchar,
  token character varying(128),
  email character varying(64),
  zip_code varchar,
  doctor_id text -- reference to doctors.location_id,
  FOREIGN KEY (doctor_id) REFERENCES doctors(location_id)
)

CREATE TABLE healthcare.medical_records (
  account_id character varying(64) NOT NULL -- unique identifier,
  updated_at timestamp,
  due_date timestamp without time zone,
  vendor_id character varying(256) -- identifier for vendor,
  verification_status char NOT NULL,
  reference_number varchar,
  doctor_id text NOT NULL -- reference to doctors.location_id,
  patient_id text -- reference to patients.user_id,
  FOREIGN KEY (doctor_id) REFERENCES doctors(location_id),
  FOREIGN KEY (patient_id) REFERENCES patients(user_id)
)

[User] Retrieve reference_number, updated_at, account_id for every medical_record.

[Assistant] SELECT reference_number, updated_at, account_id FROM healthcare.medical_records;

[User] List medical_records that have patient_id LIKE 'A%'.

[Assistant] SELECT reference_number, updated_at, account_id FROM healthcare.medical_records WHERE patient_id LIKE 'A%';

[User] Only show the top 25 results.

[Assistant] SELECT reference_number, updated_at, account_id FROM healthcare.medical_records WHERE patient_id LIKE 'A%' LIMIT 25;


[User] List all patients.

[Assistant] SELECT * FROM healthcare.patients;

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

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

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

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


[User] Get all medical_records.

[Assistant] SELECT * FROM healthcare.medical_records;

[User] Sort the results by due_date descending.

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

[User] Only show the top 50 results.

[Assistant] SELECT * FROM healthcare.medical_records ORDER BY due_date DESC LIMIT 50;


[User] Retrieve account_id, doctor_id, reference_number for every medical_record.

[Assistant] SELECT account_id, doctor_id, reference_number FROM healthcare.medical_records;

[User] Find medical_records from last week.

[Assistant] SELECT account_id, doctor_id, reference_number FROM healthcare.medical_records WHERE due_date >= CURRENT_DATE - INTERVAL '7 days';

[User] Return just 5 rows.

[Assistant] SELECT account_id, doctor_id, reference_number FROM healthcare.medical_records WHERE due_date >= CURRENT_DATE - INTERVAL '7 days' LIMIT 5;


[User] Get all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] List zip_code, updated_at, last_inspected, location_lon for each patient along with their doctor information.

[Assistant] SELECT *, doctors.last_inspected, doctors.location_lon FROM healthcare.patients JOIN healthcare.doctors ON patients.doctor_id = doctors.location_id;

[User] Calculate sum of email for each first_name in patients.

[Assistant] SELECT first_name, SUM(email) AS sum_email FROM healthcare.patients GROUP BY first_name;


[User] Get all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] Sort the results by token descending.

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

[User] Limit the results to 100 rows.

[Assistant] SELECT * FROM healthcare.patients ORDER BY token DESC LIMIT 100;


[User] Get doctor_id, patient_id, vendor_id from all medical_records.

[Assistant] SELECT doctor_id, patient_id, vendor_id FROM healthcare.medical_records;

[User] Order the output by vendor_id descending.

[Assistant] SELECT doctor_id, patient_id, vendor_id FROM healthcare.medical_records ORDER BY vendor_id DESC;

[User] Group medical_records by vendor_id and show the average of doctor_id.

[Assistant] SELECT vendor_id, AVERAGE(doctor_id) AS average_doctor_id FROM healthcare.medical_records GROUP BY vendor_id;


[User] List updated_at, email, password_hash from patients.

[Assistant] SELECT updated_at, email, password_hash FROM healthcare.patients;

[User] Show the results sorted by password_hash ascending.

[Assistant] SELECT updated_at, email, password_hash FROM healthcare.patients ORDER BY password_hash ASC;

[User] Limit the results to 100 rows.

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


[User] List due_date, reference_number, updated_at from medical_records.

[Assistant] SELECT due_date, reference_number, updated_at FROM healthcare.medical_records;

[User] Can you order these by doctor_id ascending?

[Assistant] SELECT due_date, reference_number, updated_at FROM healthcare.medical_records ORDER BY doctor_id ASC;

[User] Sort the results by verification_status ascending.

[Assistant] SELECT due_date, reference_number, updated_at FROM healthcare.medical_records ORDER BY verification_status ASC;


[User] Display all patients.

[Assistant] SELECT * FROM healthcare.patients;

[User] Retrieve doctor_id, password_hash, street, updated_at showing the relationship between patients and doctors.

[Assistant] SELECT *, doctors.street, doctors.updated_at FROM healthcare.patients JOIN healthcare.doctors ON patients.doctor_id = doctors.location_id;

[User] Limit the results to 50 rows.

[Assistant] SELECT *, doctors.street, doctors.updated_at FROM healthcare.patients JOIN healthcare.doctors ON patients.doctor_id = doctors.location_id LIMIT 50;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE education.assignments (
  address_id integer PRIMARY KEY -- unique identifier,
  created_at date,
  updated_at timestamp,
  capacity text,
  location_lon character varying(128),
  address_line1 varchar,
  student_id text NOT NULL -- reference to students.employee_id,
  department_id integer NOT NULL -- reference to departments.product_id,
  FOREIGN KEY (student_id) REFERENCES students(employee_id),
  FOREIGN KEY (department_id) REFERENCES departments(product_id)
)

CREATE TABLE education.students (
  employee_id text PRIMARY KEY -- unique identifier,
  joined_at timestamp without time zone,
  updated_at date,
  is_active bit,
  phone character varying(128),
  nationality text NOT NULL,
  username character varying(64),
  first_name character varying(64) NOT NULL,
  department_id integer NOT NULL -- reference to departments.product_id,
  FOREIGN KEY (department_id) REFERENCES departments(product_id)
)

CREATE TABLE education.departments (
  product_id integer PRIMARY KEY -- unique identifier,
  published_at timestamp,
  quantity character varying(64),
  backorder character varying(128) NOT NULL,
  available varchar NOT NULL,
  tax_rate character varying(128),
  assignment_id integer -- reference to assignments.address_id,
  FOREIGN KEY (assignment_id) REFERENCES assignments(address_id)
)

[User] List all students.

[Assistant] SELECT * FROM education.students;

[User] Show the results sorted by username ascending.

[Assistant] SELECT * FROM education.students ORDER BY username ASC;

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

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


[User] List username, is_active, first_name from students.

[Assistant] SELECT username, is_active, first_name FROM education.students;

[User] Find students where username LIKE 'A%'.

[Assistant] SELECT username, is_active, first_name FROM education.students WHERE username LIKE 'A%';

[User] Group students by username and show the average of nationality.

[Assistant] SELECT username, AVERAGE(nationality) AS average_nationality FROM education.students GROUP BY username;


[User] Retrieve updated_at, is_active, joined_at for every student.

[Assistant] SELECT updated_at, is_active, joined_at FROM education.students;

[User] Can you order these by nationality ascending?

[Assistant] SELECT updated_at, is_active, joined_at FROM education.students ORDER BY nationality ASC;

[User] Sort the results by department_id descending.

[Assistant] SELECT updated_at, is_active, joined_at FROM education.students ORDER BY department_id DESC;


[User] List all departments.

[Assistant] SELECT * FROM education.departments;

[User] Sort the results by backorder ascending.

[Assistant] SELECT * FROM education.departments ORDER BY backorder ASC;

[User] Group departments by tax_rate and show the average of published_at.

[Assistant] SELECT tax_rate, AVERAGE(published_at) AS average_published_at FROM education.departments GROUP BY tax_rate;


[User] Show me is_active, updated_at, phone for all students.

[Assistant] SELECT is_active, updated_at, phone FROM education.students;

[User] Find students where username LIKE 'A%'.

[Assistant] SELECT is_active, updated_at, phone FROM education.students WHERE username LIKE 'A%';

[User] Calculate max of username for each updated_at in students.

[Assistant] SELECT updated_at, MAX(username) AS max_username FROM education.students GROUP BY updated_at;


[User] List tax_rate, available, quantity from departments.

[Assistant] SELECT tax_rate, available, quantity FROM education.departments;

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

[Assistant] SELECT tax_rate, available, quantity FROM education.departments ORDER BY quantity DESC;

[User] Limit the results to 5 rows.

[Assistant] SELECT tax_rate, available, quantity FROM education.departments ORDER BY quantity DESC LIMIT 5;


[User] List is_active, joined_at, username from students.

[Assistant] SELECT is_active, joined_at, username FROM education.students;

[User] Show me students with department_id > 100.

[Assistant] SELECT is_active, joined_at, username FROM education.students WHERE department_id > 100;

[User] Can you order these by first_name ascending?

[Assistant] SELECT is_active, joined_at, username FROM education.students WHERE department_id > 100 ORDER BY first_name ASC;


[User] Retrieve all assignments.

[Assistant] SELECT * FROM education.assignments;

[User] List assignments with dates from last week.

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

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

[Assistant] SELECT created_at, MAX(address_line1) AS max_address_line1 FROM education.assignments 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 banking.sales (
  order_id varchar PRIMARY KEY -- unique identifier,
  created_at date,
  traded_at timestamp,
  total numeric,
  payment_status varchar,
  delivery_status varchar NOT NULL,
  discount numeric(38,14),
  buyer_id character varying(256),
  amount decimal,
  customer_id text -- reference to customers.customer_id,
  FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
)

CREATE TABLE banking.customers (
  customer_id varchar PRIMARY KEY -- unique identifier,
  created_at date,
  updated_at date,
  birth_date timestamp NOT NULL,
  username character varying(128) NOT NULL,
  account_status varchar,
  gender character varying(64),
  salt character varying(256),
  country text NOT NULL,
  sale_id text -- reference to sales.order_id,
  FOREIGN KEY (sale_id) REFERENCES sales(order_id)
)

CREATE TABLE banking.invoices (
  transaction_id text PRIMARY KEY -- unique identifier,
  processed_at timestamp without time zone,
  payment_date date,
  approval_status character varying(256),
  credit character varying(64) NOT NULL,
  reconciliation_status varchar,
  notes varchar NOT NULL,
  status varchar,
  description character varying(256) NOT NULL
)

[User] What are the country, username, salt of each customer?

[Assistant] SELECT country, username, salt FROM banking.customers;

[User] Can you order these by gender ascending?

[Assistant] SELECT country, username, salt FROM banking.customers ORDER BY gender ASC;

[User] Tally up customers by birth_date.

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


[User] Retrieve all sales.

[Assistant] SELECT * FROM banking.sales;

[User] Show me sales with delivery_status LIKE 'A%'.

[Assistant] SELECT * FROM banking.sales WHERE delivery_status LIKE 'A%';

[User] Limit the results to 50 rows.

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


[User] List all sales.

[Assistant] SELECT * FROM banking.sales;

[User] Retrieve total, discount, gender, updated_at showing the relationship between sales and customers.

[Assistant] SELECT *, customers.gender, customers.updated_at FROM banking.sales JOIN banking.customers ON sales.customer_id = customers.customer_id;

[User] What is the count buyer_id for each discount in sales?

[Assistant] SELECT discount, COUNT(buyer_id) AS count_buyer_id FROM banking.sales GROUP BY discount;


[User] Show me all sales.

[Assistant] SELECT * FROM banking.sales;

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

[Assistant] SELECT * FROM banking.sales WHERE created_at > '2023-01-01';

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

[Assistant] SELECT * FROM banking.sales WHERE created_at > '2023-01-01' ORDER BY total ASC;


[User] Get account_status, updated_at, salt from all customers.

[Assistant] SELECT account_status, updated_at, salt FROM banking.customers;

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

[Assistant] SELECT account_status, updated_at, salt FROM banking.customers WHERE birth_date >= CURRENT_TIMESTAMP - INTERVAL '1 hour';

[User] Can you order these by sale_id descending?

[Assistant] SELECT account_status, updated_at, salt FROM banking.customers WHERE birth_date >= CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY sale_id DESC;


[User] Retrieve buyer_id, delivery_status, discount for every sale.

[Assistant] SELECT buyer_id, delivery_status, discount FROM banking.sales;

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

[Assistant] SELECT buyer_id, delivery_status, discount FROM banking.sales WHERE created_at > '2023-12-01';

[User] Return just 25 rows.

[Assistant] SELECT buyer_id, delivery_status, discount FROM banking.sales WHERE created_at > '2023-12-01' LIMIT 25;


[User] List delivery_status, amount, customer_id from sales.

[Assistant] SELECT delivery_status, amount, customer_id FROM banking.sales;

[User] Get all sales from last week.

[Assistant] SELECT delivery_status, amount, customer_id FROM banking.sales WHERE traded_at >= CURRENT_DATE - INTERVAL '7 days';

[User] Show me the count of sales grouped by payment_status.

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


[User] List sale_id, gender, birth_date from customers.

[Assistant] SELECT sale_id, gender, birth_date FROM banking.customers;

[User] Order the output by created_at ascending.

[Assistant] SELECT sale_id, gender, birth_date FROM banking.customers ORDER BY created_at ASC;

[User] Can you order these by country descending?

[Assistant] SELECT sale_id, gender, birth_date FROM banking.customers ORDER BY country DESC;


[User] Display all customers.

[Assistant] SELECT * FROM banking.customers;

[User] Retrieve created_at, username, total, delivery_status showing the relationship between customers and sales.

[Assistant] SELECT *, sales.total, sales.delivery_status FROM banking.customers JOIN banking.sales ON customers.sale_id = sales.order_id;

[User] Show me the count of customers grouped by account_status.

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


[User] Retrieve all sales.

[Assistant] SELECT * FROM banking.sales;

[User] List sales with dates from last week.

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

[User] Show me average of amount grouped by delivery_status for sales.

[Assistant] SELECT delivery_status, AVERAGE(amount) AS average_amount FROM banking.sales GROUP BY delivery_status;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE tradingplatform.metadata (
  venue_id text PRIMARY KEY -- unique identifier,
  last_inspected timestamp without time zone,
  location_lon character varying(64) NOT NULL,
  type character varying(256),
  category varchar,
  name text NOT NULL,
  parking_available varchar,
  wallet_id text -- reference to wallets.payment_id,
  FOREIGN KEY (wallet_id) REFERENCES wallets(payment_id)
)

CREATE TABLE tradingplatform.wallets (
  payment_id text PRIMARY KEY -- unique identifier,
  updated_at date,
  debit text NOT NULL,
  reconciliation_status character varying(128),
  reference_number varchar,
  user_id char -- identifier for user,
  exchange_rate character varying(64),
  metadat_id text -- reference to metadata.venue_id,
  FOREIGN KEY (metadat_id) REFERENCES metadata(venue_id)
)

[User] Display all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] Get all metadata older than 6 months.

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

[User] Get average of category by location_lon from metadata.

[Assistant] SELECT location_lon, AVERAGE(category) AS average_category FROM tradingplatform.metadata GROUP BY location_lon;


[User] Retrieve last_inspected, location_lon, category for every metadata.

[Assistant] SELECT last_inspected, location_lon, category FROM tradingplatform.metadata;

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

[Assistant] SELECT last_inspected, location_lon, category FROM tradingplatform.metadata ORDER BY name DESC;

[User] What is the max name for each type in metadata?

[Assistant] SELECT type, MAX(name) AS max_name FROM tradingplatform.metadata GROUP BY type;


[User] Retrieve exchange_rate, user_id, metadat_id for every wallet.

[Assistant] SELECT exchange_rate, user_id, metadat_id FROM tradingplatform.wallets;

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

[Assistant] SELECT exchange_rate, user_id, metadat_id FROM tradingplatform.wallets WHERE user_id LIKE 'A%';

[User] Return just 5 rows.

[Assistant] SELECT exchange_rate, user_id, metadat_id FROM tradingplatform.wallets WHERE user_id LIKE 'A%' LIMIT 5;


[User] Show me all wallets.

[Assistant] SELECT * FROM tradingplatform.wallets;

[User] Retrieve reference_number, metadat_id, wallet_id, location_lon showing the relationship between wallets and metadata.

[Assistant] SELECT *, metadata.wallet_id, metadata.location_lon FROM tradingplatform.wallets JOIN tradingplatform.metadata ON wallets.metadat_id = metadata.venue_id;

[User] Only show the top 20 results.

[Assistant] SELECT *, metadata.wallet_id, metadata.location_lon FROM tradingplatform.wallets JOIN tradingplatform.metadata ON wallets.metadat_id = metadata.venue_id LIMIT 20;


[User] List location_lon, category, name from metadata.

[Assistant] SELECT location_lon, category, name FROM tradingplatform.metadata;

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

[Assistant] SELECT location_lon, category, name FROM tradingplatform.metadata WHERE last_inspected > '2023-01-01';

[User] Show the results sorted by last_inspected ascending.

[Assistant] SELECT location_lon, category, name FROM tradingplatform.metadata WHERE last_inspected > '2023-01-01' ORDER BY last_inspected ASC;


[User] List all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] Can you order these by wallet_id ascending?

[Assistant] SELECT * FROM tradingplatform.metadata ORDER BY wallet_id ASC;

[User] Restrict the output to 5 items.

[Assistant] SELECT * FROM tradingplatform.metadata ORDER BY wallet_id ASC LIMIT 5;


[User] List all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

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

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

[User] Show me the count of metadata grouped by wallet_id.

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


[User] Retrieve all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] Order the output by category ascending.

[Assistant] SELECT * FROM tradingplatform.metadata ORDER BY category ASC;

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

[Assistant] SELECT * FROM tradingplatform.metadata ORDER BY last_inspected DESC;


[User] List all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

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

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

[User] Limit the results to 10 rows.

[Assistant] SELECT * FROM tradingplatform.metadata WHERE last_inspected >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 10;


[User] Show me all metadata.

[Assistant] SELECT * FROM tradingplatform.metadata;

[User] List category, location_lon, reference_number, exchange_rate for each metadata along with their wallet information.

[Assistant] SELECT *, wallets.reference_number, wallets.exchange_rate FROM tradingplatform.metadata JOIN tradingplatform.wallets ON metadata.wallet_id = wallets.payment_id;

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

[Assistant] SELECT *, wallets.reference_number, wallets.exchange_rate FROM tradingplatform.metadata JOIN tradingplatform.wallets ON metadata.wallet_id = wallets.payment_id ORDER BY location_lon DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.loans (
  address_id varchar PRIMARY KEY -- unique identifier,
  created_at date,
  address_line1 character varying(256),
  address_line2 varchar,
  operating_hours char,
  city char,
  location_lat character varying(64),
  zip_code varchar
)

CREATE TABLE finance.payments (
  id character varying(64) NOT NULL -- unique identifier,
  processed_at timestamp without time zone,
  updated_at timestamp without time zone,
  delivery_status text NOT NULL,
  tax numeric(38,14) NOT NULL,
  currency character varying(128),
  loan_id text NOT NULL -- reference to loans.address_id,
  FOREIGN KEY (loan_id) REFERENCES loans(address_id)
)

[User] Show me id, updated_at, delivery_status for all payments.

[Assistant] SELECT id, updated_at, delivery_status FROM finance.payments;

[User] Get all payments created yesterday.

[Assistant] SELECT id, updated_at, delivery_status FROM finance.payments WHERE processed_at = CURRENT_DATE - INTERVAL '1 day';

[User] Show only 10 records.

[Assistant] SELECT id, updated_at, delivery_status FROM finance.payments WHERE processed_at = CURRENT_DATE - INTERVAL '1 day' LIMIT 10;


[User] Get delivery_status, tax, processed_at from all payments.

[Assistant] SELECT delivery_status, tax, processed_at FROM finance.payments;

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

[Assistant] SELECT delivery_status, tax, processed_at FROM finance.payments WHERE processed_at BETWEEN '2023-01-01' AND '2023-03-31';

[User] What is the min delivery_status for each currency in payments?

[Assistant] SELECT currency, MIN(delivery_status) AS min_delivery_status FROM finance.payments GROUP BY currency;


[User] List all payments.

[Assistant] SELECT * FROM finance.payments;

[User] List currency, tax, operating_hours, zip_code for each payment along with their loan information.

[Assistant] SELECT *, loans.operating_hours, loans.zip_code FROM finance.payments JOIN finance.loans ON payments.loan_id = loans.address_id;

[User] What is the min tax for each tax in payments?

[Assistant] SELECT tax, MIN(tax) AS min_tax FROM finance.payments GROUP BY tax;


[User] List all payments.

[Assistant] SELECT * FROM finance.payments;

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

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

[User] Restrict the output to 25 items.

[Assistant] SELECT * FROM finance.payments WHERE updated_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 25;


[User] Get all payments.

[Assistant] SELECT * FROM finance.payments;

[User] Show me loan_id, tax, address_line1, location_lat from payments and their related loans.

[Assistant] SELECT *, loans.address_line1, loans.location_lat FROM finance.payments JOIN finance.loans ON payments.loan_id = loans.address_id;

[User] Show me the count of payments grouped by id.

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


[User] Get currency, id, loan_id from all payments.

[Assistant] SELECT currency, id, loan_id FROM finance.payments;

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

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

[User] Restrict the output to 25 items.

[Assistant] SELECT currency, id, loan_id FROM finance.payments WHERE updated_at >= CURRENT_TIMESTAMP - INTERVAL '1 hour' LIMIT 25;


[User] Display all payments.

[Assistant] SELECT * FROM finance.payments;

[User] Show me currency, updated_at, location_lat, created_at from payments and their related loans.

[Assistant] SELECT *, loans.location_lat, loans.created_at FROM finance.payments JOIN finance.loans ON payments.loan_id = loans.address_id;

[User] How many payments are there per updated_at?

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


[User] List all payments.

[Assistant] SELECT * FROM finance.payments;

[User] Show me tax, currency, created_at, location_lat from payments and their related loans.

[Assistant] SELECT *, loans.created_at, loans.location_lat FROM finance.payments JOIN finance.loans ON payments.loan_id = loans.address_id;

[User] Can you order these by tax ascending?

[Assistant] SELECT *, loans.created_at, loans.location_lat FROM finance.payments JOIN finance.loans ON payments.loan_id = loans.address_id ORDER BY tax ASC;


[User] Get all payments.

[Assistant] SELECT * FROM finance.payments;

[User] Show me id, tax, location_lat, created_at from payments and their related loans.

[Assistant] SELECT *, loans.location_lat, loans.created_at FROM finance.payments JOIN finance.loans ON payments.loan_id = loans.address_id;

[User] Restrict the output to 10 items.

[Assistant] SELECT *, loans.location_lat, loans.created_at FROM finance.payments JOIN finance.loans ON payments.loan_id = loans.address_id LIMIT 10;


[User] Retrieve all payments.

[Assistant] SELECT * FROM finance.payments;

[User] Retrieve payments where loan_id LIKE 'A%'.

[Assistant] SELECT * FROM finance.payments WHERE loan_id LIKE 'A%';

[User] Order the output by tax ascending.

[Assistant] SELECT * FROM finance.payments WHERE loan_id LIKE 'A%' ORDER BY tax ASC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE finance.transactions (
  payment_id varchar PRIMARY KEY -- unique identifier,
  cancelled_at date,
  buyer_id char,
  customer_id varchar,
  exchange_rate text NOT NULL,
  payment_method char,
  fee character varying(128),
  subtotal numeric(38,14)
)

CREATE TABLE finance.investments (
  employee_id text PRIMARY KEY -- unique identifier,
  joined_at timestamp,
  website text,
  nationality character varying(256),
  birth_date timestamp,
  email character varying(128),
  salt text
)

CREATE TABLE finance.loans (
  invoice_id character varying(64) NOT NULL -- unique identifier,
  processed_at date,
  payment_status character varying(256),
  product_id character varying(256) NOT NULL,
  price smallint,
  subtotal decimal,
  status character varying(128) NOT NULL,
  approval_status text,
  investment_id text NOT NULL -- reference to investments.employee_id,
  FOREIGN KEY (investment_id) REFERENCES investments(employee_id)
)

[User] Display all loans.

[Assistant] SELECT * FROM finance.loans;

[User] List product_id, investment_id, nationality, website for each loan along with their investment information.

[Assistant] SELECT *, investments.nationality, investments.website FROM finance.loans JOIN finance.investments ON loans.investment_id = investments.employee_id;

[User] Show the results sorted by price ascending.

[Assistant] SELECT *, investments.nationality, investments.website FROM finance.loans JOIN finance.investments ON loans.investment_id = investments.employee_id ORDER BY price ASC;


[User] Show me all loans.

[Assistant] SELECT * FROM finance.loans;

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

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

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

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


[User] List all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Can you order these by status ascending?

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

[User] Restrict the output to 10 items.

[Assistant] SELECT * FROM finance.loans ORDER BY status ASC LIMIT 10;


[User] Retrieve status, investment_id, product_id for every loan.

[Assistant] SELECT status, investment_id, product_id FROM finance.loans;

[User] Sort the results by product_id ascending.

[Assistant] SELECT status, investment_id, product_id FROM finance.loans ORDER BY product_id ASC;

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

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


[User] List processed_at, subtotal, approval_status from loans.

[Assistant] SELECT processed_at, subtotal, approval_status FROM finance.loans;

[User] Can you order these by price descending?

[Assistant] SELECT processed_at, subtotal, approval_status FROM finance.loans ORDER BY price DESC;

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

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


[User] List all loans.

[Assistant] SELECT * FROM finance.loans;

[User] Find loans where subtotal > 46.

[Assistant] SELECT * FROM finance.loans WHERE subtotal > 46;

[User] Calculate min of subtotal for each invoice_id in loans.

[Assistant] SELECT invoice_id, MIN(subtotal) AS min_subtotal FROM finance.loans GROUP BY invoice_id;


[User] Get all loans.

[Assistant] SELECT * FROM finance.loans;

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

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

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

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


[User] Retrieve all loans.

[Assistant] SELECT * FROM finance.loans;

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

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

[User] Show the results sorted by investment_id descending.

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


[User] Show me approval_status, invoice_id, investment_id for all loans.

[Assistant] SELECT approval_status, invoice_id, investment_id FROM finance.loans;

[User] Retrieve investment_id, product_id, email, website showing the relationship between loans and investments.

[Assistant] SELECT approval_status, invoice_id, investment_id, investments.email, investments.website FROM finance.loans JOIN finance.investments ON loans.investment_id = investments.employee_id;

[User] Show me max of processed_at grouped by product_id for loans.

[Assistant] SELECT product_id, MAX(processed_at) AS max_processed_at FROM finance.loans GROUP BY product_id;


[User] Show me approval_status, price, processed_at for all loans.

[Assistant] SELECT approval_status, price, processed_at FROM finance.loans;

[User] Show me status, invoice_id, email, nationality from loans and their related investments.

[Assistant] SELECT approval_status, price, processed_at, investments.email, investments.nationality FROM finance.loans JOIN finance.investments ON loans.investment_id = investments.employee_id;

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

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