System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.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 up-to-date_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )

[User] List each product_type along with the most expensive active product in that type, showing product_type, product_id, product_name, and base_premium.

[Assistant]
SELECT product_type, product_id, product_name, base_premium
FROM (
  SELECT product_type, product_id, product_name, base_premium,
         ROW_NUMBER() OVER (PARTITION BY product_type ORDER BY base_premium DESC) AS rn
  FROM insurance.insurance_products
  WHERE is_active = true
) t
WHERE rn = 1;

[User] Actually, format the result to only include product types where the max base_premium exceeds 2000.

[Assistant]
SELECT product_type, product_id, product_name, base_premium
FROM (
  SELECT product_type, product_id, product_name, base_premium,
         ROW_NUMBER() OVER (PARTITION BY product_type ORDER BY base_premium DESC) AS rn
  FROM insurance.insurance_products
  WHERE is_active = true
) t
WHERE rn = 1
  AND base_premium > 2000;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 up-to-date_TIMESTAMP, -- timestamp of comment creation
    updated_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, -- timestamp of last comment edit
    PRIMARY KEY (comment_id)
)

[User] Count the number of comments that have been updated since they were first created.

[Assistant] SELECT COUNT(*) FROM social_media.comments WHERE updated_at > created_at;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )
CREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )
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 )
CREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )

[User] Which locations have received fuel logs greater than 300 liters in total? Please include the location name and city.

[Assistant]
SELECT l.name AS location_name, l.city, SUM(f.quantity) AS total_quantity
FROM transportation.fuel_logs f
JOIN transportation.locations l ON f.location_id = l.location_id
GROUP BY l.location_id, l.name, l.city
HAVING SUM(f.quantity) > 300;

[User] Can you also include the number of times fuel was logged at each location?

[Assistant]
SELECT l.name AS location_name, l.city, COUNT(f.fuel_log_id) AS log_count, SUM(f.quantity) AS total_quantity
FROM transportation.fuel_logs f
JOIN transportation.locations l ON f.location_id = l.location_id
GROUP BY l.location_id, l.name, l.city
HAVING SUM(f.quantity) > 300;

[User] Actually, could you restrict it to only locations that are in 'New York' city?

[Assistant]
SELECT l.name AS location_name, l.city, COUNT(f.fuel_log_id) AS log_count, SUM(f.quantity) AS total_quantity
FROM transportation.fuel_logs f
JOIN transportation.locations l ON f.location_id = l.location_id
WHERE l.city = 'New York'
GROUP BY l.location_id, l.name, l.city
HAVING SUM(f.quantity) > 300;

[User] I got an error about ambiguous column in GROUP BY, can you fix and show only the columns used in SELECT in the GROUP BY?

[Assistant]
SELECT l.name AS location_name, l.city, COUNT(f.fuel_log_id) AS log_count, SUM(f.quantity) AS total_quantity
FROM transportation.fuel_logs f
JOIN transportation.locations l ON f.location_id = l.location_id
WHERE l.city = 'New York'
GROUP BY l.name, l.city
HAVING SUM(f.quantity) > 300;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL inspect (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )

[User] How many beneficiaries are there for each relationship type?

[Assistant]
SELECT relationship,
       COUNT(*) AS beneficiary_count
FROM insurance.policy_beneficiaries
GROUP BY relationship;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.room_types ( room_type_id text, attribute_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )

[User] List all room types along with the name of the attribute they belong to. Show the room type name, attribute name, and base rate.

[Assistant] SELECT t1.type_name, t2.attribute_name, t1.base_rate FROM hospitality_technology.room_types AS t1 JOIN hospitality_technology.properties AS t2 ON t1.attribute_id = t2.attribute_id


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.claims ( claim_id text, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )

[User] What is the total estimated_loss and average settlement_amount for all claims with status 'Approved'?

[Assistant]
SELECT SUM(estimated_loss) AS total_estimated_loss,
       AVG(settlement_amount) AS average_settlement
FROM insurance.claims
WHERE status = 'Approved';


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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] List the appointment ID, subject, location, and lawyer ID for all appointments where there is at least one other appointment with the same location and lawyer assigned.

[Assistant] SELECT appointment_id, subject, location, lawyer_id FROM legal_services.appointments AS a1 WHERE EXISTS (SELECT 1 FROM legal_services.appointments AS a2 WHERE a1.location = a2.location AND a1.lawyer_id = a2.lawyer_id AND a1.appointment_id != a2.appointment_id);

[User] Actually, can you also include the start time for these appointments?

[Assistant] SELECT appointment_id, subject, location, lawyer_id, start_time FROM legal_services.appointments AS a1 WHERE EXISTS (SELECT 1 FROM legal_services.appointments AS a2 WHERE a1.location = a2.location AND a1.lawyer_id = a2.lawyer_id AND a1.appointment_id != a2.appointment_id);

[User] Now, only show appointments with status 'Scheduled' and sort them by creation timestamp descending.

[Assistant] SELECT appointment_id, subject, location, lawyer_id, start_time FROM legal_services.appointments AS a1 WHERE a1.status = 'Scheduled' AND EXISTS (SELECT 1 FROM legal_services.appointments AS a2 WHERE a1.location = a2.location AND a1.lawyer_id = a2.lawyer_id AND a1.appointment_id != a2.appointment_id) ORDER BY a1.created_at DESC;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )
CREATE TABLE financial_services.accounts ( account_id.text, customer_id.text, account_number.text, account_type.text, balance.numeric, currency.text, opened_date.date, status.text, interest_rate.numeric, last_updated_at.timestamp )
CREATE TABLE financial_services.transactions ( transaction_id text, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )
CREATE TABLE financial_services.securities ( security_id.text, 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.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) )
CREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )
CREATE TABLE financial_services.loans ( loan_id text, account_id text, loan_type text, principal_amount numeric, up-to-date_principal_balance numeric, interest_rate numeric, term_months integer, origination_date date, maturity_date date, monthly_payment numeric, collateral_description text, status text )

[User] Show me for each loan_type, the total number of loans and the average principal_amount, along with the average account balance for the accounts associated with those loans.

