System:
You are very professional for database language writing. 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 project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )
CREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )
CREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )
CREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )
CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )

[User] What is the average profit of smart money addresses whose profit is above $1,000, grouped by chain?

[Assistant]
SELECT chain, AVG(profit) AS avg_profit
FROM smart_money_profit
WHERE profit > 1000
GROUP BY chain;


System:
You are very professional for database language writing. 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 social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )
CREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )
CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )
CREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )
CREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )

[User] List all group chat conversations and the number of messages in each group chat.

[Assistant]
SELECT c.conversation_id,
       c.group_name,
       COUNT(m.message_id) AS message_count
FROM social_media.conversations c
JOIN social_media.messages m
  ON c.conversation_id = m.conversation_id
WHERE c.is_group_chat = true
GROUP BY c.conversation_id, c.group_name;

[User] Actually, only include group chats with more than 10 messages and order by message_count descending.

[Assistant]
SELECT c.conversation_id,
       c.group_name,
       COUNT(m.message_id) AS message_count
FROM social_media.conversations c
JOIN social_media.messages m
  ON c.conversation_id = m.conversation_id
WHERE c.is_group_chat = true
GROUP BY c.conversation_id, c.group_name
HAVING COUNT(m.message_id) > 10
ORDER BY message_count DESC;


System:
You are very professional for database language writing. 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 project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )

[User] How many projects raised funds in 2023?

[Assistant]
SELECT COUNT(*) AS project_count
FROM project_fundraising_record
WHERE investment_date LIKE '2023-%';

[User] Also provide the average investment_value for these projects.

[Assistant]
SELECT COUNT(*) AS project_count, AVG(investment_value) AS avg_investment
FROM project_fundraising_record
WHERE investment_date LIKE '2023-%';


System:
You are very professional for database language writing. 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 hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )
CREATE TABLE hospitality_technology.rooms (
    room_id character varying(64) NOT NULL,  -- unique identifier for the room
    property_id character varying(64) NOT NULL, -- FK to properties table
    room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')
    room_type_id character varying(64) NOT NULL, -- FK to room_types table
    floor integer, -- floor number the room is on
    status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance
    is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag
    features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)
    current_condition text, -- notes on room condition
    last_cleaned_at timestamp with time zone, -- timestamp of last cleaning
    PRIMARY KEY (room_id),
    FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),
    FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)
)
CREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )
CREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )
CREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
CREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )
CREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )
CREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )

[User] For each property, show the number of guests who have checked in since the start of this year.

[Assistant]
SELECT p.property_name, COUNT(DISTINCT res.guest_id) AS guest_count
FROM hospitality_technology.reservations res
JOIN hospitality_technology.properties p ON res.property_id = p.property_id
WHERE res.status = 'CheckedIn' AND res.actual_check_in_ts >= DATE_TRUNC('year', CURRENT_DATE)
GROUP BY p.property_name;

[User] Can you also include the total number of unique reservations per property in that time frame?

[Assistant]
SELECT p.property_name, COUNT(DISTINCT res.guest_id) AS guest_count, COUNT(res.reservation_id) AS reservation_count
FROM hospitality_technology.reservations res
JOIN hospitality_technology.properties p ON res.property_id = p.property_id
WHERE res.status = 'CheckedIn' AND res.actual_check_in_ts >= DATE_TRUNC('year', CURRENT_DATE)
GROUP BY p.property_name;

[User] Please also show the average length of stay (in days) for these reservations per property.

[Assistant]
SELECT p.property_name,
       COUNT(DISTINCT res.guest_id) AS guest_count,
       COUNT(res.reservation_id) AS reservation_count,
       AVG(res.check_out_date - res.check_in_date) AS avg_length_of_stay_days
FROM hospitality_technology.reservations res
JOIN hospitality_technology.properties p ON res.property_id = p.property_id
WHERE res.status = 'CheckedIn' AND res.actual_check_in_ts >= DATE_TRUNC('year', CURRENT_DATE)
GROUP BY p.property_name;


System:
You are very professional for database language writing. 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
Use Hashes. Key pattern: 'inv:<inventory_record_id>'. Example: HSET inv:INVREC500 component_id "component:WINGBOLT" quantity 5000 location_warehouse "WH3" batch_number "BCH778899" ... Consider Sorted Set by expiry date: ZADD component_expiry:<component_id> <expiry_timestamp> <inventory_record_id>.

[User] I need to get the inventory quantity and location for a specific batch number. Can you help with that?

[Assistant] HGETALL inv:<inventory_record_id>

[User] Can you also show me the component ID associated with this batch?

[Assistant] HGETALL inv:<inventory_record_id>

[User] If I want to retrieve multiple inventory records for the same component ID, how can I do that?

[Assistant] ZRANGE component_expiry:<component_id> 0 -1

[User] Can you sort those records by expiry date in ascending order?

[Assistant] ZRANGE component_expiry:<component_id> 0 -1 WITHSCORES


System:
You are very professional for database language writing. 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 transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )

[User] What is the average estimated_duration_minutes for each route type?

[Assistant] SELECT type, AVG(estimated_duration_minutes) AS average_duration FROM transportation.routes GROUP BY type;

[User] Now filter to include only route types with average duration greater than 60 minutes and order by average duration descending.

[Assistant] SELECT type, AVG(estimated_duration_minutes) AS average_duration FROM transportation.routes GROUP BY type HAVING AVG(estimated_duration_minutes) > 60 ORDER BY average_duration DESC;


System:
You are very professional for database language writing. 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 legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )
CREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )
CREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )
CREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )
CREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )
CREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )

[User] Retrieve the invoice_number, issue_date, total_amount, client_id, and case_name for all invoices with status 'Sent' issued between '2024-07-01' and '2024-07-31'. Order the results by issue_date descending.

[Assistant]
SELECT i.invoice_number, i.issue_date, i.total_amount, i.client_id, c.case_name
FROM legal_services.invoices i
JOIN legal_services.cases c ON i.case_id = c.case_id
WHERE i.status = 'Sent'
  AND i.issue_date BETWEEN '2024-07-01' AND '2024-07-31'
ORDER BY i.issue_date DESC;


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )

[User] Which agents have sold policies with a coverage limit over 1,000,000, and what are the policy numbers and their respective coverage limits?

[Assistant] SELECT agent_id, policy_number, coverage_limit FROM insurance.policies WHERE coverage_limit > 1000000;


