System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
CREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )

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

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

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )

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

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

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

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

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

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


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

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

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

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE trading_platform.trades (
    trade_id character varying(64) NOT NULL,  -- unique identifier for the trade
    order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade
    buyer_id character varying(64) NOT NULL, -- identifier of the buyer
    seller_id character varying(64) NOT NULL, -- identifier of the seller
    asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
    quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade
    price numeric(38,14) NOT NULL, -- price per unit of the asset
    traded_at timestamp NOT NULL, -- time when the trade was executed
    PRIMARY KEY (trade_id)
)
CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )
CREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )
CREATE TABLE trading_platform.metadata (
    metadata_id character varying(64) NOT NULL,  -- unique identifier for the metadata
    asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with
    key character varying(128) NOT NULL, -- key of the metadata
    value text NOT NULL, -- value of the metadata
    PRIMARY KEY (metadata_id)
)
CREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )
CREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )

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

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

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.fuel_logs (
    fuel_log_id character varying(64) NOT NULL,  -- unique identifier for the fuel log entry
    vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled
    trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred
    log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred
    fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)
    quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)
    unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)
    cost_per_unit numeric(8, 4), -- price per unit of fuel
    total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase
    odometer_reading integer, -- vehicle mileage at time of fueling
    location_id character varying(64), -- identifier of the fueling station/location
    PRIMARY KEY (fuel_log_id)
)

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users (
    user_id character varying(64) NOT NULL,  -- unique identifier for the user
    username character varying(128) NOT NULL, -- username of the user
    email character varying(128) NOT NULL, -- email address of the user
    password_hash text NOT NULL, -- hashed password of the user
    created_at timestamp NOT NULL, -- time when the user account was created
    PRIMARY KEY (user_id)
)
CREATE TABLE trading_platform.orders (
    order_id character varying(64) NOT NULL,  -- unique identifier for the order
    user_id character varying(64) NOT NULL, -- identifier of the user placing the order
    wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order
    asset_id character varying(64) NOT NULL, -- identifier of the asset being traded
    order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)
    quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order
    price numeric(38,14) NOT NULL, -- price per unit of the asset
    status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)
    created_at timestamp NOT NULL, -- time when the order was created
    PRIMARY KEY (order_id)
)
CREATE TABLE trading_platform.utxos (
    utxo_id character varying(64) NOT NULL,  -- unique identifier for the UTXO
    transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO
    output_index integer NOT NULL, -- index of the output in the transaction
    address character varying(128) NOT NULL, -- address that can spend the UTXO
    amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO
    spent boolean NOT NULL, -- whether the UTXO has been spent
    PRIMARY KEY (utxo_id)
)
CREATE TABLE trading_platform.dapps (
    dapp_id character varying(64) NOT NULL,  -- unique identifier for the DApp
    name character varying(128) NOT NULL, -- name of the DApp
    description text NOT NULL, -- description of the DApp
    url character varying(256) NOT NULL, -- URL of the DApp
    PRIMARY KEY (dapp_id)
)
CREATE TABLE trading_platform.peers (
    peer_id character varying(64) NOT NULL,  -- unique identifier for the peer
    ip_address character varying(15) NOT NULL, -- IP address of the peer
    port integer NOT NULL, -- port number of the peer
    last_seen timestamp NOT NULL, -- last time the peer was active
    PRIMARY KEY (peer_id)
)
CREATE TABLE trading_platform.logs (
    log_id character varying(64) NOT NULL,  -- unique identifier for the log entry
    user_id character varying(64), -- identifier of the user associated with the log entry
    action character varying(128) NOT NULL, -- action performed
    details text NOT NULL, -- details of the action
    logged_at timestamp NOT NULL, -- time when the log entry was created
    PRIMARY KEY (log_id)
)

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )
CREATE TABLE healthcare.insurance_plans (
    plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan
    plan_name character varying(200) NOT NULL, -- name of the insurance plan
    insurance_provider character varying(100) NOT NULL, -- name of the insurance company
    plan_type character varying(50), -- e.g., PPO, HMO, EPO
    contact_phone character varying(20), -- provider contact number
    website character varying(255), -- provider website
    PRIMARY KEY (plan_id)
)

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

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

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.notifications ( notification_id.text, citizen_id.text, application_id.text, message_subject.text, message_body.text, channel.text, sent_at.timestamp, status.text, related_entity_type.text, related_entity_id.text )

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.contracts ( contract_id.text, address.text, abi.text, bytecode.text, deployer_address.text, deployed_at.timestamp, network_id.text, status.text )
CREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )
CREATE TABLE web3.token_transfers ( transfer_id.text, token_id.text, from_address.text, to_address.text, value.numeric, transaction_id.text, log_index.integer )
CREATE TABLE web3.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )
CREATE TABLE web3.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE manufacturing.materials (
    material_id character varying(64) NOT NULL,  -- unique identifier for the material
    material_name character varying(128) NOT NULL, -- common name (e.g., Titanium Alloy Grade 5, Carbon Fiber Prepreg)
    specification character varying(255), -- specification standard (e.g., AMS 4928)
    description text, -- detailed description of properties
    density_kg_m3 numeric(10, 4), -- density in kg per cubic meter
    tensile_strength_mpa integer, -- tensile strength in Megapascals
    PRIMARY KEY (material_id)
)
CREATE TABLE manufacturing.assembly_steps (
    step_id character varying(64) NOT NULL, -- unique identifier for an assembly step/task
    line_id character varying(64) NOT NULL, -- FK to the assembly line where this step occurs
    step_number integer NOT NULL, -- sequence number of the step on the line
    step_name character varying(255) NOT NULL, -- name of the task (e.g., Install Wing Root Fairing)
    description text, -- detailed instructions or description
    standard_duration_hours numeric(8,2), -- estimated time to complete the step
    required_skill_level character varying(50), -- skill level needed (e.g., 'Mechanic II', 'Electrician I')
    workstation character varying(100), -- specific workstation or area for the step
    PRIMARY KEY (step_id)
)

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE trading_platform.users (
    user_id character varying(64) NOT NULL,  -- unique identifier for the user
    username character varying(128) NOT NULL, -- username of the user
    email character varying(128) NOT NULL, -- email address of the user
    password_hash text NOT NULL, -- hashed password of the user
    created_at timestamp NOT NULL, -- time when the user account was created
    PRIMARY KEY (user_id)
)
CREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )
CREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )
CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )

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

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

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

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

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )

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

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

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

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


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

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

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

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

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

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

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

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

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


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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )
CREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )
CREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )
CREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )
CREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )
CREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )
CREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )
CREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )

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

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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )
CREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )

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

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

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

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