[Assistant]
SELECT l.loan_type, COUNT(l.loan_id) AS loan_count, AVG(l.principal_amount) AS avg_principal_amount, AVG(a.balance) AS avg_account_balance
FROM financial_services.loans l
JOIN financial_services.accounts a ON l.account_id = a.account_id
GROUP BY l.loan_type;

[User] Can you only include loan types with more than 3 loans?

[Assistant]
SELECT l.loan_type, COUNT(l.loan_id) AS loan_count, AVG(l.principal_amount) AS avg_principal_amount, AVG(a.balance) AS avg_account_balance
FROM financial_services.loans l
JOIN financial_services.accounts a ON l.account_id = a.account_id
GROUP BY l.loan_type
HAVING COUNT(l.loan_id) > 3;

[User] And sort the result by avg_principal_amount in descending order.

[Assistant]
SELECT l.loan_type, COUNT(l.loan_id) AS loan_count, AVG(l.principal_amount) AS avg_principal_amount, AVG(a.balance) AS avg_account_balance
FROM financial_services.loans l
JOIN financial_services.accounts a ON l.account_id = a.account_id
GROUP BY l.loan_type
HAVING COUNT(l.loan_id) > 3
ORDER BY avg_principal_amount DESC;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )
CREATE TABLE trading_platform.wallets (
    wallet_id character varying(64) NOT NULL,  -- unique identifier for the wallet
    user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet
    address character varying(128) NOT NULL, -- address of the wallet
    private_key text NOT NULL, -- private key of the wallet
    created_at timestamp NOT NULL, -- time when the wallet was created
    PRIMARY KEY (wallet_id)
)
CREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )
CREATE TABLE trading_platform.assets (
    asset_id character varying(64) NOT NULL,  -- unique identifier for the asset
    name character varying(128) NOT NULL, -- name of the asset
    symbol character varying(32) NOT NULL, -- symbol of the asset
    type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)
    PRIMARY KEY (asset_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.text, name.text, description.text, url.text )
CREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_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.kyc_audit ( kyc_audit_id.text, user_id.text, status.text, reviewed_at.timestamp )
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, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )

[User] How many distinct ports have been used by peers in the system?

[Assistant]
SELECT COUNT(DISTINCT port) AS distinct_port_count
FROM trading_platform.peers;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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.credential_transfers ( transfer_id.text, credential_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] Find the usernames of users who have deployed contracts and list the address of the contract they deployed.

[Assistant] SELECT T1.username, T3.address FROM web3.users AS T1 JOIN web3.wallets AS T2 ON T1.user_id = T2.user_id JOIN web3.contracts AS T3 ON T2.address = T3.deployer_address;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.claims (
    claim_id character varying(64) NOT NULL, -- unique identifier for the claim
    policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)
    customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)
    incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim
    reported_date timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, -- date the claim was reported
    description text NOT NULL, -- detailed description of the incident and claim
    estimated_loss numeric(15, 2), -- initial estimated cost of the loss
    status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled
    settlement_amount numeric(15, 2), -- final amount paid out
    settlement_date date,
    claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)
    police_report_number character varying(100),
    PRIMARY KEY (claim_id)
)

[User] List each claim_handler_id along with the number of claims they've handled and the total settlement_amount they've paid out.

[Assistant]
SELECT claim_handler_id,
       COUNT(*) AS total_claims,
       SUM(settlement_amount) AS total_settlement
FROM insurance.claims
GROUP BY claim_handler_id;

[User] In addition, include the claim_id of the single claim with the highest settlement_amount for each handler.

[Assistant]
SELECT ag.claim_handler_id,
       ag.total_claims,
       ag.total_settlement,
       c_max.claim_id               AS max_settlement_claim_id,
       c_max.settlement_amount      AS max_settlement_amount
FROM (
  SELECT claim_handler_id,
         COUNT(*) AS total_claims,
         SUM(settlement_amount) AS total_settlement
  FROM insurance.claims
  GROUP BY claim_handler_id
) ag
JOIN insurance.claims c_max
  ON c_max.claim_handler_id = ag.claim_handler_id
  AND c_max.settlement_amount = (
    SELECT MAX(settlement_amount)
    FROM insurance.claims
    WHERE claim_handler_id = ag.claim_handler_id
  );

[User] Only include handlers who have managed at least 3 claims and have a non-null claim_handler_id.

[Assistant]
SELECT ag.claim_handler_id,
       ag.total_claims,
       ag.total_settlement,
       c_max.claim_id               AS max_settlement_claim_id,
       c_max.settlement_amount      AS max_settlement_amount
FROM (
  SELECT claim_handler_id,
         COUNT(*) AS total_claims,
         SUM(settlement_amount) AS total_settlement
  FROM insurance.claims
  GROUP BY claim_handler_id
  HAVING COUNT(*) >= 3
     AND claim_handler_id IS NOT NULL
) ag
JOIN insurance.claims c_max
  ON c_max.claim_handler_id = ag.claim_handler_id
  AND c_max.settlement_amount = (
    SELECT MAX(settlement_amount)
    FROM insurance.claims
    WHERE claim_handler_id = ag.claim_handler_id
  );

[User] Finally, sort the results by total_settlement in descending order.

[Assistant]
SELECT ag.claim_handler_id,
       ag.total_claims,
       ag.total_settlement,
       c_max.claim_id               AS max_settlement_claim_id,
       c_max.settlement_amount      AS max_settlement_amount
FROM (
  SELECT claim_handler_id,
         COUNT(*) AS total_claims,
         SUM(settlement_amount) AS total_settlement
  FROM insurance.claims
  GROUP BY claim_handler_id
  HAVING COUNT(*) >= 3
     AND claim_handler_id IS NOT NULL
) ag
JOIN insurance.claims c_max
  ON c_max.claim_handler_id = ag.claim_handler_id
  AND c_max.settlement_amount = (
    SELECT MAX(settlement_amount)
    FROM insurance.claims
    WHERE claim_handler_id = ag.claim_handler_id
  )