System:
You are very professional for database language writing. 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 hospitality_technology.rooms (
    room_id character varying(64) NOT NULL,  -- unique identifier for the room
    property_id character varying(64) NOT NULL, -- FK to properties table
    room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')
    room_type_id character varying(64) NOT NULL, -- FK to room_types table
    floor integer, -- floor number the room is on
    status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance
    is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag
    features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)
    current_condition text, -- notes on room condition
    last_cleaned_at timestamp with time zone, -- timestamp of last cleaning
    PRIMARY KEY (room_id),
    FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),
    FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)
)

[User] List all smoking rooms, showing the property name, room number, and room type name.

[Assistant] SELECT T1.property_name, T2.room_number, T3.type_name FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.rooms AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.room_types AS T3 ON T2.room_type_id = T3.room_type_id WHERE T2.is_smoking = true


System:
You are very professional for database language writing. 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 legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )

[User] List all law firms that do not have a website registered, including their firm name and phone.

[Assistant]
SELECT firm_name, phone
FROM legal_services.law_firms
WHERE website IS NULL OR website = '';


System:
You are very professional for database language writing. 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 legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )
CREATE TABLE legal_services.lawyers (
    lawyer_id character varying(64) NOT NULL,  -- unique identifier for the lawyer
    first_name character varying(100) NOT NULL, -- lawyer's first name
    last_name character varying(100) NOT NULL, -- lawyer's last name
    bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number
    firm_id character varying(64), -- FK to law_firms table
    email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email
    phone character varying(32), -- lawyer's contact phone number
    specialization text, -- areas of legal expertise
    hire_date timestamp NOT NULL, -- date the lawyer was hired or joined
    is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner
    PRIMARY KEY (lawyer_id)
)
CREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )
CREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )
CREATE TABLE legal_services.time_entries (
    entry_id character varying(64) NOT NULL,  -- unique identifier for the time entry
    case_id character varying(64) NOT NULL, -- FK to cases table
    lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)
    date_worked date NOT NULL, -- date the work was performed
    hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)
    billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry
    description text NOT NULL, -- detailed description of the work performed
    is_billable boolean DEFAULT true, -- whether this time entry is billable to the client
    is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice
    invoice_id character varying(64), -- FK to invoices table (once billed)
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded
    PRIMARY KEY (entry_id)
)
CREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )
CREATE TABLE legal_services.appointments (
    appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment
    client_id character varying(64) NOT NULL, -- FK to clients table
    lawyer_id character varying(64) NOT NULL, -- FK to lawyers table
    case_id character varying(64), -- FK to cases table (optional, if related to a specific case)
    start_time timestamp NOT NULL, -- scheduled start date and time
    end_time timestamp NOT NULL, -- scheduled end date and time
    location text, -- location of the meeting (address or virtual link)
    subject character varying(255), -- subject or purpose of the appointment
    notes text, -- additional notes for the appointment
    status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (appointment_id)
)

[User] List the first and last names of all lawyers who have worked on time entries for cases associated with clients from the company 'Innovatech Ltd'.

[Assistant] SELECT DISTINCT T1.first_name, T1.last_name FROM legal_services.lawyers AS T1 INNER JOIN legal_services.time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id INNER JOIN legal_services.cases AS T3 ON T2.case_id = T3.case_id INNER JOIN legal_services.clients AS T4 ON T3.client_id = T4.client_id WHERE T4.company_name = 'Innovatech Ltd';


System:
You are very professional for database language writing. 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 social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )
CREATE TABLE social_media.follows (
    follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship
    follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)
    following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started
    PRIMARY KEY (follow_id),
    CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows
)
CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )
CREATE TABLE social_media.post_hashtags (
    post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link
    post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)
    hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)
    PRIMARY KEY (post_hashtag_id),
    CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post
)
CREATE TABLE social_media.messages (
    message_id character varying(64) NOT NULL, -- unique identifier for the message
    conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)
    sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)
    content text, -- textual content of the message
    media_url text, -- URL to attached media (image/video)
    media_type character varying(20), -- type of media ('image', 'video', null)
    sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent
    read_at timestamp, -- timestamp when message was read by recipient(s)
    PRIMARY KEY (message_id)
)
CREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )
CREATE TABLE social_media.conversation_participants (
    participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry
    conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)
    user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)
    joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation
    last_read_at timestamp, -- timestamp indicating up to when the user has read messages
    PRIMARY KEY (participant_id),
    CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times
)
CREATE TABLE social_media.notifications (
    notification_id character varying(64) NOT NULL, -- unique identifier for the notification
    recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)
    sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)
    notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')
    target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)
    target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created
    read_at timestamp, -- timestamp notification was marked as read
    PRIMARY KEY (notification_id)
)
CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )

[User] List all post IDs and their corresponding hashtag names for posts that include media.

[Assistant]
SELECT ph.post_id, h.tag_name
FROM social_media.post_hashtags ph
JOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id
JOIN social_media.posts p ON ph.post_id = p.post_id
WHERE p.media_url IS NOT NULL AND p.media_url != '';


System:
You are very professional for database language writing. 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 social_media.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified bool )

[User] Show the username, full name, and location for all users who registered before January 1, 2024 and are not verified.

[Assistant] SELECT username, full_name, location FROM social_media.users WHERE created_at < '2024-01-01' AND is_verified = false;

[User] Only include those who have a non-empty location.

[Assistant] SELECT username, full_name, location FROM social_media.users WHERE created_at < '2024-01-01' AND is_verified = false AND location IS NOT NULL AND location <> '';


System:
You are very professional for database language writing. 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 financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )

[User] List each account number and the total quantity of shares traded through it.

[Assistant] SELECT T2.account_number, SUM(T1.quantity) FROM financial_services.trades AS T1 JOIN financial_services.accounts AS T2 ON T1.account_id = T2.account_id GROUP BY 1

[User] Only include accounts with total quantity traded greater than 1000, and order the results by total quantity descending.

[Assistant] SELECT T2.account_number, SUM(T1.quantity) AS total_traded_quantity FROM financial_services.trades AS T1 JOIN financial_services.accounts AS T2 ON T1.account_id = T2.account_id GROUP BY 1 HAVING SUM(T1.quantity) > 1000 ORDER BY total_traded_quantity DESC


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )

[User] Show me the total estimated loss per claim status, and for each status, include the most recent claim's incident date.