[User] Sort the output by latest_update ascending.

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


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

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

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

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

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

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

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

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

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


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

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

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


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
  "CREATE TABLE token_dexpool_info (",
    "pair_address character varying(512) NOT NULL, -- the id of dexpool",
    "token_name character varying(100) NOT NULL, -- the name of the token in the dexpool",
    "token_symbol character varying(100) NOT NULL, -- the token's symbol",
    "chain text, -- the chain that the dexpool resides",
    "price double precision, -- the current price of the token",
    "price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour",
    "price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours",
    "price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours",
    "makers_24h double precision, -- the makers of the dex pool in 24 hours",
    "volume_24h double precision, -- the trade volume of the dex pool in 24 hours",
    "liquidity double precision, -- the liquidity of the dex pool",
    "market_cap double precision, -- the market cap of the token",
    "trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token.",
    ",PRIMARY KEY (pair_address, chain);"

[User] List the top 3 tokens by liquidity on BSC and show their token symbols, prices, market cap, and liquidity.

[Assistant]
SELECT token_symbol, price, market_cap, liquidity
FROM token_dexpool_info
WHERE chain = 'BSC'
ORDER BY liquidity DESC
LIMIT 3;

[User] Could you also include the 24-hour price change percentage and 24-hour trading volume for these tokens?

[Assistant]
SELECT token_symbol, price, market_cap, liquidity, price_change_percentage_24h, volume_24h
FROM token_dexpool_info
WHERE chain = 'BSC'
ORDER BY liquidity DESC
LIMIT 3;