ORDER BY ag.total_settlement DESC;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )

[User] List the first and last names, email, and phone number of all customers whose status is not 'Active'.

[Assistant]
SELECT first_name, last_name, email, phone_number
FROM insurance.customers
WHERE status <> 'Active';

[User] Now, only show those who live in the state of California.

[Assistant]
SELECT first_name, last_name, email, phone_number
FROM insurance.customers
WHERE status <> 'Active' AND state = 'CA';

[User] I got some records where the phone_number is missing. Please exclude customers with a NULL phone number.

[Assistant]
SELECT first_name, last_name, email, phone_number
FROM insurance.customers
WHERE status <> 'Active'
  AND state = 'CA'
  AND phone_number IS NOT NULL;

[User] Finally, sort the results by last_name ascending and limit the output to 20 records.

[Assistant]
SELECT first_name, last_name, email, phone_number
FROM insurance.customers
WHERE status <> 'Active'
  AND state = 'CA'
  AND phone_number IS NOT NULL
ORDER BY last_name ASC
LIMIT 20;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, PRIMARY KEY (comment_id) )
CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT inspect_like_target inspect (post_id IS NOT NULL OR comment_id IS NOT NULL) )
CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )
CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )
CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, read_at timestamp, 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 up-to-date_TIMESTAMP, PRIMARY KEY (setting_id) )

[User] How many likes were given to comments in June 2024?

[Assistant]
SELECT COUNT(*) AS comment_likes_count
FROM social_media.likes
WHERE comment_id IS NOT NULL
  AND DATE_TRUNC('month', created_at) = '2024-06-01';


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )

[User] Show me the developer(s) who were founded in the most recent year.

[Assistant] SELECT name, country, founded_year FROM gaming_technology.developers WHERE founded_year = (SELECT MAX(founded_year) FROM gaming_technology.developers);

[User] Can you also add their official website?

[Assistant] SELECT name, country, founded_year, website FROM gaming_technology.developers WHERE founded_year = (SELECT MAX(founded_year) FROM gaming_technology.developers);

[User] Only include developers whose country is not null.

[Assistant] SELECT name, country, founded_year, website FROM gaming_technology.developers WHERE founded_year = (SELECT MAX(founded_year) FROM gaming_technology.developers) AND country IS NOT NULL;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )

[User] I want to see pairs of customers living in the same state but having different risk profiles. Show their customer_ids, states, and risk_profiles.

[Assistant] SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile;

[User] Exclude any pairs where either customer has a null phone_number.

[Assistant] SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL;

[User] Ensure each pair appears only once, without reversed duplicates.

[Assistant] SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL AND a.customer_id < b.customer_id;

[User] Finally, only include states that have more than 3 customers in total.

[Assistant] SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL AND a.customer_id < b.customer_id AND a.state IN (SELECT state FROM financial_services.customers GROUP BY state HAVING COUNT(*) > 3);


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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) )
CREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )

[User] Show me the total number of trades and the sum of total_amount for each status in the trades table.

[Assistant]
SELECT
  t.status,
  COUNT(t.trade_id) AS trade_count,
  SUM(t.total_amount) AS total_amount_by_status
FROM financial_services.trades t
GROUP BY t.status;

[User] Now, only include statuses where trade_count is greater than 100, and restrict to trades executed in the last 30 days.

[Assistant]
SELECT
  t.status,
  COUNT(t.trade_id) AS trade_count,
  SUM(t.total_amount) AS total_amount_by_status
FROM financial_services.trades t
WHERE t.trade_timestamp >= up-to-date_DATE - INTERVAL '30 days'
GROUP BY t.status
HAVING COUNT(t.trade_id) > 100;

[User] Exclude any statuses where the sum of commission is null or less than 1000.

[Assistant]
SELECT
  t.status,
  COUNT(t.trade_id) AS trade_count,
  SUM(t.total_amount) AS total_amount_by_status,
  SUM(t.commission) AS total_commission
FROM financial_services.trades t
WHERE t.trade_timestamp >= up-to-date_DATE - INTERVAL '30 days'
GROUP BY t.status
HAVING COUNT(t.trade_id) > 100
   AND SUM(t.commission) >= 1000;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 )
CREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )
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 )
CREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )

[User] For each vehicle that appears in both the maintenance logs and fuel logs tables, calculate the total maintenance cost and the total fuel cost. Display the vehicle ID and these two total costs.

[Assistant] SELECT T1.vehicle_id ,  SUM(T1.cost) AS total_maintenance_cost ,  SUM(T2.total_cost) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id  =  T2.vehicle_id GROUP BY T1.vehicle_id

[User] Now, only include vehicles where the total maintenance cost exceeds 5000.

[Assistant] SELECT T1.vehicle_id ,  SUM(T1.cost) AS total_maintenance_cost ,  SUM(T2.total_cost) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id  =  T2.vehicle_id GROUP BY T1.vehicle_id HAVING SUM(T1.cost)  >  5000

[User] Also, only consider fuel log entries from the year 2023 for the fuel cost calculation.

[Assistant] SELECT T1.vehicle_id ,  SUM(T1.cost) AS total_maintenance_cost ,  SUM(CASE WHEN STRFTIME('%Y', T2.log_timestamp) = '2023' THEN T2.total_cost ELSE 0 END) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id  =  T2.vehicle_id GROUP BY T1.vehicle_id HAVING SUM(T1.cost)  >  5000


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )
CREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )
CREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )
CREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )

[User] Retrieve the first_name, last_name, and email of all passengers who have never made a booking.

[Assistant]
SELECT
  p.first_name,
  p.last_name,
  p.email
FROM transportation.passengers p
LEFT JOIN transportation.bookings b
  ON p.passenger_id = b.passenger_id
WHERE b.booking_id IS NULL;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.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 up-to-date_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )
CREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )
CREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )

[User] Which insurance products have had a policy issued in 2024, and what is the name and type of those products? Show the product_id, product_name, and product_type.