[Assistant]
SELECT status, SUM(estimated_loss) AS total_estimated_loss, MAX(incident_date) AS most_recent_incident_date
FROM insurance.claims
GROUP BY status;


System:
You are very professional for database language writing. 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 transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )

[User] For each vehicle, can you show the vehicle_id, the number of unique fuel types it used, and the maximum quantity recorded in a single fuel log? Only include vehicles that have used more than one type of fuel.

[Assistant]
SELECT vehicle_id, COUNT(DISTINCT fuel_type) AS unique_fuel_types, MAX(quantity) AS max_quantity
FROM transportation.fuel_logs
GROUP BY vehicle_id
HAVING COUNT(DISTINCT fuel_type) > 1;

[User] Additionally, for these vehicles, please provide the total fuel cost for each vehicle.

[Assistant]
SELECT vehicle_id, COUNT(DISTINCT fuel_type) AS unique_fuel_types, MAX(quantity) AS max_quantity, SUM(total_cost) AS total_fuel_cost
FROM transportation.fuel_logs
GROUP BY vehicle_id
HAVING COUNT(DISTINCT fuel_type) > 1;


System:
You are very professional for database language writing. 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 social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )
CREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )
CREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )
CREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )
CREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )
CREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )
CREATE TABLE social_media.post_hashtags ( post_hashtag_id text, post_id text, hashtag_id text )
CREATE TABLE social_media.messages (
    message_id character varying(64) NOT NULL, -- unique identifier for the message
    conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)
    sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)
    content text, -- textual content of the message
    media_url text, -- URL to attached media (image/video)
    media_type character varying(20), -- type of media ('image', 'video', null)
    sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent
    read_at timestamp, -- timestamp when message was read by recipient(s)
    PRIMARY KEY (message_id)
)
CREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )
CREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )
CREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )

[User] List the usernames of users who have created posts associated with any hashtag, and the name of the hashtag.

[Assistant]
SELECT
  u.username,
  h.tag_name
FROM social_media.users AS u
JOIN social_media.posts AS p
  ON u.user_id = p.user_id
JOIN social_media.post_hashtags AS ph
  ON p.post_id = ph.post_id
JOIN social_media.hashtags AS h
  ON ph.hashtag_id = h.hashtag_id;

[User] Please refine the list to only include users who are verified.

[Assistant]
SELECT
  u.username,
  h.tag_name
FROM social_media.users AS u
JOIN social_media.posts AS p
  ON u.user_id = p.user_id
JOIN social_media.post_hashtags AS ph
  ON p.post_id = ph.post_id
JOIN social_media.hashtags AS h
  ON ph.hashtag_id = h.hashtag_id
WHERE
  u.is_verified = TRUE;


System:
You are very professional for database language writing. 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 social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )
CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )
CREATE TABLE social_media.comments (
    comment_id character varying(64) NOT NULL, -- unique identifier for the comment
    post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)
    user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)
    parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)
    content text NOT NULL, -- textual content of the comment
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation
    updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit
    PRIMARY KEY (comment_id)
)
CREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )
CREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )
CREATE TABLE social_media.post_hashtags (
    post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link
    post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)
    hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)
    PRIMARY KEY (post_hashtag_id),
    CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post
)
CREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )
CREATE TABLE social_media.conversations (
    conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated
    last_message_at timestamp, -- timestamp of the last message in the conversation
    is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message
    group_name character varying(100), -- name of the group chat (if applicable)
    PRIMARY KEY (conversation_id)
)
CREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )
CREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )
CREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )

[User] List the message_id, content, sender's username, and group_name for all messages in group chats.

[Assistant]
SELECT m.message_id, m.content, u.username, c.group_name
FROM social_media.messages m
JOIN social_media.conversations c ON m.conversation_id = c.conversation_id
JOIN social_media.users u ON m.sender_user_id = u.user_id
WHERE c.is_group_chat = TRUE;

[User] Exclude group chats that have fewer than 3 participants.

[Assistant]
SELECT m.message_id, m.content, u.username, c.group_name
FROM social_media.messages m
JOIN social_media.conversations c ON m.conversation_id = c.conversation_id
JOIN social_media.users u ON m.sender_user_id = u.user_id
JOIN (
  SELECT conversation_id
  FROM social_media.conversation_participants
  GROUP BY conversation_id
  HAVING COUNT(*) >= 3
) cp ON c.conversation_id = cp.conversation_id
WHERE c.is_group_chat = TRUE;

[User] And only show messages sent after '2024-06-01', ordering by sent_at ascending.

[Assistant]
SELECT m.message_id, m.content, u.username, c.group_name
FROM social_media.messages m
JOIN social_media.conversations c ON m.conversation_id = c.conversation_id
JOIN social_media.users u ON m.sender_user_id = u.user_id
JOIN (
  SELECT conversation_id
  FROM social_media.conversation_participants
  GROUP BY conversation_id
  HAVING COUNT(*) >= 3
) cp ON c.conversation_id = cp.conversation_id
WHERE c.is_group_chat = TRUE
  AND m.sent_at > '2024-06-01'
ORDER BY m.sent_at ASC;


[User] List all claims that are still pending (status = 'pending') and were reported more than 30 days ago.

[Assistant] SELECT claim_id, policy_id, customer_id, reported_date FROM insurance.claims WHERE status = 'pending' AND reported_date < CURRENT_DATE - INTERVAL '30 days';

[User] Now include only claims with estimated loss values and sort them by the oldest reported date first.

[Assistant] SELECT claim_id, policy_id, customer_id, reported_date, estimated_loss FROM insurance.claims WHERE status = 'pending' AND reported_date < CURRENT_DATE - INTERVAL '30 days' AND estimated_loss IS NOT NULL ORDER BY reported_date ASC;


System:
You are very professional for database language writing. 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 trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )
CREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )
CREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )
CREATE TABLE trading_platform.metadata (
    metadata_id character varying(64) NOT NULL,  -- unique identifier for the metadata
    asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with
    key character varying(128) NOT NULL, -- key of the metadata
    value text NOT NULL, -- value of the metadata
    PRIMARY KEY (metadata_id)
)
CREATE TABLE trading_platform.logs (
    log_id character varying(64) NOT NULL,  -- unique identifier for the log entry
    user_id character varying(64), -- identifier of the user associated with the log entry
    action character varying(128) NOT NULL, -- action performed
    details text NOT NULL, -- details of the action
    logged_at timestamp NOT NULL, -- time when the log entry was created
    PRIMARY KEY (log_id)
)
CREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )

[User] For each asset, show its name and the number of metadata entries associated with it, including assets with zero metadata, sorted by asset name ascending.

[Assistant]
SELECT a.name, COUNT(m.metadata_id) AS metadata_count
FROM trading_platform.assets a
LEFT JOIN trading_platform.metadata m
  ON a.asset_id = m.asset_id
GROUP BY a.name
ORDER BY a.name;

[User] Actually, I only want assets that have more than 3 metadata entries.

[Assistant]
SELECT a.name, COUNT(m.metadata_id) AS metadata_count
FROM trading_platform.assets a
LEFT JOIN trading_platform.metadata m
  ON a.asset_id = m.asset_id
GROUP BY a.name
HAVING COUNT(m.metadata_id) > 3
ORDER BY a.name;


System:
You are very professional for database language writing. 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 government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )

[User] List the full names of employees who have verified 'Proof of Identity' documents.

[Assistant] SELECT DISTINCT T1.first_name, T1.last_name FROM government_services.employees AS T1 JOIN government_services.documents AS T2 ON T1.employee_id = T2.verified_by_employee_id WHERE T2.document_type = 'Proof of Identity';


System:
You are very professional for database language writing. 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.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )

[User] Show me the names and manufacturers of all medications that have a description provided.

[Assistant] SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NOT NULL;

[User] Now, only show those manufactured by 'Pfizer'.

[Assistant] SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NOT NULL AND manufacturer = 'Pfizer';

[User] Further filter to medications whose generic name contains 'statin'.

[Assistant] SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NOT NULL AND manufacturer = 'Pfizer' AND generic_name LIKE '%statin%';

[User] Instead, just show the medication ID and NDC code for these.

[Assistant] SELECT medication_id, ndc_code FROM healthcare.medications WHERE description IS NOT NULL AND manufacturer = 'Pfizer' AND generic_name LIKE '%statin%';


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.medical_records (
    record_id character varying(64) NOT NULL,  -- unique identifier for the medical record entry
    patient_id character varying(64) NOT NULL, -- FK to patients table
    appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)
    doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)
    record_date timestamp with time zone NOT NULL, -- date the record/observation was made
    chief_complaint text, -- patient's primary reason for visit
    present_illness_history text, -- detailed history of the current issue
    past_medical_history text, -- relevant past conditions/surgeries
    physical_examination_notes text, -- findings from the physical exam
    assessment text, -- doctor's assessment/diagnosis summary
    treatment_plan text, -- planned course of action
    vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON
    created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
    PRIMARY KEY (record_id)
)
CREATE TABLE healthcare.diagnoses (
    diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry
    record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry
    patient_id character varying(64) NOT NULL, -- FK to patients table
    doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)
    diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)
    code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used
    description text, -- textual description of the diagnosis
    diagnosis_date date NOT NULL, -- date the diagnosis was made
    status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out
    is_chronic boolean DEFAULT false, -- flag for chronic conditions
    PRIMARY KEY (diagnosis_id)
)
CREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )

[User] Show me all prescriptions made by doctors who have issued diagnoses described as 'Hypertension'. Include the doctor's ID, prescription ID, medication ID, and prescription date.

[Assistant]
SELECT p.doctor_id, p.prescription_id, p.medication_id, p.prescription_date
FROM healthcare.prescriptions p
JOIN healthcare.diagnoses d ON p.doctor_id = d.doctor_id
WHERE d.description = 'Hypertension';

[User] Change it to only include those prescriptions that started after January 1st, 2024.

[Assistant]
SELECT p.doctor_id, p.prescription_id, p.medication_id, p.prescription_date
FROM healthcare.prescriptions p
JOIN healthcare.diagnoses d ON p.doctor_id = d.doctor_id
WHERE d.description = 'Hypertension' AND p.start_date > '2024-01-01';

[User] Actually, also include the patient ID and only show results where the doctor's diagnosis of 'Hypertension' happened before the prescription start date.

[Assistant]
SELECT p.doctor_id, p.patient_id, p.prescription_id, p.medication_id, p.prescription_date
FROM healthcare.prescriptions p
JOIN healthcare.diagnoses d ON p.doctor_id = d.doctor_id AND p.patient_id = d.patient_id
WHERE d.description = 'Hypertension' AND p.start_date > '2024-01-01' AND d.diagnosis_date < p.start_date;


System:
You are very professional for database language writing. 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 hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
CREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )

[User] Find all reservations where the total amount is greater than 500 and they have at least one service order. Show the reservation ID and the total amount.

[Assistant] SELECT DISTINCT T1.reservation_id, T1.total_amount FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.service_orders AS T2 ON T1.reservation_id = T2.reservation_id WHERE T1.total_amount > 500;

[User] Actually, also include the number of service orders for each of these reservations and the total price of those service orders.

[Assistant] SELECT T1.reservation_id, T1.total_amount, COUNT(T2.order_id), SUM(T2.total_price) FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.service_orders AS T2 ON T1.reservation_id = T2.reservation_id WHERE T1.total_amount > 500 GROUP BY T1.reservation_id, T1.total_amount;

[User] Only show reservations where the total price of the service orders is more than 100.

[Assistant] SELECT T1.reservation_id, T1.total_amount, COUNT(T2.order_id), SUM(T2.total_price) FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.service_orders AS T2 ON T1.reservation_id = T2.reservation_id WHERE T1.total_amount > 500 GROUP BY T1.reservation_id, T1.total_amount HAVING SUM(T2.total_price) > 100;


[User] Show me law firms that were founded after 2018 and have a website provided.

[Assistant]
SELECT firm_name, founded_date, website
FROM legal_services.law_firms
WHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '';

[User] Actually, only include firms where the phone number starts with '+1'.

[Assistant]
SELECT firm_name, founded_date, website, phone
FROM legal_services.law_firms
WHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '' AND phone LIKE '+1%';

[User] Also add the firm address and sort the results by founded_date descending.

[Assistant]
SELECT firm_name, founded_date, website, phone, address
FROM legal_services.law_firms
WHERE founded_date > '2018-12-31' AND website IS NOT NULL AND website <> '' AND phone LIKE '+1%'
ORDER BY founded_date DESC;


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )
CREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )
CREATE TABLE healthcare.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )

[User] I need a list of all chronic diagnoses marked as 'Active', showing diagnosis_id, diagnosis_date, doctor_id, and the associated chief_complaint from medical_records.