[User] Show only those tokens with positive 6-hour and 24-hour price change percentages.

[Assistant]
SELECT token_symbol, price, market_cap, liquidity, price_change_percentage_24h, volume_24h
FROM token_dexpool_info
WHERE chain = 'BSC'
  AND price_change_percentage_6h > 0
  AND price_change_percentage_24h > 0
ORDER BY liquidity DESC
LIMIT 3;

[User] Now include the makers_24h for each result.

[Assistant]
SELECT token_symbol, price, market_cap, liquidity, price_change_percentage_24h, volume_24h, makers_24h
FROM token_dexpool_info
WHERE chain = 'BSC'
  AND price_change_percentage_6h > 0
  AND price_change_percentage_24h > 0
ORDER BY liquidity DESC
LIMIT 3;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.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 )
CREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )
CREATE TABLE insurance.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 PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )
CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )

[User] List all active agents with the number of open claims they've handled and the average settlement amount for their closed claims. Include agent_id, first_name, last_name, open_claims_count, and avg_settlement_closed.

[Assistant]
SELECT a.agent_id, a.first_name, a.last_name,
       COUNT(CASE WHEN c.status = 'Open' THEN 1 END) AS open_claims_count,
       AVG(CASE WHEN c.status = 'Closed' THEN c.settlement_amount END) AS avg_settlement_closed
FROM insurance.agents a
LEFT JOIN insurance.claims c ON a.agent_id = c.claim_handler_id
WHERE a.status = 'Active'
GROUP BY a.agent_id, a.first_name, a.last_name;

[User] Actually, only include agents with more than 5 open claims, and also include their total number of closed claims as closed_claims_count.

[Assistant]
SELECT a.agent_id, a.first_name, a.last_name,
       COUNT(CASE WHEN c.status = 'Open' THEN 1 END) AS open_claims_count,
       SUM(CASE WHEN c.status = 'Closed' THEN 1 END) AS closed_claims_count,
       AVG(CASE WHEN c.status = 'Closed' THEN c.settlement_amount END) AS avg_settlement_closed
FROM insurance.agents a
LEFT JOIN insurance.claims c ON a.agent_id = c.claim_handler_id
WHERE a.status = 'Active'
GROUP BY a.agent_id, a.first_name, a.last_name
HAVING COUNT(CASE WHEN c.status = 'Open' THEN 1 END) > 5;

[User] Also, sort the results by avg_settlement_closed descending and limit to the top 10 agents.

[Assistant]
SELECT a.agent_id, a.first_name, a.last_name,
       COUNT(CASE WHEN c.status = 'Open' THEN 1 END) AS open_claims_count,
       SUM(CASE WHEN c.status = 'Closed' THEN 1 END) AS closed_claims_count,
       AVG(CASE WHEN c.status = 'Closed' THEN c.settlement_amount END) AS avg_settlement_closed
FROM insurance.agents a
LEFT JOIN insurance.claims c ON a.agent_id = c.claim_handler_id
WHERE a.status = 'Active'
GROUP BY a.agent_id, a.first_name, a.last_name
HAVING COUNT(CASE WHEN c.status = 'Open' THEN 1 END) > 5
ORDER BY avg_settlement_closed DESC
LIMIT 10;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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 text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
CREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )
CREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )
CREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )
CREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text )
CREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )
CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )
CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )
CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )
CREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )

[User] List all users who currently have a 'pending' KYC status, showing their user ID and username.