[Assistant]
SELECT DISTINCT ip.product_id, ip.product_name, ip.product_type
FROM insurance.policies p
JOIN insurance.insurance_products ip ON p.product_id = ip.product_id
WHERE p.start_date >= '2024-01-01';

[User] Can you also include the base premium of each product and only show policies where the base premium is greater than 2500?

[Assistant]
SELECT DISTINCT ip.product_id, ip.product_name, ip.product_type, ip.base_premium
FROM insurance.policies p
JOIN insurance.insurance_products ip ON p.product_id = ip.product_id
WHERE p.start_date >= '2024-01-01'
  AND ip.base_premium > 2500;

[User] Actually, I want to see only products that are up-to-dately active, and order the results by base premium descending.

[Assistant]
SELECT DISTINCT ip.product_id, ip.product_name, ip.product_type, ip.base_premium
FROM insurance.policies p
JOIN insurance.insurance_products ip ON p.product_id = ip.product_id
WHERE p.start_date >= '2024-01-01'
  AND ip.base_premium > 2500
  AND ip.is_active = true
ORDER BY ip.base_premium DESC;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )
CREATE TABLE insurance.claims ( claim_id text, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )

[User] How many unique customers are there in the system?

[Assistant]
SELECT COUNT(DISTINCT customer_id) AS unique_customer_count
FROM insurance.customers;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )
CREATE TABLE social_media.hashtags ( hashtag_id text, tag_name text, created_at timestamp )
CREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )

[User] How many group chats have been created since January 1, 2024?

[Assistant]
SELECT COUNT(*) AS group_chat_count
FROM social_media.conversations
WHERE is_group_chat = TRUE
  AND created_at >= '2024-01-01';


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )
CREATE TABLE insurance.policies (
    policy_id character varying(64) NOT NULL, -- unique identifier for the policy
    customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)
    product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)
    agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)
    policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number
    start_date date NOT NULL, -- date the policy coverage begins
    end_date date NOT NULL, -- date the policy coverage ends
    premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term
    coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered
    deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in
    status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending
    issued_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, -- when the policy was issued
    cancellation_date date,
    cancellation_reason text,
    PRIMARY KEY (policy_id)
)
CREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )
CREATE TABLE insurance.agents ( agent_id.text, first_name.text, last_name.text, agency_name.text, license_number.text, license_state.text, contact_email.text, contact_phone.text, hire_date.date, termination_date.date, status.text, commission_rate.numeric, manager_id.text )
CREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )

[User] List all policies sold by agents licensed in Texas. Include the policy number, policy start date, and the agent's first and last name.

[Assistant] SELECT T1.policy_number, T1.start_date, T2.first_name, T2.last_name FROM insurance.policies AS T1 JOIN insurance.agents AS T2 ON T1.agent_id = T2.agent_id WHERE T2.license_state = 'TX'

[User] Can you also include the policy status and only show policies that are 'Cancelled'?

[Assistant] SELECT T1.policy_number, T1.start_date, T2.first_name, T2.last_name, T1.status FROM insurance.policies AS T1 JOIN insurance.agents AS T2 ON T1.agent_id = T2.agent_id WHERE T2.license_state = 'TX' AND T1.status = 'Cancelled'

[User] For those cancelled policies, please add the customer's full name.

[Assistant] SELECT T1.policy_number, T1.start_date, T2.first_name AS agent_first_name, T2.last_name AS agent_last_name, T1.status, T3.first_name AS customer_first_name, T3.last_name AS customer_last_name FROM insurance.policies AS T1 JOIN insurance.agents AS T2 ON T1.agent_id = T2.agent_id JOIN insurance.customers AS T3 ON T1.customer_id = T3.customer_id WHERE T2.license_state = 'TX' AND T1.status = 'Cancelled'


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )
CREATE TABLE transportation.locations ( location_id character varying(64) NOT NULL, name character varying(255) NOT NULL, type character varying(64) NOT NULL, address_line1 character varying(255), city character varying(128), state_province character varying(128), postal_code character varying(32), country character varying(64) NOT NULL, latitude numeric(9, 6), longitude numeric(9, 6), timezone character varying(64), PRIMARY KEY (location_id) )
CREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )
CREATE TABLE transportation.passengers ( passenger_id character varying(64) NOT NULL, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32) UNIQUE, date_of_birth date, loyalty_program_id character varying(64), created_at timestamp with time zone NOT NULL, PRIMARY KEY (passenger_id) )
CREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )

[User] For each trip, list the trip_id, the passenger_count from trips, the number of bookings for that trip, and the average fare of those bookings.

[Assistant]
SELECT t.trip_id, t.passenger_count, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare
FROM transportation.trips t
LEFT JOIN transportation.bookings b ON t.trip_id = b.trip_id
GROUP BY t.trip_id, t.passenger_count;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )

[User] Find agents whose commission_rate is higher than their manager's commission_rate. Show agent_id, agent first_name, agent last_name, commission_rate, manager_id, and the manager's commission_rate.

[Assistant]
SELECT a.agent_id,
       a.first_name,
       a.last_name,
       a.commission_rate,
       a.manager_id,
       m.commission_rate AS manager_commission_rate
  FROM insurance.agents a
  JOIN insurance.agents m
    ON a.manager_id = m.agent_id
 WHERE a.commission_rate > m.commission_rate;

[User] Now restrict to agents hired before January 1, 2023.