[Assistant]
SELECT d.diagnosis_id,
       d.diagnosis_date,
       d.doctor_id,
       m.chief_complaint
FROM healthcare.diagnoses d
JOIN healthcare.medical_records m
  ON d.record_id = m.record_id
WHERE d.is_chronic = TRUE
  AND d.status = 'Active';

[User] Actually, only include those diagnoses that occurred in February 2024 and order the results by diagnosis_date ascending.

[Assistant]
SELECT d.diagnosis_id,
       d.diagnosis_date,
       d.doctor_id,
       m.chief_complaint
FROM healthcare.diagnoses d
JOIN healthcare.medical_records m
  ON d.record_id = m.record_id
WHERE d.is_chronic = TRUE
  AND d.status = 'Active'
  AND d.diagnosis_date BETWEEN '2024-02-01' AND '2024-02-29'
ORDER BY d.diagnosis_date ASC;

[User] Also, include the assessment column from medical_records in the output.

[Assistant]
SELECT d.diagnosis_id,
       d.diagnosis_date,
       d.doctor_id,
       m.chief_complaint,
       m.assessment
FROM healthcare.diagnoses d
JOIN healthcare.medical_records m
  ON d.record_id = m.record_id
WHERE d.is_chronic = TRUE
  AND d.status = 'Active'
  AND d.diagnosis_date BETWEEN '2024-02-01' AND '2024-02-29'
ORDER BY d.diagnosis_date ASC;


System:
You are very professional for database language writing. 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 trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE trading_platform.trades (
    trade_id character varying(64) NOT NULL,  -- unique identifier for the trade
    order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade
    buyer_id character varying(64) NOT NULL, -- identifier of the buyer
    seller_id character varying(64) NOT NULL, -- identifier of the seller
    asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
    quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade
    price numeric(38,14) NOT NULL, -- price per unit of the asset
    traded_at timestamp NOT NULL, -- time when the trade was executed
    PRIMARY KEY (trade_id)
)
CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )
CREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )
CREATE TABLE trading_platform.metadata (
    metadata_id character varying(64) NOT NULL,  -- unique identifier for the metadata
    asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with
    key character varying(128) NOT NULL, -- key of the metadata
    value text NOT NULL, -- value of the metadata
    PRIMARY KEY (metadata_id)
)
CREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )
CREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )

[User] Show me the top 5 users who have the highest total trade volume (quantity * price) as buyers, along with their wallet addresses and the number of distinct assets they traded.

[Assistant] SELECT t.buyer_id, w.address, COUNT(DISTINCT t.asset_id) AS distinct_assets, SUM(t.quantity * t.price) AS total_volume FROM trading_platform.trades t JOIN trading_platform.wallets w ON t.buyer_id = w.user_id GROUP BY t.buyer_id, w.address ORDER BY total_volume DESC LIMIT 5;

[User] Now modify the query to only include trades that happened in the last 30 days and show the average trade price for each buyer.

[Assistant] SELECT t.buyer_id, w.address, COUNT(DISTINCT t.asset_id) AS distinct_assets, SUM(t.quantity * t.price) AS total_volume, AVG(t.price) AS avg_price FROM trading_platform.trades t JOIN trading_platform.wallets w ON t.buyer_id = w.user_id WHERE t.traded_at >= NOW() - INTERVAL '30 days' GROUP BY t.buyer_id, w.address ORDER BY total_volume DESC LIMIT 5;

[User] Actually, I want to see the top 5 buyers by total trade volume who also have at least 3 distinct assets traded, and include their wallet creation date.

[Assistant] SELECT t.buyer_id, w.address, COUNT(DISTINCT t.asset_id) AS distinct_assets, SUM(t.quantity * t.price) AS total_volume, AVG(t.price) AS avg_price, w.created_at AS wallet_created FROM trading_platform.trades t JOIN trading_platform.wallets w ON t.buyer_id = w.user_id WHERE t.traded_at >= NOW() - INTERVAL '30 days' GROUP BY t.buyer_id, w.address, w.created_at HAVING COUNT(DISTINCT t.asset_id) >= 3 ORDER BY total_volume DESC LIMIT 5;


System:
You are very professional for database language writing. 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 transportation.fuel_logs (
    fuel_log_id character varying(64) NOT NULL,  -- unique identifier for the fuel log entry
    vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled
    trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred
    log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred
    fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)
    quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)
    unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)
    cost_per_unit numeric(8, 4), -- price per unit of fuel
    total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase
    odometer_reading integer, -- vehicle mileage at time of fueling
    location_id character varying(64), -- identifier of the fueling station/location
    PRIMARY KEY (fuel_log_id)
)

[User] For each fuel_type, can you calculate the total total_cost and the average total_cost from the fuel_logs table?

[Assistant]
SELECT fuel_type,
       SUM(total_cost) AS total_cost_sum,
       AVG(total_cost) AS average_cost
FROM transportation.fuel_logs
GROUP BY fuel_type;

[User] Please exclude any fuel_type with fewer than 5 fuel log entries.

[Assistant]
SELECT fuel_type,
       SUM(total_cost) AS total_cost_sum,
       AVG(total_cost) AS average_cost
FROM transportation.fuel_logs
GROUP BY fuel_type
HAVING COUNT(*) >= 5;


System:
You are very professional for database language writing. 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 trading_platform.users (
    user_id character varying(64) NOT NULL,  -- unique identifier for the user
    username character varying(128) NOT NULL, -- username of the user
    email character varying(128) NOT NULL, -- email address of the user
    password_hash text NOT NULL, -- hashed password of the user
    created_at timestamp NOT NULL, -- time when the user account was created
    PRIMARY KEY (user_id)
)
CREATE TABLE trading_platform.orders (
    order_id character varying(64) NOT NULL,  -- unique identifier for the order
    user_id character varying(64) NOT NULL, -- identifier of the user placing the order
    wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order
    asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
    order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)
    quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order
    price numeric(38,14) NOT NULL, -- price per unit of the asset
    status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)
    created_at timestamp NOT NULL, -- time when the order was created
    PRIMARY KEY (order_id)
)
CREATE TABLE trading_platform.utxos (
    utxo_id character varying(64) NOT NULL,  -- unique identifier for the UTXO
    transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO
    output_index integer NOT NULL, -- index of the output in the transaction
    address character varying(128) NOT NULL, -- address that can spend the UTXO
    amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO
    spent boolean NOT NULL, -- whether the UTXO has been spent
    PRIMARY KEY (utxo_id)
)
CREATE TABLE trading_platform.dapps (
    dapp_id character varying(64) NOT NULL,  -- unique identifier for the DApp
    name character varying(128) NOT NULL, -- name of the DApp
    description text NOT NULL, -- description of the DApp
    url character varying(256) NOT NULL, -- URL of the DApp
    PRIMARY KEY (dapp_id)
)
CREATE TABLE trading_platform.peers (
    peer_id character varying(64) NOT NULL,  -- unique identifier for the peer
    ip_address character varying(15) NOT NULL, -- IP address of the peer
    port integer NOT NULL, -- port number of the peer
    last_seen timestamp NOT NULL, -- last time the peer was active
    PRIMARY KEY (peer_id)
)
CREATE TABLE trading_platform.logs (
    log_id character varying(64) NOT NULL,  -- unique identifier for the log entry
    user_id character varying(64), -- identifier of the user associated with the log entry
    action character varying(128) NOT NULL, -- action performed
    details text NOT NULL, -- details of the action
    logged_at timestamp NOT NULL, -- time when the log entry was created
    PRIMARY KEY (log_id)
)