[Assistant] SELECT u.user_id, u.username FROM users u JOIN kyc_audit k ON u.user_id = k.user_id WHERE k.status = 'pending';


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE gaming_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 CURRENT_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.games ( game_id uuid NOT NULL DEFAULT gen_random_uuid(), title character varying(200) NOT NULL, developer_id uuid NOT NULL, publisher_id uuid, genre character varying(100), release_date date, description text, platform character varying(50) NOT NULL, engine character varying(100), website character varying(255), PRIMARY KEY (game_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 CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )

[User] Retrieve the title and release_date of all games on the 'PC' platform.

[Assistant]
SELECT title, release_date
FROM gaming_technology.games
WHERE platform = 'PC';

[User] Now exclude any games released before 2018.

[Assistant]
SELECT title, release_date
FROM gaming_technology.games
WHERE platform = 'PC'
  AND release_date >= '2018-01-01';

[User] Also sort the results by release_date in ascending order.

[Assistant]
SELECT title, release_date
FROM gaming_technology.games
WHERE platform = 'PC'
  AND release_date >= '2018-01-01'
ORDER BY release_date ASC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )
CREATE TABLE hospitality_technology.reviews ( review_id text PRIMARY KEY, property_id text, reservation_id text, guest_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 each property and the number of public reviews it has received.

[Assistant]
SELECT p.property_id, p.property_name, COUNT(r.review_id) AS public_review_count
FROM hospitality_technology.properties p
LEFT JOIN hospitality_technology.reviews r ON p.property_id = r.property_id AND r.is_public = TRUE
GROUP BY p.property_id, p.property_name;

[User] I only want properties which have received at least 10 public reviews.

[Assistant]
SELECT p.property_id, p.property_name, COUNT(r.review_id) AS public_review_count
FROM hospitality_technology.properties p
LEFT JOIN hospitality_technology.reviews r ON p.property_id = r.property_id AND r.is_public = TRUE
GROUP BY p.property_id, p.property_name
HAVING COUNT(r.review_id) >= 10;

[User] Additionally, please provide the average overall rating for each of these properties.

[Assistant]
SELECT p.property_id, p.property_name, COUNT(r.review_id) AS public_review_count, AVG(r.rating_overall) AS avg_public_rating
FROM hospitality_technology.properties p
LEFT JOIN hospitality_technology.reviews r ON p.property_id = r.property_id AND r.is_public = TRUE
GROUP BY p.property_id, p.property_name
HAVING COUNT(r.review_id) >= 10;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )
CREATE TABLE web3.tokens (
    token_id character varying(64) NOT NULL,  -- unique identifier for the token
    contract_address character varying(128) NOT NULL, -- address of the token contract
    token_name character varying(128) NOT NULL, -- name of the token
    token_symbol character varying(32) NOT NULL, -- symbol of the token
    decimals integer NOT NULL, -- number of decimals for the token
    total_supply numeric(38,14) NOT NULL, -- total supply of the token
    PRIMARY KEY (token_id)
)
CREATE TABLE web3.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 web3.users (
    user_id character varying(64) NOT NULL,  -- unique identifier for the user
    username character varying(128) NOT NULL, -- username of the user
    email character varying(128) NOT NULL, -- email address of the user
    password_hash text NOT NULL, -- hashed password of the user
    created_at timestamp NOT NULL, -- time when the user account was created
    PRIMARY KEY (user_id)
)

[User] List the username, registration date, and the creation date of the first wallet created by each user who owns at least one wallet.

[Assistant] SELECT u.username, u.created_at AS registration_date, MIN(w.created_at) AS first_wallet_creation_date FROM web3.users AS u JOIN web3.wallets AS w ON u.user_id = w.user_id GROUP BY u.user_id, u.username, u.created_at;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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) )
CREATE TABLE web3.token_transfers (
    transfer_id character varying(64) NOT NULL,  -- unique identifier for the transfer
    token_id character varying(64) NOT NULL, -- identifier of the token being transferred
    from_address character varying(128) NOT NULL, -- address of the sender
    to_address character varying(128) NOT NULL, -- address of the receiver
    value numeric(38,14) NOT NULL, -- amount of tokens transferred
    transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer
    log_index integer NOT NULL, -- index of the transfer log in the transaction
    PRIMARY KEY (transfer_id)
)

[User] Show the top 5 transactions with the highest number of token transfers, along with their Ethereum value. Include transaction_id, token_transfer_count, and ether_value.

[Assistant]
SELECT
  tt.transaction_id,
  COUNT(tt.transfer_id) AS token_transfer_count,
  t.value AS ether_value
FROM web3.token_transfers tt
JOIN web3.transactions t
  ON tt.transaction_id = t.transaction_id