[Assistant]
SELECT a.agent_id,
       a.first_name,
       a.last_name,
       a.commission_rate,
       a.manager_id,
       m.commission_rate AS manager_commission_rate
  FROM insurance.agents a
  JOIN insurance.agents m
    ON a.manager_id = m.agent_id
 WHERE a.commission_rate > m.commission_rate
   AND a.hire_date < '2023-01-01';


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.rooms (
    room_id character varying(64) NOT NULL,  -- unique identifier for the room
    attribute_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)
    up-to-date_condition text, -- notes on room condition
    last_cleaned_at timestamp with time zone, -- timestamp of last cleaning
    PRIMARY KEY (room_id),
    FOREIGN KEY (attribute_id) REFERENCES hospitality_technology.properties(attribute_id),
    FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)
)
CREATE TABLE hospitality_technology.visitors ( visitor_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 up-to-date_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT up-to-date_timestamp, PRIMARY KEY (visitor_id) )
CREATE TABLE hospitality_technology.reservations ( reservation_id text, attribute_id text, visitor_id text, room_id text, room_type_id text, inspect_in_date date, inspect_out_date date, actual_inspect_in_ts timestamp, actual_inspect_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )
CREATE TABLE hospitality_technology.staff (
    staff_id character varying(64) NOT NULL,  -- unique identifier for the staff member
    attribute_id character varying(64) NOT NULL, -- FK to properties table (primary attribute)
    first_name character varying(100) NOT NULL,
    last_name character varying(100) NOT NULL,
    position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge
    work_email character varying(255) UNIQUE, -- staff member's work email
    work_phone character varying(30),
    hire_date date NOT NULL,
    termination_date date, -- date employment ended (if applicable)
    is_active boolean NOT NULL DEFAULT true, -- up-to-dately employed flag
    access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)
    manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)
    created_at timestamp with time zone NOT NULL DEFAULT up-to-date_timestamp,
    PRIMARY KEY (staff_id),
    FOREIGN KEY (attribute_id) REFERENCES hospitality_technology.properties(attribute_id),
    FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)
)
CREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, visitor_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )
CREATE TABLE hospitality_technology.payments (
    payment_id character varying(64) NOT NULL,  -- unique identifier for the payment transaction
    reservation_id character varying(64), -- FK to reservations (if payment is for a stay)
    visitor_id character varying(64) NOT NULL, -- FK to visitors (who paid)
    bill_id character varying(64), -- FK to bills/invoices this payment applies to
    amount numeric(12,2) NOT NULL, -- amount of the payment
    currency_code character varying(3) NOT NULL, -- ISO currency code (e.g., USD, EUR)
    payment_method character varying(50) NOT NULL, -- e.g., CreditCard, Cash, BankTransfer, Points, Voucher
    card_type character varying(50), -- e.g., Visa, MasterCard, Amex (if CC)
    card_last_four character varying(4), -- last 4 digits of CC (if CC)
    transaction_ref character varying(128), -- reference ID from payment gateway or processor
    payment_timestamp timestamp with time zone NOT NULL DEFAULT up-to-date_timestamp, -- when the payment occurred
    status character varying(50) NOT NULL, -- e.g., Pending, Succeeded, Failed, Refunded, Disputed
    staff_id_processed character varying(64), -- FK to staff (who processed the payment)
    notes text, -- notes about the payment
    PRIMARY KEY (payment_id),
    FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),
    FOREIGN KEY (visitor_id) REFERENCES hospitality_technology.visitors(visitor_id),
    FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id)
)
CREATE TABLE hospitality_technology.reviews ( review_id text PRIMARY KEY, attribute_id text, reservation_id text, visitor_id text, rating_overall int, rating_cleanliness int, rating_service int, rating_location int, rating_value int, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )

[User] List all visitors who placed a service order with a total price greater than 200, including their first name, last name, and the order ID.

[Assistant] SELECT T1.first_name, T1.last_name, T2.order_id FROM hospitality_technology.visitors AS T1 JOIN hospitality_technology.service_orders AS T2 ON T1.visitor_id = T2.visitor_id WHERE T2.total_price > 200;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) )
CREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, PRIMARY KEY (invoice_id) )

[User] Find all invoices that are up-to-dately overdue. Include the invoice number, due date, total amount, and the client's name.

[Assistant] SELECT i.invoice_number, i.due_date, i.total_amount, c.first_name, c.last_name FROM legal_services.invoices i JOIN legal_services.clients c ON i.client_id = c.client_id WHERE i.status = 'Overdue' AND i.due_date < up-to-date_DATE;

[User] Only show overdue invoices for clients from the company 'Acme Corporation'.

[Assistant] SELECT i.invoice_number, i.due_date, i.total_amount, c.first_name, c.last_name FROM legal_services.invoices i JOIN legal_services.clients c ON i.client_id = c.client_id WHERE i.status = 'Overdue' AND i.due_date < up-to-date_DATE AND c.company_name = 'Acme Corporation';

[User] Sort the results by the due date, from oldest to newest.

[Assistant] SELECT i.invoice_number, i.due_date, i.total_amount, c.first_name, c.last_name FROM legal_services.invoices i JOIN legal_services.clients c ON i.client_id = c.client_id WHERE i.status = 'Overdue' AND i.due_date < up-to-date_DATE AND c.company_name = 'Acme Corporation' ORDER BY i.due_date ASC;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )

[User] Show me all players who have unlocked achievements, and for each, also list the total number of achievements they've unlocked.

[Assistant] SELECT player_id, COUNT(*) AS achievements_unlocked FROM gaming_technology.player_achievements GROUP BY player_id;

[User] Now limit it to only players who have unlocked more than 5 achievements.

[Assistant] SELECT player_id, COUNT(*) AS achievements_unlocked FROM gaming_technology.player_achievements GROUP BY player_id HAVING COUNT(*) > 5;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )
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] I want to see the number of 'buy' and 'sell' orders for each asset, along with the asset_id.

[Assistant] SELECT asset_id, order_type, COUNT(*) AS order_count FROM trading_platform.orders GROUP BY asset_id, order_type;

[User] Can you also show the average price for 'buy' and 'sell' orders for each asset?

[Assistant] SELECT asset_id, order_type, COUNT(*) AS order_count, AVG(price) AS avg_price FROM trading_platform.orders GROUP BY asset_id, order_type;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE credential_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the credential credential_name character varying(100) NOT NULL, -- the credential's name credential_symbol character varying(100) NOT NULL, -- the credential's symbol credential_address character varying(100) NOT NULL, -- the credential's address chain text, -- the chain that the credential resides price double precision, -- the up-to-date price of the credential price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original credential price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original credential price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original credential price in 7 days highest_price_24h double precision, -- the highest price of the credential in 24 hours lowest_price_24h double precision,  -- the lowest price of the credential in 24 hours market_cap double precision, -- the market cap of the credential market_cap_rank bigint, -- the rank of the credential market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the credential both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the credential trend_rank biging, -- the trending rank of the credential, value 1 expresses the most popular credential. ,PRIMARY KEY (coin_id, chain) )
CREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 credentials in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original credential price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original credential price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original credential price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative credential_num bigint, -- total credential number in the narrative ,PRIMARY KEY (narrative) )
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_credential character varying(100), -- the credential 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) )