[User] For each user, list their username and the total number of filled orders they have placed.

[Assistant]
SELECT u.username, COUNT(o.order_id) AS filled_order_count
FROM trading_platform.users u
JOIN trading_platform.orders o ON u.user_id = o.user_id
WHERE o.status = 'filled'
GROUP BY u.username;

[User] Now only include users who have placed more than 10 filled orders.

[Assistant]
SELECT u.username, COUNT(o.order_id) AS filled_order_count
FROM trading_platform.users u
JOIN trading_platform.orders o ON u.user_id = o.user_id
WHERE o.status = 'filled'
GROUP BY u.username
HAVING COUNT(o.order_id) > 10;


System:
You are very professional for database language writing. 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 ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )
CREATE TABLE healthcare.insurance_plans (
    plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan
    plan_name character varying(200) NOT NULL, -- name of the insurance plan
    insurance_provider character varying(100) NOT NULL, -- name of the insurance company
    plan_type character varying(50), -- e.g., PPO, HMO, EPO
    contact_phone character varying(20), -- provider contact number
    website character varying(255), -- provider website
    PRIMARY KEY (plan_id)
)

[User] List all female patients born before 1990 who have a phone number listed, showing their full names and contact information.

[Assistant] SELECT first_name, last_name, phone_number, email, emergency_contact_name, emergency_contact_phone FROM healthcare.patients WHERE gender = 'female' AND date_of_birth < '1990-01-01' AND phone_number IS NOT NULL;

[User] Now, I also want to see their insurance provider names if they have any insurance plans.

[Assistant] SELECT p.first_name, p.last_name, p.phone_number, p.email, ip.insurance_provider FROM healthcare.patients p LEFT JOIN healthcare.insurance_plans ip ON p.patient_id = ip.plan_id WHERE p.gender = 'female' AND p.date_of_birth < '1990-01-01' AND p.phone_number IS NOT NULL;

[User] Actually, I only need patients whose insurance providers are 'Blue Cross'.

[Assistant] SELECT p.first_name, p.last_name, p.phone_number, p.email, ip.insurance_provider FROM healthcare.patients p LEFT JOIN healthcare.insurance_plans ip ON p.patient_id = ip.plan_id WHERE p.gender = 'female' AND p.date_of_birth < '1990-01-01' AND p.phone_number IS NOT NULL AND ip.insurance_provider = 'Blue Cross';


System:
You are very professional for database language writing. 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 government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text )

[User] Find pairs of notifications for the same citizen where one was sent via 'Email' and another via 'SMS'. Display citizen_id, email_notification_id, sms_notification_id, email_sent_at, and sms_sent_at.

[Assistant]
SELECT e.citizen_id,
       e.notification_id AS email_notification_id,
       s.notification_id AS sms_notification_id,
       e.sent_at           AS email_sent_at,
       s.sent_at           AS sms_sent_at
FROM government_services.notifications e
JOIN government_services.notifications s
  ON e.citizen_id = s.citizen_id
 AND e.channel = 'Email'
 AND s.channel = 'SMS';


System:
You are very professional for database language writing. 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 web3.contracts ( contract_id.text, address.text, abi.text, bytecode.text, deployer_address.text, deployed_at.timestamp, network_id.text, status.text )
CREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )
CREATE TABLE web3.token_transfers ( transfer_id.text, token_id.text, from_address.text, to_address.text, value.numeric, transaction_id.text, log_index.integer )
CREATE TABLE web3.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )
CREATE TABLE web3.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )

[User] List the transaction IDs that have both an event and a token transfer, along with the name of the event and the value of the token transfer.

[Assistant] SELECT T1.transaction_id, T1.event_name, T2.value FROM web3.events AS T1 JOIN web3.token_transfers AS T2 ON T1.transaction_id = T2.transaction_id;


System:
You are very professional for database language writing. 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 manufacturing.materials (
    material_id character varying(64) NOT NULL,  -- unique identifier for the material
    material_name character varying(128) NOT NULL, -- common name (e.g., Titanium Alloy Grade 5, Carbon Fiber Prepreg)
    specification character varying(255), -- specification standard (e.g., AMS 4928)
    description text, -- detailed description of properties
    density_kg_m3 numeric(10, 4), -- density in kg per cubic meter
    tensile_strength_mpa integer, -- tensile strength in Megapascals
    PRIMARY KEY (material_id)
)
CREATE TABLE manufacturing.assembly_steps (
    step_id character varying(64) NOT NULL, -- unique identifier for an assembly step/task
    line_id character varying(64) NOT NULL, -- FK to the assembly line where this step occurs
    step_number integer NOT NULL, -- sequence number of the step on the line
    step_name character varying(255) NOT NULL, -- name of the task (e.g., Install Wing Root Fairing)
    description text, -- detailed instructions or description
    standard_duration_hours numeric(8,2), -- estimated time to complete the step
    required_skill_level character varying(50), -- skill level needed (e.g., 'Mechanic II', 'Electrician I')
    workstation character varying(100), -- specific workstation or area for the step
    PRIMARY KEY (step_id)
)

[User] 特定の材料の詳細情報を取得したいです。材料ID、材料名、仕様、密度を取得してください。

[Assistant]
SELECT material_id, material_name, specification, density_kg_m3
FROM manufacturing.materials
WHERE material_id = 'specific_material_id';

[User] さらに、引張強度が500MPa以上の材料だけを表示するようにできますか？