GROUP BY
  tt.transaction_id,
  t.value
ORDER BY token_transfer_count DESC
LIMIT 5;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.vehicles (
    vehicle_id character varying(64) NOT NULL,  -- unique identifier for the vehicle
    license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate
    vin character varying(17) UNIQUE, -- vehicle identification number
    make character varying(64) NOT NULL, -- manufacturer of the vehicle
    model character varying(64) NOT NULL, -- model of the vehicle
    year integer NOT NULL, -- manufacturing year
    type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)
    capacity integer, -- passenger or cargo capacity
    fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen
    status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned
    depot_id character varying(64), -- identifier of the home depot/base
    acquisition_date date, -- date the vehicle was acquired
    PRIMARY KEY (vehicle_id)
)
CREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )
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 PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, 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 )

[User] List all maintenance logs for vehicles acquired in the year 2023. Include log ID, vehicle make, model, service date, and cost.

[Assistant] SELECT ml.log_id, v.make, v.model, ml.service_date, ml.cost FROM transportation.maintenance_logs AS ml JOIN transportation.vehicles AS v ON ml.vehicle_id = v.vehicle_id WHERE EXTRACT(YEAR FROM v.acquisition_date) = 2023;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE web3.contracts (
    contract_id character varying(64) NOT NULL,  -- unique identifier for the contract
    address character varying(128) NOT NULL, -- address of the deployed contract
    abi text NOT NULL, -- application binary interface of the contract
    bytecode text NOT NULL, -- bytecode of the contract
    deployer_address character varying(128) NOT NULL, -- address of the deployer
    deployed_at timestamp NOT NULL, -- time when the contract was deployed
    network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed
    status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)
    PRIMARY KEY (contract_id)
)
CREATE TABLE web3.events (
    event_id character varying(64) NOT NULL,  -- unique identifier for the event
    contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event
    event_name character varying(128) NOT NULL, -- name of the event
    data text NOT NULL, -- data payload of the event
    emitted_at timestamp NOT NULL, -- time when the event was emitted
    transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event
    log_index integer NOT NULL, -- index of the event log in the transaction
    PRIMARY KEY (event_id)
)
CREATE TABLE web3.transactions (
    transaction_id character varying(64) NOT NULL,  -- unique identifier for the transaction
    from_address character varying(128) NOT NULL, -- address of the sender
    to_address character varying(128), -- address of the receiver (can be null for contract deployment)
    value numeric(38,14) NOT NULL, -- value transferred
    gas_used integer NOT NULL, -- amount of gas used by the transaction
    gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction
    block_number integer NOT NULL, -- block number containing the transaction
    timestamp timestamp NOT NULL, -- time when the transaction was mined
    input_data text, -- input data of the transaction (can be null)
    status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)
    nonce integer NOT NULL, -- nonce of the sender at the time of the transaction
    PRIMARY KEY (transaction_id)
)
CREATE TABLE web3.tokens (
    token_id character varying(64) NOT NULL,  -- unique identifier for the token
    contract_address character varying(128) NOT NULL, -- address of the token contract
    token_name character varying(128) NOT NULL, -- name of the token
    token_symbol character varying(32) NOT NULL, -- symbol of the token
    decimals integer NOT NULL, -- number of decimals for the token
    total_supply numeric(38,14) NOT NULL, -- total supply of the token
    PRIMARY KEY (token_id)
)
CREATE TABLE web3.token_transfers (
    transfer_id character varying(64) NOT NULL,  -- unique identifier for the transfer
    token_id character varying(64) NOT NULL, -- identifier of the token being transferred
    from_address character varying(128) NOT NULL, -- address of the sender
    to_address character varying(128) NOT NULL, -- address of the receiver
    value numeric(38,14) NOT NULL, -- amount of tokens transferred
    transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer
    log_index integer NOT NULL, -- index of the transfer log in the transaction
    PRIMARY KEY (transfer_id)
)
CREATE TABLE web3.users (
    user_id character varying(64) NOT NULL,  -- unique identifier for the user
    username character varying(128) NOT NULL, -- username of the user
    email character varying(128) NOT NULL, -- email address of the user
    password_hash text NOT NULL, -- hashed password of the user
    created_at timestamp NOT NULL, -- time when the user account was created
    PRIMARY KEY (user_id)
)