[User] Show me the top 3 narratives by trend rank, along with their top 3 credentials and 7-day price change percentage.

[Assistant] SELECT n.narrative, n.top_3_coins, n.price_change_percentage_7d FROM narrative_info n ORDER BY n.trend_rank ASC LIMIT 3;

[User] Can you also include the 24-hour trading volume for these narratives?

[Assistant] SELECT n.narrative, n.top_3_coins, n.price_change_percentage_7d, n.volume_24h FROM narrative_info n ORDER BY n.trend_rank ASC LIMIT 3;

[User] Actually, I only want narratives with a 7-day price change percentage above 10%.

[Assistant] SELECT n.narrative, n.top_3_coins, n.price_change_percentage_7d, n.volume_24h FROM narrative_info n WHERE n.price_change_percentage_7d > 10 ORDER BY n.trend_rank ASC LIMIT 3;

[User] Now order the results by 24-hour trading volume in descending order.

[Assistant] SELECT n.narrative, n.top_3_coins, n.price_change_percentage_7d, n.volume_24h FROM narrative_info n WHERE n.price_change_percentage_7d > 10 ORDER BY n.volume_24h DESC LIMIT 3;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.patients ( 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.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) )
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 up-to-date_timestamp, PRIMARY KEY (prescription_id) )

[User] List the full names of patients who have ever been prescribed a medication manufactured by 'Novartis'.

[Assistant]
SELECT DISTINCT p.first_name, p.last_name
FROM healthcare.patients p
JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id
JOIN healthcare.medications m ON pr.medication_id = m.medication_id
WHERE m.manufacturer = 'Novartis';

[User] Please also show the medication name for each result.

[Assistant]
SELECT DISTINCT p.first_name, p.last_name, m.medication_name
FROM healthcare.patients p
JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id
JOIN healthcare.medications m ON pr.medication_id = m.medication_id
WHERE m.manufacturer = 'Novartis';


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.properties (
    attribute_id character varying(64) NOT NULL,  -- unique identifier for the attribute (hotel, resort, etc.)
    attribute_name character varying(255) NOT NULL, -- name of the attribute
    address_line1 character varying(255) NOT NULL, -- primary address line
    address_line2 character varying(255), -- secondary address line
    city character varying(100) NOT NULL, -- city
    state_province character varying(100), -- state or province
    postal_code character varying(20) NOT NULL, -- zip or postal code
    country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)
    phone_number character varying(30), -- main contact phone
    email_address character varying(255), -- main contact email
    attribute_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel
    star_rating numeric(2,1), -- star rating (e.g., 4.5)
    timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)
    manager_staff_id character varying(64), -- FK to staff table for the general manager
    created_at timestamp with time zone NOT NULL DEFAULT up-to-date_timestamp, -- record creation time
    updated_at timestamp with time zone NOT NULL DEFAULT up-to-date_timestamp, -- record last update time
    PRIMARY KEY (attribute_id)
)
CREATE TABLE hospitality_technology.rooms ( room_id.text, attribute_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, up-to-date_condition.text, last_cleaned_at.timestamp )
CREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, attribute_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )
CREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, attribute_id text, visitor_id text, room_id text, room_type_id text, inspect_in_date date, inspect_out_date date, actual_inspect_in_ts timestamp, actual_inspect_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )
CREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, attribute_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, attribute_id.text, service_name.text, description.text, category.text, price.numeric, unit.text, is_available.boolean, department.text )

[User] List all room types that have at least one service in the 'Spa' category, including the room type name, attribute name, and service name.

[Assistant]
SELECT DISTINCT rt.type_name, p.attribute_name, s.service_name
FROM hospitality_technology.room_types AS rt
JOIN hospitality_technology.properties AS p ON rt.attribute_id = p.attribute_id
JOIN hospitality_technology.services AS s ON rt.attribute_id = s.attribute_id
WHERE s.category = 'Spa';

[User] Actually, only show room types with a base_rate above 200.

[Assistant]
SELECT DISTINCT rt.type_name, p.attribute_name, s.service_name
FROM hospitality_technology.room_types AS rt
JOIN hospitality_technology.properties AS p ON rt.attribute_id = p.attribute_id
JOIN hospitality_technology.services AS s ON rt.attribute_id = s.attribute_id
WHERE s.category = 'Spa'
  AND rt.base_rate > 200;

[User] Also sort the results by base_rate descending and limit to 10.

[Assistant]
SELECT DISTINCT rt.type_name, p.attribute_name, s.service_name
FROM hospitality_technology.room_types AS rt
JOIN hospitality_technology.properties AS p ON rt.attribute_id = p.attribute_id
JOIN hospitality_technology.services AS s ON rt.attribute_id = s.attribute_id
WHERE s.category = 'Spa'
  AND rt.base_rate > 200