[Assistant]
SELECT material_id, material_name, specification, density_kg_m3
FROM manufacturing.materials
WHERE material_id = 'specific_material_id'
AND tensile_strength_mpa >= 500;

[User] もし密度が2000kg/m3未満の材料を除外したい場合はどうすればいいですか？

[Assistant]
SELECT material_id, material_name, specification, density_kg_m3
FROM manufacturing.materials
WHERE material_id = 'specific_material_id'
AND tensile_strength_mpa >= 500
AND density_kg_m3 >= 2000;

[User] 最後に、材料名をアルファベット順に並べ替えてください。

[Assistant]
SELECT material_id, material_name, specification, density_kg_m3
FROM manufacturing.materials
WHERE material_id = 'specific_material_id'
AND tensile_strength_mpa >= 500
AND density_kg_m3 >= 2000
ORDER BY material_name;


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )

[User] I need to list pairs of achievements within the same game, showing game_id, the name of the first achievement, and the name of the second achievement.

[Assistant]
SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2
FROM gaming_technology.achievements a1
JOIN gaming_technology.achievements a2
  ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id;

[User] Exclude any pairs where either achievement is hidden.

[Assistant]
SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2
FROM gaming_technology.achievements a1
JOIN gaming_technology.achievements a2
  ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id
WHERE a1.hidden = FALSE AND a2.hidden = FALSE;

[User] Only include pairs where the absolute difference in points between the two achievements is greater than 50.

[Assistant]
SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2
FROM gaming_technology.achievements a1
JOIN gaming_technology.achievements a2
  ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id
WHERE a1.hidden = FALSE AND a2.hidden = FALSE
  AND ABS(a1.points - a2.points) > 50;

[User] Finally, order the results by the points difference in descending order.

[Assistant]
SELECT a1.game_id, a1.name AS achievement1, a2.name AS achievement2
FROM gaming_technology.achievements a1
JOIN gaming_technology.achievements a2
  ON a1.game_id = a2.game_id AND a1.achievement_id < a2.achievement_id
WHERE a1.hidden = FALSE AND a2.hidden = FALSE
  AND ABS(a1.points - a2.points) > 50
ORDER BY ABS(a1.points - a2.points) DESC;


System:
You are very professional for database language writing. 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 trading_platform.users (
    user_id character varying(64) NOT NULL,  -- unique identifier for the user
    username character varying(128) NOT NULL, -- username of the user
    email character varying(128) NOT NULL, -- email address of the user
    password_hash text NOT NULL, -- hashed password of the user
    created_at timestamp NOT NULL, -- time when the user account was created
    PRIMARY KEY (user_id)
)
CREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )
CREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )
CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )

[User] Show each asset's symbol and the number of unique addresses that have UTXOs associated with it.

[Assistant]
SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses
FROM trading_platform.assets a
JOIN trading_platform.utxos u ON a.asset_id = u.transaction_id
GROUP BY a.asset_id, a.symbol;

[User] Now show only assets with more than 5 unique addresses.

[Assistant]
SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses
FROM trading_platform.assets a
JOIN trading_platform.utxos u ON a.asset_id = u.transaction_id
GROUP BY a.asset_id, a.symbol
HAVING COUNT(DISTINCT u.address) > 5;

[User] Please also include the total amount for each asset in the result.

[Assistant]
SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses, COALESCE(SUM(u.amount), 0) AS total_amount
FROM trading_platform.assets a
JOIN trading_platform.utxos u ON a.asset_id = u.transaction_id
GROUP BY a.asset_id, a.symbol
HAVING COUNT(DISTINCT u.address) > 5;

[User] Order the results by total_amount ascending and limit to the top 3.

[Assistant]
SELECT a.symbol, COUNT(DISTINCT u.address) AS unique_addresses, COALESCE(SUM(u.amount), 0) AS total_amount
FROM trading_platform.assets a
JOIN trading_platform.utxos u ON a.asset_id = u.transaction_id
GROUP BY a.asset_id, a.symbol
HAVING COUNT(DISTINCT u.address) > 5
ORDER BY total_amount ASC
LIMIT 3;


[User] Which medications do not have a generic name listed? Show their medication_id, medication_name, and manufacturer.

[Assistant] SELECT medication_id, medication_name, manufacturer FROM healthcare.medications WHERE generic_name IS NULL OR generic_name = '';

[User] Could you also include the description for each medication?

[Assistant] SELECT medication_id, medication_name, manufacturer, description FROM healthcare.medications WHERE generic_name IS NULL OR generic_name = '';


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.in_game_items ( item_id.uuid, game_id.uuid, item_name.text, item_type.text, description.text, rarity.text, cost_currency.text, cost_amount.numeric, attributes.jsonb )

[User] Find pairs of items within the same game where the cost of one item is at least 10 times the cost of the other. Show the game ID, the name of the more expensive item, and the name of the less expensive item.

[Assistant] SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id;

[User] Only include pairs where both items are of rarity 'Rare' or higher (i.e., 'Rare', 'Epic', 'Legendary').

[Assistant] SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id AND i1.rarity IN ('Rare', 'Epic', 'Legendary') AND i2.rarity IN ('Rare', 'Epic', 'Legendary');

[User] Exclude pairs where either item's cost is 0.

[Assistant] SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id AND i1.rarity IN ('Rare', 'Epic', 'Legendary') AND i2.rarity IN ('Rare', 'Epic', 'Legendary') AND i1.cost_amount > 0 AND i2.cost_amount > 0;

[User] Order the results by the game ID and then by the cost of the expensive item descending.

[Assistant] SELECT i1.game_id, i1.item_name AS expensive_item, i2.item_name AS cheaper_item FROM gaming_technology.in_game_items i1 JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id WHERE i1.cost_amount >= 10 * i2.cost_amount AND i1.item_id != i2.item_id AND i1.rarity IN ('Rare', 'Epic', 'Legendary') AND i2.rarity IN ('Rare', 'Epic', 'Legendary') AND i1.cost_amount > 0 AND i2.cost_amount > 0 ORDER BY i1.game_id, i1.cost_amount DESC;


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.customers (
    customer_id character varying(64) NOT NULL,  -- unique identifier for the customer
    first_name character varying(100) NOT NULL, -- customer's first name
    last_name character varying(100) NOT NULL, -- customer's last name
    date_of_birth date NOT NULL, -- customer's date of birth
    ssn_hash character varying(128), -- Hashed social security number (or national ID)
    address_line1 character varying(255) NOT NULL,
    address_line2 character varying(255),
    city character varying(100) NOT NULL,
    state character varying(50) NOT NULL,
    zip_code character varying(20) NOT NULL,
    country character varying(50) NOT NULL DEFAULT 'USA',
    phone_number character varying(30),
    email character varying(128) UNIQUE, -- unique email address
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created
    updated_at timestamp, -- when the customer record was last updated
    status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect
    PRIMARY KEY (customer_id)
)
CREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )
CREATE TABLE insurance.premium_payments ( payment_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, amount_paid numeric(12, 2) NOT NULL, payment_method character varying(50), transaction_reference character varying(128) UNIQUE, due_date date, payment_period_start date, payment_period_end date, status character varying(30) NOT NULL DEFAULT 'Completed', PRIMARY KEY (payment_id) )
CREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )

[User] Count the number of customers grouped by their status.

[Assistant] SELECT status, COUNT(*) FROM insurance.customers GROUP BY status;


System:
You are very professional for database language writing. 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 hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )
CREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )
CREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )
CREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )
CREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )
CREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )
CREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )
CREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )

[User] List guests who have written reviews, showing their full name and the review comment.

[Assistant] SELECT g.first_name || ' ' || g.last_name AS guest_full_name, r.comment FROM hospitality_technology.guests AS g JOIN hospitality_technology.reviews AS r ON g.guest_id = r.guest_id;

[User] Now only include reviews with an overall rating of 5.

[Assistant] SELECT g.first_name || ' ' || g.last_name AS guest_full_name, r.comment FROM hospitality_technology.guests AS g JOIN hospitality_technology.reviews AS r ON g.guest_id = r.guest_id WHERE r.rating_overall = 5;


System:
You are very professional for database language writing. 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 ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )

[User] Find all doctors who have a hospital affiliation and include their full names (concatenated), specialties, and affiliation IDs.

[Assistant] SELECT CONCAT(first_name, ' ', last_name) AS full_name, specialty, hospital_affiliation_id FROM healthcare.doctors WHERE hospital_affiliation_id IS NOT NULL;


System:
You are very professional for database language writing. 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 financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )
CREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )

[User] Give me the number of securities and the latest update timestamp for each security_type.

[Assistant]
SELECT security_type,
       COUNT(*) AS security_count,
       MAX(last_updated) AS latest_update
FROM financial_services.securities
GROUP BY security_type;

[User] Now only show types with more than 10 securities.

[Assistant]
SELECT security_type,
       COUNT(*) AS security_count,
       MAX(last_updated) AS latest_update
FROM financial_services.securities
GROUP BY security_type
HAVING COUNT(*) > 10;

[User] Sort the output by latest_update ascending.

[Assistant]
SELECT security_type,
       COUNT(*) AS security_count,
       MAX(last_updated) AS latest_update
FROM financial_services.securities
GROUP BY security_type
HAVING COUNT(*) > 10
ORDER BY latest_update ASC;


System:
You are very professional for database language writing. 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 transportation.locations (
    location_id character varying(64) NOT NULL,  -- unique identifier for the location
    name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)
    type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address
    address_line1 character varying(255), -- street address
    city character varying(128), -- city name
    state_province character varying(128), -- state or province
    postal_code character varying(32), -- postal code
    country character varying(64) NOT NULL, -- country name
    latitude numeric(9, 6), -- geographic latitude
    longitude numeric(9, 6), -- geographic longitude
    timezone character varying(64), -- IANA timezone name (e.g., America/New_York)
    PRIMARY KEY (location_id)
)
CREATE TABLE transportation.passengers (
    passenger_id character varying(64) NOT NULL,  -- unique identifier for the passenger
    first_name character varying(128) NOT NULL, -- passenger's first name
    last_name character varying(128) NOT NULL, -- passenger's last name
    email character varying(128) UNIQUE, -- email address
    phone_number character varying(32) UNIQUE, -- phone number
    date_of_birth date, -- passenger's date of birth
    loyalty_program_id character varying(64), -- identifier for loyalty program membership
    created_at timestamp with time zone NOT NULL, -- time when the passenger record was created
    PRIMARY KEY (passenger_id)
)
CREATE TABLE transportation.bookings (
    booking_id character varying(64) NOT NULL,  -- unique identifier for the booking
    passenger_id character varying(64) NOT NULL, -- identifier of the passenger making the booking
    trip_id character varying(64) NOT NULL, -- identifier of the trip being booked
    seat_number character varying(16), -- assigned seat number (if applicable)
    booking_time timestamp with time zone NOT NULL, -- time when the booking was made
    status character varying(32) NOT NULL, -- e.g., Confirmed, Cancelled, Pending Payment
    fare numeric(10, 2) NOT NULL, -- price paid for the booking
    payment_transaction_id character varying(128), -- reference to the payment transaction
    special_requests text, -- any special requests from the passenger
    PRIMARY KEY (booking_id)
)

[User] For each passenger, show their full name and the total amount they have spent on completed bookings.

[Assistant]
SELECT p.first_name, p.last_name, SUM(b.fare) AS total_spent
FROM transportation.passengers p
JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
WHERE b.status = 'Completed'
GROUP BY p.passenger_id, p.first_name, p.last_name;

[User] Can you also include the number of completed bookings for each passenger?

[Assistant]
SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS completed_bookings, SUM(b.fare) AS total_spent
FROM transportation.passengers p
JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
WHERE b.status = 'Completed'
GROUP BY p.passenger_id, p.first_name, p.last_name;

[User] Only include passengers who have spent more than 300 in total.

[Assistant]
SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS completed_bookings, SUM(b.fare) AS total_spent
FROM transportation.passengers p
JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
WHERE b.status = 'Completed'
GROUP BY p.passenger_id, p.first_name, p.last_name
HAVING SUM(b.fare) > 300;

[User] I got an error about missing the email, please add their email to the output.

[Assistant]
SELECT p.first_name, p.last_name, p.email, COUNT(b.booking_id) AS completed_bookings, SUM(b.fare) AS total_spent
FROM transportation.passengers p
JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
WHERE b.status = 'Completed'
GROUP BY p.passenger_id, p.first_name, p.last_name, p.email
HAVING SUM(b.fare) > 300;


System:
You are very professional for database language writing. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )
CREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )
CREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )
CREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )

[User] List all insurance products along with their product type and creation date.

[Assistant]
SELECT product_name, product_type, created_at
FROM insurance.insurance_products;