[User] Show each contract's address along with the total number of events it has emitted and the total number of transactions sent to it.

[Assistant]
SELECT
  c.address,
  COUNT(e.event_id) AS event_count,
  COUNT(t.transaction_id) AS tx_count
FROM web3.contracts c
LEFT JOIN web3.events e
  ON c.contract_id = e.contract_id
LEFT JOIN web3.transactions t
  ON c.address = t.to_address
GROUP BY c.address;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE 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.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )
CREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )
CREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )

[User] Show me the conversation ID and creation time for group chats that have received at least one message.

[Assistant] SELECT DISTINCT T1.conversation_id, T1.created_at FROM social_media.conversations AS T1 INNER JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE;

[User] Only show those created in 2024.

[Assistant] SELECT DISTINCT T1.conversation_id, T1.created_at FROM social_media.conversations AS T1 INNER JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01';


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, 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.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 )

[User] Show the full name and job title of employees whose job title includes 'Manager' and who do not have a listed manager.

[Assistant] SELECT first_name, last_name, job_title FROM government_services.employees WHERE job_title LIKE '%Manager%' AND manager_employee_id IS NULL;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )

[User] List the top 5 tokens by total USD inflow and outflow, including net flow, sorted by net flow descending.

[Assistant]
WITH inflow AS (
  SELECT token_symbol, chain, SUM(usd_value) AS usd_in
  FROM smart_money_token_inflow
  WHERE type = 1
  GROUP BY token_symbol, chain
),
outflow AS (
  SELECT token_symbol, chain, SUM(usd_value) AS usd_out
  FROM smart_money_token_inflow
  WHERE type = 2
  GROUP BY token_symbol, chain
),
net_flow AS (
  SELECT
    i.token_symbol,
    i.chain,
    COALESCE(i.usd_in, 0) AS usd_in,
    COALESCE(o.usd_out, 0) AS usd_out,
    COALESCE(i.usd_in, 0) - COALESCE(o.usd_out, 0) AS net_flow
  FROM inflow i
  LEFT JOIN outflow o
    ON i.token_symbol = o.token_symbol
   AND i.chain = o.chain
)
SELECT token_symbol, chain, usd_in, usd_out, net_flow
FROM net_flow
ORDER BY net_flow DESC
LIMIT 5;

[User] Now filter the results to only include tokens where net flow is positive.

[Assistant]
WITH inflow AS (
  SELECT token_symbol, chain, SUM(usd_value) AS usd_in
  FROM smart_money_token_inflow
  WHERE type = 1
  GROUP BY token_symbol, chain
),
outflow AS (
  SELECT token_symbol, chain, SUM(usd_value) AS usd_out
  FROM smart_money_token_inflow
  WHERE type = 2
  GROUP BY token_symbol, chain
),
net_flow AS (
  SELECT
    i.token_symbol,
    i.chain,
    COALESCE(i.usd_in, 0) AS usd_in,
    COALESCE(o.usd_out, 0) AS usd_out,
    COALESCE(i.usd_in, 0) - COALESCE(o.usd_out, 0) AS net_flow
  FROM inflow i
  LEFT JOIN outflow o
    ON i.token_symbol = o.token_symbol
   AND i.chain = o.chain
)
SELECT token_symbol, chain, usd_in, usd_out, net_flow
FROM net_flow
WHERE net_flow > 0
ORDER BY net_flow DESC
LIMIT 5;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, 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.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )

[User] Retrieve all notifications with status 'failed' along with the citizen's full name and contact_phone for those notifications that occurred in the past 30 days.

[Assistant]
SELECT n.notification_id,
       n.sent_at,
       n.status,
       c.first_name || ' ' || c.last_name AS full_name,
       c.contact_phone
FROM government_services.notifications n
JOIN government_services.citizens c
  ON n.citizen_id = c.citizen_id