ORDER BY rt.base_rate DESC
LIMIT 10;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )
CREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, credential_id.text, contract_type.text, amount.text, pk.integer )
CREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )
CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )
CREATE TABLE nft_collections (
    blockchain varchar NOT NULL, -- blockchain fields for the functionType  in contract
    contract_address varchar NOT NULL, -- Contract address(with bloom filter)
    name varchar NOT NULL, -- name fields for the functionType  in contract
    symbol varchar NOT NULL, -- symbol fields for the functionType  in contract
    deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType  in contract
    deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType  in contract
    erc_type varchar NOT NULL, -- The type of credential
    owner varchar NOT NULL, -- owner fields for the functionType  in contract
    traits varchar NOT NULL, -- traits fields for the functionType  in contract
    description varchar NOT NULL, -- description fields for the functionType  in contract
    slug varchar NOT NULL, -- slug fields for the functionType  in contract
    media_info varchar NOT NULL, -- media_info fields for the functionType  in contract
    image_url varchar NOT NULL, -- image_url fields for the functionType  in contract
    banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType  in contract
    updated_at bigint NOT NULL, -- updated_at fields for the functionType  in contract
    banner varchar NOT NULL, -- banner fields for the functionType  in contract
    credential_count bigint NOT NULL, -- credential_count fields for the functionType  in contract
    floor_price varchar NOT NULL, -- floor_price fields for the functionType  in contract
    floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType  in contract
    floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType  in contract
    pk integer NOT NULL  -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))
)
CREATE TABLE credential_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )
CREATE TABLE credential_info (
    block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
    block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
    tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
    tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
    tick varchar NOT NULL, -- credential tick
    max_supply decimal(38,0) NOT NULL, -- Max supply
    lim decimal(38,0) NOT NULL, -- Limit of each mint
    wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint
    dec integer NOT NULL, -- Decimal for minimum divie
    creator varchar(42) NOT NULL  -- Address originating the inscription (matches from_address in transactions table)
)
CREATE TABLE credential_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )
CREATE TABLE credential_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE credential_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )

[User] For each NFT collection deployed on Ethereum, count the number of distinct wallets that have ever held any credential from that collection.

[Assistant]
SELECT
  nc.contract_address,
  nc.name,
  COUNT(DISTINCT nh.wallet_address) AS holder_count
FROM nft_collections nc
JOIN nft_holder_historical nh
  ON nc.contract_address = nh.contract_address
WHERE nc.blockchain = 'Ethereum'
GROUP BY nc.contract_address, nc.name;

[User] Include each collection's credential_count and floor_price from nft_collections.

[Assistant]
SELECT
  nc.contract_address,
  nc.name,
  nc.credential_count,
  nc.floor_price,
  COUNT(DISTINCT nh.wallet_address) AS holder_count
FROM nft_collections nc
JOIN nft_holder_historical nh
  ON nc.contract_address = nh.contract_address
WHERE nc.blockchain = 'Ethereum'
GROUP BY
  nc.contract_address,
  nc.name,
  nc.credential_count,
  nc.floor_price;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )
CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, PRIMARY KEY (comment_id) )
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 up-to-date_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )
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 up-to-date_TIMESTAMP, PRIMARY KEY (hashtag_id) )
CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )
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 up-to-date_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )
CREATE TABLE social_media.conversation_participants ( participant_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, joined_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, last_read_at timestamp, PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) )
CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT up-to-date_TIMESTAMP, read_at timestamp, 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 up-to-date_TIMESTAMP, PRIMARY KEY (setting_id) )

[User] List all users who commented on posts tagged with hashtag 'spring', showing user_id, comment_id, content, and tag_name.

[Assistant]
SELECT c.user_id, c.comment_id, c.content, h.tag_name
FROM social_media.comments c
JOIN social_media.post_hashtags ph ON c.post_id = ph.post_id
JOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id
WHERE h.tag_name = 'spring';

[User] Actually, only include comments from the last 7 days.

[Assistant]
SELECT c.user_id, c.comment_id, c.content, h.tag_name
FROM social_media.comments c
JOIN social_media.post_hashtags ph ON c.post_id = ph.post_id
JOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id
WHERE h.tag_name = 'spring'
  AND c.created_at >= up-to-date_TIMESTAMP - INTERVAL '7 days';

[User] Also only include users who have email notifications enabled.

[Assistant]
SELECT c.user_id, c.comment_id, c.content, h.tag_name
FROM social_media.comments c
JOIN social_media.post_hashtags ph ON c.post_id = ph.post_id
JOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id
JOIN social_media.user_settings us ON c.user_id = us.user_id
WHERE h.tag_name = 'spring'
  AND c.created_at >= up-to-date_TIMESTAMP - INTERVAL '7 days'
  AND us.email_notifications_enabled = TRUE;

[User] Order the results by comment created_at descending and limit to 50.

[Assistant]
SELECT c.user_id, c.comment_id, c.content, h.tag_name
FROM social_media.comments c
JOIN social_media.post_hashtags ph ON c.post_id = ph.post_id
JOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id
JOIN social_media.user_settings us ON c.user_id = us.user_id
WHERE h.tag_name = 'spring'
  AND c.created_at >= up-to-date_TIMESTAMP - INTERVAL '7 days'
  AND us.email_notifications_enabled = TRUE
ORDER BY c.created_at DESC
LIMIT 50;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )

[User] Provide a count of transactions grouped by their status.

[Assistant] SELECT status, COUNT(*) FROM web3.transactions GROUP BY status;

[User] Now, only show the statuses that have more than 50 transactions.

[Assistant] SELECT status, COUNT(*) FROM web3.transactions GROUP BY status HAVING COUNT(*) > 50;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )

[User] I want to find the average time it takes for a notification to be marked as read, calculated for each user. Please show the user ID and the average read time in seconds, considering only notifications that have been read.

[Assistant] SELECT user_id, AVG(EXTRACT(EPOCH FROM (read_at - sent_at))) AS average_read_time_seconds FROM notifications WHERE read_at IS NOT NULL GROUP BY user_id ORDER BY average_read_time_seconds;

[User] The previous query only included users who have read at least one notification. Please modify it to include all users who have received at least one notification, showing NULL for the average read time if they haven't read any.

[Assistant] SELECT user_id, AVG(CASE WHEN read_at IS NOT NULL THEN EXTRACT(EPOCH FROM (read_at - sent_at)) END) AS average_read_time_seconds FROM notifications GROUP BY user_id ORDER BY average_read_time_seconds;

[User] Now, filter this list to only include users whose average read time is greater than 600 seconds (10 minutes).