WHERE n.status = 'failed'
  AND n.sent_at >= NOW() - INTERVAL '30 days';


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )
CREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )
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.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] Show each passenger's first_name, last_name, and the total number of bookings they have made.

[Assistant]
SELECT p.passenger_id, p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count
FROM transportation.passengers p
LEFT JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
GROUP BY p.passenger_id, p.first_name, p.last_name;

[User] Filter to only include passengers who have made more than 3 bookings.

[Assistant]
SELECT p.passenger_id, p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count
FROM transportation.passengers p
LEFT JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
GROUP BY p.passenger_id, p.first_name, p.last_name
HAVING COUNT(b.booking_id) > 3;

[User] Also include the average fare for these passengers and order by booking_count descending.

[Assistant]
SELECT p.passenger_id, p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare
FROM transportation.passengers p
LEFT JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
GROUP BY p.passenger_id, p.first_name, p.last_name
HAVING COUNT(b.booking_id) > 3
ORDER BY booking_count DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )
CREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status 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 )
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] For each passenger, compute the count of bookings and average fare for bookings made in February 2024.

[Assistant]
SELECT p.passenger_id, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare
FROM transportation.passengers p
JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
WHERE b.booking_time >= '2024-02-01' AND b.booking_time < '2024-03-01'
GROUP BY p.passenger_id;

[User] I need to see the passengers' first and last names instead of IDs and only include those with an average fare greater than 75.

[Assistant]
SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare
FROM transportation.passengers p
JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
WHERE b.booking_time >= '2024-02-01' AND b.booking_time < '2024-03-01'
GROUP BY p.first_name, p.last_name
HAVING AVG(b.fare) > 75;

[User] Also, order the results by booking_count descending and limit the output to the top 5 passengers.

[Assistant]
SELECT p.first_name, p.last_name, COUNT(b.booking_id) AS booking_count, AVG(b.fare) AS avg_fare
FROM transportation.passengers p
JOIN transportation.bookings b ON p.passenger_id = b.passenger_id
WHERE b.booking_time >= '2024-02-01' AND b.booking_time < '2024-03-01'
GROUP BY p.first_name, p.last_name
HAVING AVG(b.fare) > 75
ORDER BY booking_count DESC
LIMIT 5;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )
CREATE TABLE social_media.posts ( post_id text, 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 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 CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )
CREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )
CREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )
CREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )
CREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )

[User] I want a report of public posts with images in the last 30 days that shows post_id, content, author's username and email, and the count of likes, ordered by like count descending, limit to top 5.

[Assistant] SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 5;

[User] Actually, only include posts created by verified users.

[Assistant] SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' AND u.is_verified = true GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 5;

[User] Also, filter to posts within 50 kilometers of latitude 40.0 and longitude -74.0.

[Assistant] SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' AND u.is_verified = true AND p.location_lat BETWEEN 40.0 - 0.45 AND 40.0 + 0.45 AND p.location_lon BETWEEN -74.0 - 0.45 AND -74.0 + 0.45 GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 5;

[User] Finally, reduce the limit to top 3 posts only.

[Assistant] SELECT p.post_id, p.content, u.username, u.email, COUNT(l.like_id) AS like_count FROM social_media.posts p JOIN social_media.users u ON p.user_id = u.user_id LEFT JOIN social_media.likes l ON l.post_id = p.post_id WHERE p.visibility = 'public' AND p.media_type = 'image' AND p.created_at >= now() - interval '30 days' AND u.is_verified = true AND p.location_lat BETWEEN 40.0 - 0.45 AND 40.0 + 0.45 AND p.location_lon BETWEEN -74.0 - 0.45 AND -74.0 + 0.45 GROUP BY p.post_id, p.content, u.username, u.email ORDER BY like_count DESC LIMIT 3;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )

[User] For each account type and status, can you show the total number of accounts and their combined balance per currency?

[Assistant]
SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance
FROM financial_services.accounts
GROUP BY account_type, status, currency;

[User] Can you add the average interest rate for each group in the result?

[Assistant]
SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate
FROM financial_services.accounts
GROUP BY account_type, status, currency;

[User] Please filter the results to only include groups where the total_balance is above 50000.