[Assistant] SELECT user_id, AVG(CASE WHEN read_at IS NOT NULL THEN EXTRACT(EPOCH FROM (read_at - sent_at)) END) AS average_read_time_seconds FROM notifications GROUP BY user_id HAVING AVG(CASE WHEN read_at IS NOT NULL THEN EXTRACT(EPOCH FROM (read_at - sent_at)) END) > 600 ORDER BY average_read_time_seconds;

[User] Also, include the total number of notifications sent to each of these users in the result, and order the list by average read time in descending order.

[Assistant] SELECT user_id, AVG(CASE WHEN read_at IS NOT NULL THEN EXTRACT(EPOCH FROM (read_at - sent_at)) END) AS average_read_time_seconds, COUNT(*) AS total_notifications FROM notifications GROUP BY user_id HAVING AVG(CASE WHEN read_at IS NOT NULL THEN EXTRACT(EPOCH FROM (read_at - sent_at)) END) > 600 ORDER BY average_read_time_seconds DESC;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.citizens (
    citizen_id character varying(64) NOT NULL,  -- unique identifier for the citizen
    national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number
    first_name character varying(100) NOT NULL,
    last_name character varying(100) NOT NULL,
    date_of_birth date NOT NULL,
    gender character varying(20),
    primary_address text NOT NULL, -- full primary residential address
    contact_email character varying(128) UNIQUE,
    contact_phone character varying(32),
    registration_date timestamp NOT NULL, -- when the citizen profile was created
    is_verified boolean DEFAULT false, -- whether identity has been officially verified
    PRIMARY KEY (citizen_id)
)
CREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )
CREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )
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 )
CREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )
CREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )

[User] How many citizens are marked as not verified?

[Assistant] SELECT COUNT(*) FROM government_services.citizens WHERE is_verified = FALSE;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )
CREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )
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 )
CREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )
CREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )
CREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )

[User] Could you show me all scheduled appointments including appointment_id, scheduled_start_time, the citizen's full name, and the location name?

[Assistant]
SELECT a.appointment_id,
       a.scheduled_start_time,
       c.first_name || ' ' || c.last_name AS citizen_name,
       l.location_name
FROM government_services.appointments a
JOIN government_services.citizens c ON a.citizen_id = c.citizen_id
JOIN government_services.service_locations l ON a.location_id = l.location_id
WHERE a.status = 'Scheduled';

[User] Actually, include only those appointments scheduled after June 1, 2024.

[Assistant]
SELECT a.appointment_id,
       a.scheduled_start_time,
       c.first_name || ' ' || c.last_name AS citizen_name,
       l.location_name
FROM government_services.appointments a
JOIN government_services.citizens c ON a.citizen_id = c.citizen_id
JOIN government_services.service_locations l ON a.location_id = l.location_id
WHERE a.status = 'Scheduled'
  AND a.scheduled_start_time > '2024-06-01';


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT up-to-date_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )
CREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT up-to-date_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )
CREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT up-to-date_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )

[User] For each player, can you list the total number of achievements they have unlocked and the total number of sessions they have played, along with their username?

[Assistant]
SELECT p.player_id, p.username, COUNT(DISTINCT pa.achievement_id) AS total_achievements, COUNT(DISTINCT gs.session_id) AS total_sessions
FROM gaming_technology.players p
LEFT JOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id
LEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id
GROUP BY p.player_id, p.username;

[User] Can you add the player's country_code to the results and only show players who have unlocked at least two achievements?

[Assistant]
SELECT p.player_id, p.username, p.country_code,
       COUNT(DISTINCT pa.achievement_id) AS total_achievements, COUNT(DISTINCT gs.session_id) AS total_sessions
FROM gaming_technology.players p
LEFT JOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id
LEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id
GROUP BY p.player_id, p.username, p.country_code
HAVING COUNT(DISTINCT pa.achievement_id) >= 2;

[User] Now, I want to see the earliest session start_time for each player as well.

[Assistant]
SELECT p.player_id, p.username, p.country_code,
       COUNT(DISTINCT pa.achievement_id) AS total_achievements,
       COUNT(DISTINCT gs.session_id) AS total_sessions,
       MIN(gs.start_time) AS earliest_session
FROM gaming_technology.players p
LEFT JOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id
LEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id
GROUP BY p.player_id, p.username, p.country_code
HAVING COUNT(DISTINCT pa.achievement_id) >= 2;

[User] Can you also sort the results by earliest_session ascending and then by username ascending?

[Assistant]
SELECT p.player_id, p.username, p.country_code,
       COUNT(DISTINCT pa.achievement_id) AS total_achievements,
       COUNT(DISTINCT gs.session_id) AS total_sessions,
       MIN(gs.start_time) AS earliest_session
FROM gaming_technology.players p
LEFT JOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id
LEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id
GROUP BY p.player_id, p.username, p.country_code
HAVING COUNT(DISTINCT pa.achievement_id) >= 2
ORDER BY earliest_session ASC, p.username ASC;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.credential_transfers ( transfer_id character varying(64) NOT NULL, credential_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128) NOT NULL, value numeric(38,14) NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (transfer_id) )

[User] Find all addresses that have both received and sent transfers of the same credential. List the address and the credential ID for each such instance.

[Assistant] SELECT DISTINCT t1.to_address AS address, t1.credential_id FROM web3.credential_transfers t1 JOIN web3.credential_transfers t2 ON t1.to_address = t2.from_address AND t1.credential_id = t2.credential_id;


System:
I think you have deep knowledge in database programming language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.diagnoses ( diagnosis_id.text, 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 )

[User] Find all unique diagnosis codes that are associated with more than one doctor, and show how many doctors are linked to each code.

[Assistant] SELECT diagnosis_code, COUNT(DISTINCT doctor_id) AS doctor_count FROM healthcare.diagnoses GROUP BY diagnosis_code HAVING COUNT(DISTINCT doctor_id) > 1;

[User] Also, show only codes that are used after January 1st, 2023.

[Assistant] SELECT diagnosis_code, COUNT(DISTINCT doctor_id) AS doctor_count FROM healthcare.diagnoses WHERE diagnosis_date > '2023-01-01' GROUP BY diagnosis_code HAVING COUNT(DISTINCT doctor_id) > 1;