[Assistant]
SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate
FROM financial_services.accounts
GROUP BY account_type, status, currency
HAVING SUM(balance) > 50000;

[User] Finally, sort the result by average_interest_rate in descending order.

[Assistant]
SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate
FROM financial_services.accounts
GROUP BY account_type, status, currency
HAVING SUM(balance) > 50000
ORDER BY average_interest_rate DESC;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )
CREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )
CREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )

[User] List all services, showing the service name, category, and the name of the property where it is offered.

[Assistant] SELECT T1.service_name, T1.category, T2.property_name FROM hospitality_technology.services AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id;

[User] Please filter the results to only include services that are currently available.

[Assistant] SELECT T1.service_name, T1.category, T2.property_name FROM hospitality_technology.services AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id WHERE T1.is_available = TRUE;

[User] Can you also include the star rating of the property and order the results by property star rating descending?

[Assistant] SELECT T1.service_name, T1.category, T2.property_name, T2.star_rating FROM hospitality_technology.services AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id WHERE T1.is_available = TRUE ORDER BY T2.star_rating DESC;


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

[User] List all tokens on the 'BSC' chain with a trend rank between 6 and 20 (inclusive), along with their symbol, price, and liquidity.

[Assistant]
SELECT t.token_symbol, t.price, d.liquidity
FROM token_basic_info t
JOIN token_dexpool_info d ON lower(t.token_symbol) = lower(d.token_symbol) AND t.chain = d.chain
WHERE t.chain = 'BSC' AND t.trend_rank BETWEEN 6 AND 20;

[User] Could you also show their 24-hour trading volume and only include tokens with a positive 24-hour price change percentage?

[Assistant]
SELECT t.token_symbol, t.price, d.liquidity, d.volume_24h
FROM token_basic_info t
JOIN token_dexpool_info d ON lower(t.token_symbol) = lower(d.token_symbol) AND t.chain = d.chain
WHERE t.chain = 'BSC' AND t.trend_rank BETWEEN 6 AND 20 AND t.price_change_percentage_24h > 0;

[User] Add the narrative for each token and order the results by liquidity descending, showing only the top 5.

[Assistant]
SELECT t.token_symbol, t.price, d.liquidity, d.volume_24h, t.narrative
FROM token_basic_info t
JOIN token_dexpool_info d ON lower(t.token_symbol) = lower(d.token_symbol) AND t.chain = d.chain
WHERE t.chain = 'BSC' AND t.trend_rank BETWEEN 6 AND 20 AND t.price_change_percentage_24h > 0
ORDER BY d.liquidity DESC
LIMIT 5;


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE insurance.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 )
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] Show all claims handled by agents who have uploaded at least one claim document. Include the claim_id, agent's uploaded document_id, and the incident date.

[Assistant]
SELECT c.claim_id, cd.document_id, c.incident_date
FROM insurance.claims c
JOIN insurance.claim_documents cd ON c.claim_handler_id = cd.uploaded_by
WHERE cd.claim_id = c.claim_id;

[User] Can you also include the file_name and the uploaded timestamp of each document?

[Assistant]
SELECT c.claim_id, cd.document_id, c.incident_date, cd.file_name, cd.uploaded_at
FROM insurance.claims c
JOIN insurance.claim_documents cd ON c.claim_handler_id = cd.uploaded_by
WHERE cd.claim_id = c.claim_id;

[User] Actually, only show records where the claim status is 'Open' and the document is of type 'POLICE_REPORT'.

[Assistant]
SELECT c.claim_id, cd.document_id, c.incident_date, cd.file_name, cd.uploaded_at
FROM insurance.claims c
JOIN insurance.claim_documents cd ON c.claim_handler_id = cd.uploaded_by
WHERE cd.claim_id = c.claim_id
  AND c.status = 'Open'
  AND cd.document_type = 'POLICE_REPORT';


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )
CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_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 text, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )

[User] How many comments were created in the month of March 2024?

[Assistant] SELECT COUNT(*) FROM social_media.comments WHERE created_at >= '2024-03-01' AND created_at < '2024-04-01';