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 text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )

[User] List all failed transactions where the gas_used is greater than 100,000, including the transaction_id and timestamp.

[Assistant] SELECT transaction_id, timestamp FROM web3.transactions WHERE status = 'failed' AND gas_used > 100000;

[User] Actually, I also need to see the from_address and the value of these transactions.

[Assistant] SELECT transaction_id, timestamp, from_address, value FROM web3.transactions WHERE status = 'failed' AND gas_used > 100000;

[User] There's a typo in your SQL, it should be '100000' not '100,000'. Also, sort the results by timestamp in descending order.

[Assistant] SELECT transaction_id, timestamp, from_address, value FROM web3.transactions WHERE status = 'failed' AND gas_used > 100000 ORDER BY timestamp DESC;

[User] Now filter to only show transactions from the last 30 days.

[Assistant] SELECT transaction_id, timestamp, from_address, value FROM web3.transactions WHERE status = 'failed' AND gas_used > 100000 AND timestamp >= NOW() - INTERVAL '30 days' ORDER BY timestamp 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 blockchain.transactions (
    transaction_id character varying(64) NOT NULL,  -- unique identifier for the transaction
    block_id character varying(64) NOT NULL, -- identifier of the block containing the transaction
    sender_address character varying(128) NOT NULL, -- address of the sender
    receiver_address character varying(128) NOT NULL, -- address of the receiver
    amount numeric(38,14) NOT NULL, -- amount transferred
    timestamp timestamp NOT NULL, -- time when the transaction was created
    signature text NOT NULL, -- digital signature of the transaction
    PRIMARY KEY (transaction_id)
)

[User] Show all transactions where the sender and receiver are different addresses but the transaction amount is exactly 1000. Include transaction_id, sender_address, receiver_address, and timestamp.

[Assistant]
SELECT transaction_id, sender_address, receiver_address, timestamp
FROM blockchain.transactions
WHERE sender_address <> receiver_address AND amount = 1000;


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) )

[User] Find all pairs of events that occurred in the same transaction but at different log indices, showing both event_ids, their event_names, the transaction_id, and each log_index.

[Assistant]
SELECT a.event_id AS event_id1,
       a.event_name AS event_name1,
       b.event_id AS event_id2,
       b.event_name AS event_name2,
       a.transaction_id,
       a.log_index AS log_index1,
       b.log_index AS log_index2
FROM web3.events a
JOIN web3.events b
  ON a.transaction_id = b.transaction_id
 AND a.log_index < b.log_index;


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,  -- unique identifier for the property (hotel, resort, etc.)
    property_name character varying(255) NOT NULL, -- name of the property
    address_line1 character varying(255) NOT NULL, -- primary address line
    address_line2 character varying(255), -- secondary address line
    city character varying(100) NOT NULL, -- city
    state_province character varying(100), -- state or province
    postal_code character varying(20) NOT NULL, -- zip or postal code
    country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)
    phone_number character varying(30), -- main contact phone
    email_address character varying(255), -- main contact email
    property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel
    star_rating numeric(2,1), -- star rating (e.g., 4.5)
    timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)
    manager_staff_id character varying(64), -- FK to staff table for the general manager
    created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time
    updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time
    PRIMARY KEY (property_id)
)
CREATE TABLE hospitality_technology.rooms (
    room_id character varying(64) NOT NULL,  -- unique identifier for the room
    property_id character varying(64) NOT NULL, -- FK to properties table
    room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')
    room_type_id character varying(64) NOT NULL, -- FK to room_types table
    floor integer, -- floor number the room is on
    status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance
    is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag
    features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)
    current_condition text, -- notes on room condition
    last_cleaned_at timestamp with time zone, -- timestamp of last cleaning
    PRIMARY KEY (room_id),
    FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),
    FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)
)
CREATE TABLE hospitality_technology.staff (
    staff_id character varying(64) NOT NULL,  -- unique identifier for the staff member
    property_id character varying(64) NOT NULL, -- FK to properties table (primary property)
    first_name character varying(100) NOT NULL,
    last_name character varying(100) NOT NULL,
    position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge
    work_email character varying(255) UNIQUE, -- staff member's work email
    work_phone character varying(30),
    hire_date date NOT NULL,
    termination_date date, -- date employment ended (if applicable)
    is_active boolean NOT NULL DEFAULT true, -- currently employed flag
    access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)
    manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)
    created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,
    PRIMARY KEY (staff_id),
    FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),
    FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)
)

[User] List all rooms with their numbers, property names, and the full name of the property manager.

[Assistant]
SELECT r.room_number, p.property_name, s.first_name || ' ' || s.last_name AS manager_full_name
FROM hospitality_technology.rooms r
JOIN hospitality_technology.properties p ON r.property_id = p.property_id
LEFT JOIN hospitality_technology.staff s ON p.manager_staff_id = s.staff_id;

[User] Only include rooms that are currently marked as 'Available' and return their floor numbers as well.

[Assistant]
SELECT r.room_number, r.floor, p.property_name, s.first_name || ' ' || s.last_name AS manager_full_name
FROM hospitality_technology.rooms r
JOIN hospitality_technology.properties p ON r.property_id = p.property_id
LEFT JOIN hospitality_technology.staff s ON p.manager_staff_id = s.staff_id
WHERE r.status = 'Available';

[User] Now, only show those rooms that are on floors above 2, and sort the results by property name and then by room number.

[Assistant]
SELECT r.room_number, r.floor, p.property_name, s.first_name || ' ' || s.last_name AS manager_full_name
FROM hospitality_technology.rooms r
JOIN hospitality_technology.properties p ON r.property_id = p.property_id
LEFT JOIN hospitality_technology.staff s ON p.manager_staff_id = s.staff_id
WHERE r.status = 'Available' AND r.floor > 2
ORDER BY p.property_name, r.room_number;


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.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )

[User] Show me the full names of partners and the full names of non-partner lawyers at the same firm.

[Assistant]
SELECT p.first_name || ' ' || p.last_name AS partner_full_name, np.first_name || ' ' || np.last_name AS lawyer_full_name
FROM legal_services.lawyers p
JOIN legal_services.lawyers np
  ON p.firm_id = np.firm_id
 AND p.is_partner = TRUE
 AND np.is_partner = FALSE;

[User] Actually, only include firms that have at least 3 non-partner lawyers.

[Assistant]
SELECT p.first_name || ' ' || p.last_name AS partner_full_name, np.first_name || ' ' || np.last_name AS lawyer_full_name
FROM legal_services.lawyers p
JOIN legal_services.lawyers np
  ON p.firm_id = np.firm_id
 AND p.is_partner = TRUE
 AND np.is_partner = FALSE
WHERE np.firm_id IN (
  SELECT firm_id
  FROM legal_services.lawyers
  WHERE is_partner = FALSE
  GROUP BY firm_id
  HAVING COUNT(*) >= 3
);

[User] Also only show non-partner lawyers who were hired after 2021-01-01.

[Assistant]
SELECT p.first_name || ' ' || p.last_name AS partner_full_name, np.first_name || ' ' || np.last_name AS lawyer_full_name
FROM legal_services.lawyers p
JOIN legal_services.lawyers np
  ON p.firm_id = np.firm_id
 AND p.is_partner = TRUE
 AND np.is_partner = FALSE
WHERE np.firm_id IN (
  SELECT firm_id
  FROM legal_services.lawyers
  WHERE is_partner = FALSE
  GROUP BY firm_id
  HAVING COUNT(*) >= 3
)
  AND np.hire_date > '2021-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 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] Retrieve all transactions where the total value of token transfers in that transaction exceeds the Ether value of the transaction itself. Include transaction_id, ether_value, and total_token_value.

[Assistant]
SELECT
  t.transaction_id,
  t.value AS ether_value,
  SUM(tt.value) AS total_token_value
FROM web3.transactions t
JOIN web3.token_transfers tt
  ON t.transaction_id = tt.transaction_id
GROUP BY
  t.transaction_id,
  t.value
HAVING
  SUM(tt.value) > t.value;


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.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )
CREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )
CREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )

[User] List the 10 most recent achievement unlocks across all players. Show player ID, achievement ID, and unlock timestamp.

[Assistant] SELECT player_id, achievement_id, unlocked_at FROM gaming_technology.player_achievements ORDER BY unlocked_at DESC LIMIT 10;

[User] Now show me the 10 most recent unlocks *only* for player with ID 'a1b2c3d4-e5f6-7890-1234-abcdefghijkl'.

[Assistant] SELECT player_id, achievement_id, unlocked_at FROM gaming_technology.player_achievements WHERE player_id = 'a1b2c3d4-e5f6-7890-1234-abcdefghijkl' ORDER BY unlocked_at DESC LIMIT 10;

[User] Instead of listing unlocks, tell me how many achievements that player ('a1b2c3d4-e5f6-7890-1234-abcdefghijkl') has unlocked in total.

[Assistant] SELECT COUNT(player_achievement_id) AS total_achievements_unlocked FROM gaming_technology.player_achievements WHERE player_id = 'a1b2c3d4-e5f6-7890-1234-abcdefghijkl';

[User] How many *unique* achievements has player 'a1b2c3d4-e5f6-7890-1234-abcdefghijkl' unlocked, but *only* those unlocked in 2023?

[Assistant] SELECT COUNT(DISTINCT achievement_id) AS unique_achievements_unlocked_in_2023 FROM gaming_technology.player_achievements WHERE player_id = 'a1b2c3d4-e5f6-7890-1234-abcdefghijkl' AND unlocked_at >= '2023-01-01 00:00:00' AND unlocked_at < '2024-01-01 00:00:00';


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.lawyers ( lawyer_id text PRIMARY KEY, first_name text, last_name text, bar_number text UNIQUE, firm_id text, email text UNIQUE, phone text, specialization text, hire_date timestamp, is_partner bool )

[User] List the full name, email, and phone number of all partners together with the full name of a non-partner lawyer in the same law firm.

[Assistant] SELECT p.first_name AS partner_first_name, p.last_name AS partner_last_name, p.email AS partner_email, p.phone AS partner_phone, n.first_name AS non_partner_first_name, n.last_name AS non_partner_last_name FROM legal_services.lawyers p JOIN legal_services.lawyers n ON p.firm_id = n.firm_id WHERE p.is_partner = true AND n.is_partner = false;

[User] Show only those non-partner lawyers whose specialization is 'Tax Law'.

[Assistant] SELECT p.first_name AS partner_first_name, p.last_name AS partner_last_name, p.email AS partner_email, p.phone AS partner_phone, n.first_name AS non_partner_first_name, n.last_name AS non_partner_last_name FROM legal_services.lawyers p JOIN legal_services.lawyers n ON p.firm_id = n.firm_id WHERE p.is_partner = true AND n.is_partner = false AND n.specialization = 'Tax Law';

[User] Also, return only pairs where both the partner and the non-partner have an email address specified.

[Assistant] SELECT p.first_name AS partner_first_name, p.last_name AS partner_last_name, p.email AS partner_email, p.phone AS partner_phone, n.first_name AS non_partner_first_name, n.last_name AS non_partner_last_name FROM legal_services.lawyers p JOIN legal_services.lawyers n ON p.firm_id = n.firm_id WHERE p.is_partner = true AND n.is_partner = false AND n.specialization = 'Tax Law' AND p.email IS NOT NULL AND n.email 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 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, 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 text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )

[User] Show the transaction ID, the transaction value from the transactions table, and the sum of the value from token_transfers for all transactions that have at least one associated token transfer. Name the sum column total_token_transfer_value.

[Assistant] SELECT t.transaction_id, t.value AS transaction_native_value, SUM(tt.value) AS total_token_transfer_value FROM web3.transactions t JOIN web3.token_transfers tt ON t.transaction_id = tt.transaction_id GROUP BY t.transaction_id, t.value;


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.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.trips (
    trip_id character varying(64) NOT NULL,  -- unique identifier for a specific trip instance
    route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)
    vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used
    driver_id character varying(64) NOT NULL, -- identifier of the driver operating
    scheduled_departure timestamp with time zone NOT NULL, -- planned departure time
    actual_departure timestamp with time zone, -- actual departure time
    scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time
    actual_arrival timestamp with time zone, -- actual arrival time
    origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)
    destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)
    status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled
    passenger_count integer, -- number of passengers (if applicable)
    cargo_manifest_id character varying(64), -- link to cargo details (if applicable)
    PRIMARY KEY (trip_id)
)
CREATE TABLE transportation.fuel_logs ( fuel_log_id text PRIMARY KEY, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading int, location_id text )
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] Show all trips, including the trip ID, vehicle license plate, and the vehicle's capacity.

[Assistant] SELECT t.trip_id, v.license_plate, v.capacity FROM transportation.trips t JOIN vehicles v ON t.vehicle_id = v.vehicle_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 government_services.citizens (
    citizen_id character varying(64) NOT NULL,  -- unique identifier for the citizen
    national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number
    first_name character varying(100) NOT NULL,
    last_name character varying(100) NOT NULL,
    date_of_birth date NOT NULL,
    gender character varying(20),
    primary_address text NOT NULL, -- full primary residential address
    contact_email character varying(128) UNIQUE,
    contact_phone character varying(32),
    registration_date timestamp NOT NULL, -- when the citizen profile was created
    is_verified boolean DEFAULT false, -- whether identity has been officially verified
    PRIMARY KEY (citizen_id)
)
CREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )
CREATE TABLE government_services.applications (
    application_id character varying(64) NOT NULL, -- unique identifier for the application
    citizen_id character varying(64) NOT NULL, -- FK to citizens table
    service_id character varying(64) NOT NULL, -- FK to services table
    submitted_at timestamp NOT NULL, -- time the application was submitted
    status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info
    last_updated_at timestamp NOT NULL, -- time the status or details last changed
    assigned_employee_id character varying(64), -- FK to employees table (optional)
    decision_date date, -- date when a final decision was made
    notes text, -- internal notes or citizen-provided comments
    reference_number character varying(100) UNIQUE, -- publicly visible reference number
    PRIMARY KEY (application_id)
)
CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )
CREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )

[User] Find the first name, last name, and contact email of citizens who have scheduled appointments in March 2024.

[Assistant] SELECT DISTINCT T1.first_name, T1.last_name, T1.contact_email FROM government_services.citizens AS T1 JOIN government_services.appointments AS T2 ON T1.citizen_id = T2.citizen_id WHERE T2.scheduled_start_time >= '2024-03-01' AND T2.scheduled_start_time < '2024-04-01';

[User] Now, only include appointments that have the status 'Completed'.

[Assistant] SELECT DISTINCT T1.first_name, T1.last_name, T1.contact_email FROM government_services.citizens AS T1 JOIN government_services.appointments AS T2 ON T1.citizen_id = T2.citizen_id WHERE T2.scheduled_start_time >= '2024-03-01' AND T2.scheduled_start_time < '2024-04-01' AND T2.status = 'Completed';


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 text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )

[User] Show me the medication_id, medication_name, and manufacturer for all medications where the generic_name contains the word 'azole'.

[Assistant] SELECT medication_id, medication_name, manufacturer FROM healthcare.medications WHERE generic_name ILIKE '%azole%';

[User] Can you also include the ndc_code and only show medications where the manufacturer field is not null?

[Assistant] SELECT medication_id, medication_name, manufacturer, ndc_code FROM healthcare.medications WHERE generic_name ILIKE '%azole%' AND manufacturer 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 token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )

[User] List all tokens with a liquidity over $1 million and a negative 1-hour price change percentage on the Binance chain.

[Assistant] SELECT token_name, token_symbol, price, price_change_percentage_1h, liquidity FROM token_dexpool_info WHERE chain = 'Binance' AND liquidity > 1000000 AND price_change_percentage_1h < 0;

[User] Can you also include their 24-hour trading volume and filter for tokens with a market cap under $50 million?

[Assistant] SELECT token_name, token_symbol, price, price_change_percentage_1h, liquidity, volume_24h FROM token_dexpool_info WHERE chain = 'Binance' AND liquidity > 1000000 AND price_change_percentage_1h < 0 AND market_cap < 50000000;

[User] Actually, I want to see tokens with a positive 6-hour price change instead.

[Assistant] SELECT token_name, token_symbol, price, price_change_percentage_6h, liquidity, volume_24h FROM token_dexpool_info WHERE chain = 'Binance' AND liquidity > 1000000 AND price_change_percentage_6h > 0 AND market_cap < 50000000;

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

[Assistant] SELECT token_name, token_symbol, price, price_change_percentage_6h, liquidity, volume_24h FROM token_dexpool_info WHERE chain = 'Binance' AND liquidity > 1000000 AND price_change_percentage_6h > 0 AND market_cap < 50000000 ORDER BY volume_24h 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.text, username.text, email.text, password_hash.text, created_at.timestamp )

[User] List the user IDs and usernames for all users who registered in the year 2024.

[Assistant] SELECT user_id, username FROM trading_platform.users WHERE created_at >= '2024-01-01 00:00:00' AND created_at < '2025-01-01 00:00:00';

[User] From that list, also filter to only include users whose username starts with 'alpha'.

[Assistant] SELECT user_id, username FROM trading_platform.users WHERE created_at >= '2024-01-01 00:00:00' AND created_at < '2025-01-01 00:00:00' AND username LIKE 'alpha%';


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 character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )

[User] List the patient_id, first_name, last_name, and phone_number for all patients whose gender is 'Female', and whose emergency_contact_name is not null. Also, only include patients who have an email address.

[Assistant] SELECT patient_id, first_name, last_name, phone_number FROM healthcare.patients WHERE gender = 'Female' AND emergency_contact_name IS NOT NULL AND email IS NOT NULL;

[User] Can you only include those patients whose phone_number begins with '+1'?

[Assistant] SELECT patient_id, first_name, last_name, phone_number FROM healthcare.patients WHERE gender = 'Female' AND emergency_contact_name IS NOT NULL AND email IS NOT NULL AND phone_number LIKE '+1%';

[User] I got more results than I expected. Can you add a filter to only include patients born after January 1, 1990?

[Assistant] SELECT patient_id, first_name, last_name, phone_number FROM healthcare.patients WHERE gender = 'Female' AND emergency_contact_name IS NOT NULL AND email IS NOT NULL AND phone_number LIKE '+1%' AND date_of_birth > '1990-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 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.trips ( trip_id text, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count integer, cargo_manifest_id text )
CREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )

[User] List the booking ID, trip ID, and the booking status for all bookings.

[Assistant] SELECT booking_id, trip_id, status FROM transportation.bookings;

[User] For these bookings, please also include the scheduled departure time of the corresponding trip.

[Assistant] SELECT B.booking_id, B.trip_id, B.status, T.scheduled_departure FROM transportation.bookings AS B JOIN transportation.trips AS T ON B.trip_id = T.trip_id;

[User] Only show bookings for trips with more than 50 passengers.

[Assistant] SELECT B.booking_id, B.trip_id, B.status, T.scheduled_departure FROM transportation.bookings AS B JOIN transportation.trips AS T ON B.trip_id = T.trip_id WHERE T.passenger_count > 50;

[User] Order the results by scheduled departure time in descending order.

[Assistant] SELECT B.booking_id, B.trip_id, B.status, T.scheduled_departure FROM transportation.bookings AS B JOIN transportation.trips AS T ON B.trip_id = T.trip_id WHERE T.passenger_count > 50 ORDER BY T.scheduled_departure 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.claims (
    claim_id character varying(64) NOT NULL, -- unique identifier for the claim
    policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)
    customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)
    incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim
    reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported
    description text NOT NULL, -- detailed description of the incident and claim
    estimated_loss numeric(15, 2), -- initial estimated cost of the loss
    status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled
    settlement_amount numeric(15, 2), -- final amount paid out
    settlement_date date,
    claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)
    police_report_number character varying(100),
    PRIMARY KEY (claim_id)
)
CREATE TABLE insurance.insurance_products (
    product_id character varying(64) NOT NULL, -- unique identifier for the insurance product
    product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')
    product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'
    description text, -- detailed description of the product
    base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments
    coverage_details text, -- details about what is covered (could be JSON or structured text)
    underwriting_rules text, -- rules used for assessing risk and eligibility
    is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at timestamp,
    PRIMARY KEY (product_id)
)
CREATE TABLE insurance.premium_payments (
    payment_id character varying(64) NOT NULL, -- unique identifier for the payment
    policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)
    customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)
    payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received
    amount_paid numeric(12, 2) NOT NULL, -- amount of the payment
    payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check
    transaction_reference character varying(128) UNIQUE, -- reference from payment processor
    due_date date, -- due date for this payment installment
    payment_period_start date, -- start date of the period this payment covers
    payment_period_end date, -- end date of the period this payment covers
    status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded
    PRIMARY KEY (payment_id)
)
CREATE TABLE insurance.policy_beneficiaries (
    beneficiary_id character varying(64) NOT NULL, -- unique identifier for the beneficiary entry
    policy_id character varying(64) NOT NULL, -- identifier of the life/relevant policy (FK to policies)
    customer_id character varying(64) NOT NULL, -- identifier of the beneficiary (could be FK to customers or store info directly)
    first_name character varying(100) NOT NULL, -- beneficiary first name (if not linking to customers table)
    last_name character varying(100) NOT NULL, -- beneficiary last name
    relationship character varying(50) NOT NULL, -- relationship to the policyholder (e.g., Spouse, Child, Parent)
    percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), -- percentage of payout
    contact_info text, -- contact details for the beneficiary
    added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (beneficiary_id),
    UNIQUE (policy_id, customer_id) -- Ensure a person is listed only once per policy
)

[User] Show all premium payments along with the incident date and estimated loss of any associated claims for the same policy. List payment_id, amount_paid, payment_date, incident_date, and estimated_loss.

[Assistant] SELECT T1.payment_id, T1.amount_paid, T1.payment_date, T2.incident_date, T2.estimated_loss FROM insurance.premium_payments AS T1 LEFT JOIN insurance.claims AS T2 ON T1.policy_id = T2.policy_id;

[User] Refine the results to only show payments for policies that have an associated claim with an estimated loss exceeding 10000.

[Assistant] SELECT T1.payment_id, T1.amount_paid, T1.payment_date, T2.incident_date, T2.estimated_loss FROM insurance.premium_payments AS T1 JOIN insurance.claims AS T2 ON T1.policy_id = T2.policy_id WHERE T2.estimated_loss > 10000;


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.games (
    game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game
    title character varying(200) NOT NULL, -- official title of the game
    developer_id uuid NOT NULL, -- FK linking to the developers table
    publisher_id uuid, -- FK linking to a potential publishers table (optional)
    genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)
    release_date date, -- official release date
    description text, -- short description or synopsis of the game
    platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)
    engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)
    website character varying(255), -- official website URL
    PRIMARY KEY (game_id)
    -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint
)

[User] For each publisher, find pairs of games they have published that belong to different genres. Include publisher_id, the genre and title of both games in each pair.

[Assistant]
SELECT g1.publisher_id,
       g1.genre AS genre1,
       g1.title AS title1,
       g2.genre AS genre2,
       g2.title AS title2
FROM gaming_technology.games g1
JOIN gaming_technology.games g2
  ON g1.publisher_id = g2.publisher_id
 AND g1.genre <> g2.genre;

[User] Exclude any pairs where genre1 or genre2 is NULL.

[Assistant]
SELECT g1.publisher_id,
       g1.genre AS genre1,
       g1.title AS title1,
       g2.genre AS genre2,
       g2.title AS title2
FROM gaming_technology.games g1
JOIN gaming_technology.games g2
  ON g1.publisher_id = g2.publisher_id
 AND g1.genre <> g2.genre
WHERE g1.genre IS NOT NULL
  AND g2.genre IS NOT NULL;

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

[Assistant]
SELECT g1.publisher_id,
       g1.genre AS genre1,
       g1.title AS title1,
       g2.genre AS genre2,
       g2.title AS title2
FROM gaming_technology.games g1
JOIN gaming_technology.games g2
  ON g1.publisher_id = g2.publisher_id
 AND g1.genre <> g2.genre
 AND g1.game_id < g2.game_id
WHERE g1.genre IS NOT NULL
  AND g2.genre IS NOT NULL;

[User] Order the results by publisher_id and then by title1 ascending.

[Assistant]
SELECT g1.publisher_id,
       g1.genre AS genre1,
       g1.title AS title1,
       g2.genre AS genre2,
       g2.title AS title2
FROM gaming_technology.games g1
JOIN gaming_technology.games g2
  ON g1.publisher_id = g2.publisher_id
 AND g1.genre <> g2.genre
 AND g1.game_id < g2.game_id
WHERE g1.genre IS NOT NULL
  AND g2.genre IS NOT NULL
ORDER BY g1.publisher_id,
         g1.title;


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.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )
CREATE TABLE legal_services.law_firms (
    firm_id character varying(64) NOT NULL,  -- unique identifier for the law firm
    firm_name character varying(200) NOT NULL, -- official name of the law firm
    address text NOT NULL, -- primary address of the firm
    phone character varying(32), -- firm's main phone number
    website character varying(255), -- firm's website URL
    founded_date date, -- date the firm was established
    managing_partner_id character varying(64), -- FK to lawyers table (optional)
    PRIMARY KEY (firm_id)
)
CREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )
CREATE TABLE legal_services.time_entries ( entry_id text PRIMARY KEY, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable bool, is_billed bool, invoice_id text, created_at timestamp )
CREATE TABLE legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )

[User] Show me all appointments where the subject contains the word 'Meeting', including the appointment ID, start time, end time, and subject.

[Assistant] SELECT appointment_id ,  start_time ,  end_time ,  subject FROM legal_services.appointments WHERE subject LIKE '%Meeting%'


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 PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, 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 PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )
CREATE TABLE transportation.trips ( trip_id text PRIMARY KEY, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count int, cargo_manifest_id text )
CREATE TABLE transportation.locations ( location_id text PRIMARY KEY, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )
CREATE TABLE transportation.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )
CREATE TABLE transportation.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] Provide each trip's ID, vehicle license plate, driver's full name, origin city, and destination city.

[Assistant]
SELECT t.trip_id,
       v.license_plate,
       CONCAT(d.first_name, ' ', d.last_name) AS driver_name,
       lo.city AS origin_city,
       ld.city AS destination_city
FROM transportation.trips t
JOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id
JOIN transportation.drivers d ON t.driver_id = d.driver_id
JOIN transportation.locations lo ON t.origin_location_id = lo.location_id
JOIN transportation.locations ld ON t.destination_location_id = ld.location_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 healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )
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] Count the number of patients grouped by gender, showing gender and patient_count.

[Assistant]
SELECT gender, COUNT(*) AS patient_count
FROM healthcare.patients
GROUP BY gender;


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) )

[User] I need to find all pairs of policies for each customer whose coverage periods overlap. Show customer_id, the two policy_ids for each overlapping pair.

[Assistant]
SELECT p1.customer_id,
       p1.policy_id AS policy1_id,
       p2.policy_id AS policy2_id
FROM insurance.policies p1
JOIN insurance.policies p2
  ON p1.customer_id = p2.customer_id
  AND p1.policy_id < p2.policy_id
  AND p1.start_date <= p2.end_date
  AND p2.start_date <= p1.end_date;

[User] Can you also include the number of days of overlap between the two policies as overlap_days?

[Assistant]
SELECT p1.customer_id,
       p1.policy_id AS policy1_id,
       p2.policy_id AS policy2_id,
       (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days
FROM insurance.policies p1
JOIN insurance.policies p2
  ON p1.customer_id = p2.customer_id
  AND p1.policy_id < p2.policy_id
  AND p1.start_date <= p2.end_date
  AND p2.start_date <= p1.end_date;

[User] Actually, restrict the results to only include pairs where both policies are currently active.

[Assistant]
SELECT p1.customer_id,
       p1.policy_id AS policy1_id,
       p2.policy_id AS policy2_id,
       (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days
FROM insurance.policies p1
JOIN insurance.policies p2
  ON p1.customer_id = p2.customer_id
  AND p1.policy_id < p2.policy_id
  AND p1.start_date <= p2.end_date
  AND p2.start_date <= p1.end_date
WHERE p1.status = 'active'
  AND p2.status = 'active';


System:
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement.
##Table Structure
CREATE TABLE social_media.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified bool )
CREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )
CREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )
CREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )
CREATE TABLE social_media.post_hashtags ( post_hashtag_id text PRIMARY KEY, post_id text, hashtag_id text )
CREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )
CREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )
CREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, 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 )

[User] Which users have participated in group chats and also liked comments? Please show their usernames, the group name, and the comment_id they've liked.

[Assistant]
SELECT u.username, c.group_name, l.comment_id
FROM social_media.conversation_participants cp
JOIN social_media.conversations c ON cp.conversation_id = c.conversation_id
JOIN social_media.users u ON cp.user_id = u.user_id
JOIN social_media.likes l ON u.user_id = l.user_id
WHERE c.is_group_chat = true AND l.comment_id IS NOT NULL;

[User] Could you also include the joined_at time for when each user joined the group chat?

[Assistant]
SELECT u.username, c.group_name, cp.joined_at, l.comment_id
FROM social_media.conversation_participants cp
JOIN social_media.conversations c ON cp.conversation_id = c.conversation_id
JOIN social_media.users u ON cp.user_id = u.user_id
JOIN social_media.likes l ON u.user_id = l.user_id
WHERE c.is_group_chat = true AND l.comment_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 gaming_technology.players (
    player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player
    username character varying(100) NOT NULL UNIQUE, -- player's chosen display name
    email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery
    password_hash text NOT NULL, -- securely hashed password
    registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created
    last_login timestamp with time zone, -- timestamp of the last successful login
    country_code character(2), -- player's country (ISO 3166-1 alpha-2)
    status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)
    profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.
    PRIMARY KEY (player_id)
)
CREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )
CREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )
CREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )

[User] Find all pairs of servers located in the same region but with different statuses. Show the server names, the region, and their statuses.

[Assistant]
SELECT s1.server_name AS server1, s2.server_name AS server2, s1.region, s1.status AS status1, s2.status AS status2
FROM gaming_technology.servers s1
JOIN gaming_technology.servers s2
  ON s1.region = s2.region AND s1.server_id <> s2.server_id AND s1.status <> s2.status;

[User] Please also output the current_players for both servers in each pair.

[Assistant]
SELECT s1.server_name AS server1, s2.server_name AS server2, s1.region, s1.status AS status1, s2.status AS status2,
       s1.current_players AS current_players1, s2.current_players AS current_players2
FROM gaming_technology.servers s1
JOIN gaming_technology.servers s2
  ON s1.region = s2.region AND s1.server_id <> s2.server_id AND s1.status <> s2.status;

[User] Now only include pairs in regions where there are at least 3 servers in total.

[Assistant]
WITH region_counts AS (
  SELECT region, COUNT(*) AS server_count
  FROM gaming_technology.servers
  GROUP BY region
  HAVING COUNT(*) >= 3
)
SELECT s1.server_name AS server1, s2.server_name AS server2, s1.region, s1.status AS status1, s2.status AS status2,
       s1.current_players AS current_players1, s2.current_players AS current_players2
FROM gaming_technology.servers s1
JOIN gaming_technology.servers s2
  ON s1.region = s2.region AND s1.server_id <> s2.server_id AND s1.status <> s2.status
JOIN region_counts rc ON rc.region = s1.region;

[User] Sort the result by region ascending, then by server1 name ascending.

[Assistant]
WITH region_counts AS (
  SELECT region, COUNT(*) AS server_count
  FROM gaming_technology.servers
  GROUP BY region
  HAVING COUNT(*) >= 3
)
SELECT s1.server_name AS server1, s2.server_name AS server2, s1.region, s1.status AS status1, s2.status AS status2,
       s1.current_players AS current_players1, s2.current_players AS current_players2
FROM gaming_technology.servers s1
JOIN gaming_technology.servers s2
  ON s1.region = s2.region AND s1.server_id <> s2.server_id AND s1.status <> s2.status
JOIN region_counts rc ON rc.region = s1.region
ORDER BY s1.region ASC, s1.server_name 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 legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )
CREATE TABLE legal_services.documents (
    document_id character varying(64) NOT NULL,  -- unique identifier for the document
    case_id character varying(64) NOT NULL, -- FK to cases table
    document_name character varying(255) NOT NULL, -- name of the document file
    document_type character varying(100), -- e.g., Pleading, Contract, Evidence, Correspondence
    storage_path text NOT NULL, -- path or reference to the document storage location
    uploaded_by_lawyer_id character varying(64), -- FK to lawyers table (who uploaded it)
    upload_timestamp timestamp NOT NULL, -- time the document was uploaded
    version integer DEFAULT 1, -- document version number
    description text, -- brief description or notes about the document
    PRIMARY KEY (document_id)
)
CREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )

[User] List all cases that have an invoice issued in July 2024, showing the case name, case number, invoice number, and issue date.

[Assistant] SELECT T1.case_name, T1.case_number, T2.invoice_number, T2.issue_date FROM legal_services.cases AS T1 JOIN legal_services.invoices AS T2 ON T1.case_id = T2.case_id WHERE T2.issue_date BETWEEN '2024-07-01' AND '2024-07-31';


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] Which customers have more than one account? Please include customer_id and the number of accounts they hold.

[Assistant] SELECT customer_id, COUNT(account_id) AS account_count FROM financial_services.accounts GROUP BY customer_id HAVING COUNT(account_id) > 1;

[User] Can you also show the account_types for each customer in the result?

[Assistant] SELECT customer_id, COUNT(account_id) AS account_count, STRING_AGG(DISTINCT account_type, ', ') AS account_types FROM financial_services.accounts GROUP BY customer_id HAVING COUNT(account_id) > 1;


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(), -- unique identifier for the player
    username character varying(100) NOT NULL UNIQUE, -- player's chosen display name
    email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery
    password_hash text NOT NULL, -- securely hashed password
    registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created
    last_login timestamp with time zone, -- timestamp of the last successful login
    country_code character(2), -- player's country (ISO 3166-1 alpha-2)
    status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)
    profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.
    PRIMARY KEY (player_id)
)
CREATE TABLE gaming_technology.games (
    game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game
    title character varying(200) NOT NULL, -- official title of the game
    developer_id uuid NOT NULL, -- FK linking to the developers table
    publisher_id uuid, -- FK linking to a potential publishers table (optional)
    genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)
    release_date date, -- official release date
    description text, -- short description or synopsis of the game
    platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)
    engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)
    website character varying(255), -- official website URL
    PRIMARY KEY (game_id)
    -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint
)
CREATE TABLE gaming_technology.developers (
    developer_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the developer studio
    name character varying(150) NOT NULL UNIQUE, -- name of the development studio
    country character varying(100), -- country where the studio is based
    founded_year integer, -- year the studio was founded
    website character varying(255), -- developer's official website
    created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (developer_id)
)
CREATE TABLE gaming_technology.achievements (
    achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition
    game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to
    name character varying(150) NOT NULL, -- name of the achievement
    description text NOT NULL, -- how to unlock the achievement
    icon_url character varying(255), -- URL for the achievement's icon
    points integer DEFAULT 0, -- points awarded for unlocking (optional)
    hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked
    PRIMARY KEY (achievement_id)
    -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)
)
CREATE TABLE gaming_technology.player_achievements (
    player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance
    player_id uuid NOT NULL, -- FK linking to the player who unlocked it
    achievement_id uuid NOT NULL, -- FK linking to the achievement definition
    unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked
    PRIMARY KEY (player_achievement_id),
    UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once
    -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),
    -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)
)
CREATE TABLE gaming_technology.player_inventory (
    inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry
    player_id uuid NOT NULL, -- FK linking to the player owning the item
    item_id uuid NOT NULL, -- FK linking to the item definition
    quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)
    acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired
    instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)
    PRIMARY KEY (inventory_id),
    -- Optional unique constraint if items are non-stackable or unique instances
    -- UNIQUE (player_id, item_id) -- Use if quantity is always 1
    -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),
    -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)
)

[User] List all players with the games for which they've unlocked achievements, showing username, game title, and count of achievements unlocked per game.

[Assistant]
SELECT p.username, g.title AS game_title, COUNT(pa.achievement_id) AS unlocked_count
FROM gaming_technology.players p
JOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id
JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id
JOIN gaming_technology.games g ON a.game_id = g.game_id
GROUP BY p.username, g.title;

[User] Actually, I'd like to see only players who unlocked achievements in at least two different games.

[Assistant]
WITH multi_games AS (
  SELECT pa.player_id
  FROM gaming_technology.player_achievements pa
  JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id
  GROUP BY pa.player_id
  HAVING COUNT(DISTINCT a.game_id) >= 2
)
SELECT p.username, g.title AS game_title, COUNT(pa.achievement_id) AS unlocked_count
FROM multi_games mg
JOIN gaming_technology.players p ON mg.player_id = p.player_id
JOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id
JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id
JOIN gaming_technology.games g ON a.game_id = g.game_id
GROUP BY p.username, g.title;

[User] Finally, show only those game rows where the unlocked count is at least 3.

[Assistant]
WITH multi_games AS (
  SELECT pa.player_id
  FROM gaming_technology.player_achievements pa
  JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id
  GROUP BY pa.player_id
  HAVING COUNT(DISTINCT a.game_id) >= 2
)
SELECT p.username, g.title AS game_title, COUNT(pa.achievement_id) AS unlocked_count
FROM multi_games mg
JOIN gaming_technology.players p ON mg.player_id = p.player_id
JOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id
JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id
JOIN gaming_technology.games g ON a.game_id = g.game_id
GROUP BY p.username, g.title
HAVING COUNT(pa.achievement_id) >= 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 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 )

[User] Can you show me the total number of available services and the average price for each department?

[Assistant] SELECT department, COUNT(*) AS available_service_count, AVG(price) AS average_price FROM hospitality_technology.services WHERE is_available = true GROUP BY department;

[User] Now, include only departments where the average price is greater than 60 and sort by average_price descending.

[Assistant] SELECT department, COUNT(*) AS available_service_count, AVG(price) AS average_price FROM hospitality_technology.services WHERE is_available = true GROUP BY department HAVING AVG(price) > 60 ORDER BY average_price 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 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.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.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
CREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, work_email character varying(255) UNIQUE, work_phone character varying(30), hire_date date NOT NULL, termination_date date, is_active boolean NOT NULL DEFAULT true, access_level integer NOT NULL, manager_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) )
CREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )

[User] Get each property's name and the number of distinct service categories it offers.

[Assistant]
SELECT p.property_name,
       COUNT(DISTINCT s.category) AS category_count
FROM hospitality_technology.properties p
LEFT JOIN hospitality_technology.services s
  ON p.property_id = s.property_id
GROUP BY p.property_name;

[User] Now only include properties that offer more than 2 categories.

[Assistant]
SELECT p.property_name,
       COUNT(DISTINCT s.category) AS category_count
FROM hospitality_technology.properties p
LEFT JOIN hospitality_technology.services s
  ON p.property_id = s.property_id
GROUP BY p.property_name
HAVING COUNT(DISTINCT s.category) > 2;


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 PRIMARY KEY, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )

[User] I need pairs of items within the same game where one item_type is 'Weapon' and the other is 'Consumable'. Show game_id, weapon_name, and consumable_name.

[Assistant]
SELECT i1.game_id, i1.item_name AS weapon_name, i2.item_name AS consumable_name
FROM gaming_technology.in_game_items i1
JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id AND i1.item_type = 'Weapon' AND i2.item_type = 'Consumable';

[User] Actually, I only want pairs where both items are of 'Epic' rarity.

[Assistant]
SELECT i1.game_id, i1.item_name AS weapon_name, i2.item_name AS consumable_name
FROM gaming_technology.in_game_items i1
JOIN gaming_technology.in_game_items i2 ON i1.game_id = i2.game_id
  AND i1.item_type = 'Weapon' AND i2.item_type = 'Consumable'
  AND i1.rarity = 'Epic' AND i2.rarity = 'Epic';


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, user_id text, address text, private_key text, created_at timestamp )

[User] Show me pairs of wallets that belong to the same user, listing the wallet_id, user_id, address, and created_at for the earlier and later wallet in each pair.

[Assistant]
SELECT w1.user_id,
       w1.wallet_id AS earlier_wallet,
       w1.address AS earlier_address,
       w1.created_at AS earlier_created_at,
       w2.wallet_id AS later_wallet,
       w2.address AS later_address,
       w2.created_at AS later_created_at
FROM trading_platform.wallets w1
JOIN trading_platform.wallets w2
  ON w1.user_id = w2.user_id
 AND w1.created_at < w2.created_at;

[User] Now only include pairs where the later wallet was created more than 30 days after the earlier one.

[Assistant]
SELECT w1.user_id,
       w1.wallet_id AS earlier_wallet,
       w1.address AS earlier_address,
       w1.created_at AS earlier_created_at,
       w2.wallet_id AS later_wallet,
       w2.address AS later_address,
       w2.created_at AS later_created_at
FROM trading_platform.wallets w1
JOIN trading_platform.wallets w2
  ON w1.user_id = w2.user_id
 AND w2.created_at > w1.created_at + 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 hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )
CREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )
CREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )
CREATE TABLE hospitality_technology.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 all properties that have at least one room on the 10th floor. Include the property name and the count of such rooms.

[Assistant]
SELECT p.property_name,
       COUNT(r.room_id) AS room_count
FROM hospitality_technology.properties p
JOIN hospitality_technology.rooms r
  ON p.property_id = r.property_id
WHERE r.floor = 10
GROUP BY p.property_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 financial_services.transactions ( transaction_id text, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )
CREATE TABLE financial_services.securities ( security_id text, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )
CREATE TABLE financial_services.market_data ( data_point_id bigint, security_id text, data_timestamp timestamp, open_price numeric, high_price numeric, low_price numeric, close_price numeric, adjusted_close_price numeric, volume bigint, source text )

[User] Show the total number of transactions for each currency.

[Assistant] SELECT currency, COUNT(*) FROM financial_services.transactions GROUP BY currency

[User] Can you also include the total amount for each currency?

[Assistant] SELECT currency, COUNT(*), SUM(amount) FROM financial_services.transactions GROUP BY currency


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.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )
CREATE TABLE web3.token_transfers ( transfer_id character varying(64) NOT NULL, token_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128) NOT NULL, value numeric(38,14) NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (transfer_id) )
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] Find all events emitted by contracts that are also associated with token transfers. Show the event id, contract id, event name, emitted_at, transaction id, and also include the corresponding transfer id from token_transfers.

[Assistant]
SELECT e.event_id, e.contract_id, e.event_name, e.emitted_at, e.transaction_id, tt.transfer_id
FROM web3.events e
JOIN web3.token_transfers tt ON e.transaction_id = tt.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 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 )

[User] Show me all staff members who have a manager assigned, along with each manager's full name.

[Assistant]
SELECT s.staff_id, s.first_name, s.last_name, s.manager_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name
FROM hospitality_technology.staff s
LEFT JOIN hospitality_technology.staff m ON s.manager_id = m.staff_id
WHERE s.manager_id IS NOT NULL;

[User] Actually, only include managers who are currently active.

[Assistant]
SELECT s.staff_id, s.first_name, s.last_name, s.manager_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name
FROM hospitality_technology.staff s
LEFT JOIN hospitality_technology.staff m ON s.manager_id = m.staff_id
WHERE s.manager_id IS NOT NULL AND m.is_active = TRUE;


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.user_settings ( setting_id.text, user_id.text, theme.text, email_notifications_enabled.boolean, push_notifications_enabled.boolean, private_profile.boolean, updated_at.timestamp )

[User] List the user IDs, theme, and updated_at for users who have disabled email notifications, enabled push notifications, and have a private profile.

[Assistant] SELECT user_id, theme, updated_at FROM social_media.user_settings WHERE email_notifications_enabled = FALSE AND push_notifications_enabled = TRUE AND private_profile = TRUE;

[User] Now, only include those whose theme is set to 'light'.

[Assistant] SELECT user_id, theme, updated_at FROM social_media.user_settings WHERE email_notifications_enabled = FALSE AND push_notifications_enabled = TRUE AND private_profile = TRUE AND theme = 'light';

[User] Order these results by the updated_at timestamp in descending order.

[Assistant] SELECT user_id, theme, updated_at FROM social_media.user_settings WHERE email_notifications_enabled = FALSE AND push_notifications_enabled = TRUE AND private_profile = TRUE AND theme = 'light' ORDER BY updated_at DESC;

[User] Limit the results to the top 5.

[Assistant] SELECT user_id, theme, updated_at FROM social_media.user_settings WHERE email_notifications_enabled = FALSE AND push_notifications_enabled = TRUE AND private_profile = TRUE AND theme = 'light' ORDER BY updated_at 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 token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )
CREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )
CREATE TABLE erc20_balances_historical (
    block_number bigint NOT NULL, -- Block number containing the transaction
    contract_address varchar NOT NULL, -- Event contract address
    wallet_address varchar NOT NULL, -- The wallet address for the contract
    amount varchar NOT NULL, -- Wallet's on-chain balance at the corresponding block height
    pk integer NOT NULL  -- Partition key for the table(floor(block_number / 7200))
)
CREATE TABLE nft_holders (
    block_number bigint NOT NULL, -- Block number containing the transaction
    contract_address varchar NOT NULL, -- Event contract address
    wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)
    token_id varchar NOT NULL, -- NFT token id
    contract_type varchar NOT NULL, -- NFT contract type
    amount varchar NOT NULL, -- Number of held NFTs
    pk varchar NOT NULL  -- The last string partition of the contract.
)
CREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )
CREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )
CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )
CREATE TABLE nft_collections (
    blockchain varchar NOT NULL, -- blockchain fields for the functionType  in contract
    contract_address varchar NOT NULL, -- Contract address(with bloom filter)
    name varchar NOT NULL, -- name fields for the functionType  in contract
    symbol varchar NOT NULL, -- symbol fields for the functionType  in contract
    deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType  in contract
    deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType  in contract
    erc_type varchar NOT NULL, -- The type of token
    owner varchar NOT NULL, -- owner fields for the functionType  in contract
    traits varchar NOT NULL, -- traits fields for the functionType  in contract
    description varchar NOT NULL, -- description fields for the functionType  in contract
    slug varchar NOT NULL, -- slug fields for the functionType  in contract
    media_info varchar NOT NULL, -- media_info fields for the functionType  in contract
    image_url varchar NOT NULL, -- image_url fields for the functionType  in contract
    banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType  in contract
    updated_at bigint NOT NULL, -- updated_at fields for the functionType  in contract
    banner varchar NOT NULL, -- banner fields for the functionType  in contract
    token_count bigint NOT NULL, -- token_count fields for the functionType  in contract
    floor_price varchar NOT NULL, -- floor_price fields for the functionType  in contract
    floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType  in contract
    floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType  in contract
    pk integer NOT NULL  -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))
)
CREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )
CREATE TABLE token_prices_latest (
    blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType  in contract
    address varchar(42) NOT NULL, -- address fields for the functionType  in contract
    decimals bigint NOT NULL, -- decimals fields for the functionType  in contract
    symbol varchar(36) NOT NULL, -- symbol fields for the functionType  in contract
    price real NOT NULL, -- price fields for the functionType  in contract
    timestamp timestamp(6) NOT NULL  -- timestamp fields for the functionType  in contract
)
CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )
CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )
CREATE TABLE token_info (
    block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)
    block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)
    tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)
    tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)
    tick varchar NOT NULL, -- Token tick
    max_supply decimal(38,0) NOT NULL, -- Max supply
    lim decimal(38,0) NOT NULL, -- Limit of each mint
    wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint
    dec integer NOT NULL, -- Decimal for minimum divie
    creator varchar(42) NOT NULL  -- Address originating the inscription (matches from_address in transactions table)
)
CREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )
CREATE TABLE mud_holesky_redstone ( address.text, table_id.text, key_bytes.text, key0.text, key1.text, static_data.text, encoded_lengths.text, dynamic_data.text, is_deleted.boolean, block_number.bigint, log_index.bigint )
CREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )
CREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )
CREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )

[User] Find the total transfer volume for each Avalanche token over the past 7 days and include the token's creator.

[Assistant]
SELECT a.tick,
       i.creator,
       SUM(a.amt) AS total_volume
FROM token_activities_avalanche a
JOIN token_info_avalanche i
  ON a.tick = i.tick
WHERE a.block_timestamp >= NOW() - INTERVAL '7 days'
GROUP BY a.tick, i.creator;

[User] Only include tokens with total_volume > 10000 and sort by total_volume descending.

[Assistant]
SELECT a.tick,
       i.creator,
       SUM(a.amt) AS total_volume
FROM token_activities_avalanche a
JOIN token_info_avalanche i
  ON a.tick = i.tick
WHERE a.block_timestamp >= NOW() - INTERVAL '7 days'
GROUP BY a.tick, i.creator
HAVING SUM(a.amt) > 10000
ORDER BY total_volume DESC;

[User] Limit the results to the top 5 tokens.

[Assistant]
SELECT a.tick,
       i.creator,
       SUM(a.amt) AS total_volume
FROM token_activities_avalanche a
JOIN token_info_avalanche i
  ON a.tick = i.tick
WHERE a.block_timestamp >= NOW() - INTERVAL '7 days'
GROUP BY a.tick, i.creator
HAVING SUM(a.amt) > 10000
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 hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )

[User] How many service orders were placed by each staff member (staff_id_ordered)? Show the staff ID and the count.

[Assistant] SELECT staff_id_ordered, COUNT(*) FROM hospitality_technology.service_orders GROUP BY staff_id_ordered;

[User] Only show staff members who placed more than 10 orders.

[Assistant] SELECT staff_id_ordered, COUNT(*) FROM hospitality_technology.service_orders GROUP BY staff_id_ordered HAVING COUNT(*) > 10;

[User] And exclude orders that were cancelled.

[Assistant] SELECT staff_id_ordered, COUNT(*) FROM hospitality_technology.service_orders WHERE status != 'Cancelled' GROUP BY staff_id_ordered HAVING COUNT(*) > 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.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )

[User] For each user, what is the average time difference in days between their wallet creations? Return user_id and avg_diff_days.

[Assistant]
WITH diffs AS (
  SELECT
    user_id,
    EXTRACT(EPOCH FROM (created_at - LAG(created_at) OVER (PARTITION BY user_id ORDER BY created_at))) / 86400 AS diff_days
  FROM web3.wallets
)
SELECT
  user_id,
  AVG(diff_days) AS avg_diff_days
FROM diffs
WHERE diff_days IS NOT NULL
GROUP BY user_id;

[User] Actually, only include users who have created more than 2 wallets.

[Assistant]
WITH diffs AS (
  SELECT
    user_id,
    EXTRACT(EPOCH FROM (created_at - LAG(created_at) OVER (PARTITION BY user_id ORDER BY created_at))) / 86400 AS diff_days
  FROM web3.wallets
)
SELECT
  user_id,
  AVG(diff_days) AS avg_diff_days
FROM diffs
WHERE diff_days IS NOT NULL
GROUP BY user_id
HAVING COUNT(diff_days) > 1;


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 blockchain.nodes ( node_id text, ip_address text, port integer, last_seen timestamp )
CREATE TABLE blockchain.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
    PRIMARY KEY (user_id)
)

[User] How many unique email domains are there among all registered users?

[Assistant] SELECT COUNT(DISTINCT SUBSTRING(email FROM POSITION('@' IN email) + 1)) AS unique_domains FROM blockchain.users;

[User] Can you list these domains along with the count of users for each domain?

[Assistant] SELECT SUBSTRING(email FROM POSITION('@' IN email) + 1) AS domain, COUNT(*) AS user_count FROM blockchain.users GROUP BY domain;

[User] Now show only domains that have more than 10 users.

[Assistant] SELECT SUBSTRING(email FROM POSITION('@' IN email) + 1) AS domain, COUNT(*) AS user_count FROM blockchain.users GROUP BY domain HAVING COUNT(*) > 10;

[User] Can you modify this to also include the earliest registration date for each domain?

[Assistant] SELECT SUBSTRING(email FROM POSITION('@' IN email) + 1) AS domain, COUNT(*) AS user_count, MIN(created_at) AS earliest_registration FROM blockchain.users GROUP BY domain HAVING COUNT(*) > 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 legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )

[User] List all pairs of clients who registered on the same day, showing each client's first_name, last_name, and the registration date.

[Assistant] SELECT c1.first_name AS first_name_1, c1.last_name AS last_name_1, c2.first_name AS first_name_2, c2.last_name AS last_name_2, DATE(c1.date_registered) AS registration_date FROM legal_services.clients c1 JOIN legal_services.clients c2 ON DATE(c1.date_registered) = DATE(c2.date_registered) AND c1.client_id < c2.client_id;


System:
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. 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.aircraft_models ( model_id text PRIMARY KEY, model_name text, manufacturer text, passenger_capacity int, max_range_km int, engine_type text, wingspan_m numeric, status text, first_flight_date date )

[User] What are the environmental impact assessments for the production of the Airbus A350 model?

[Assistant] I'm sorry, but I don't have access to data regarding the environmental impact assessments for the production of specific aircraft models like the Airbus A350. My information is limited to the technical specifications and basic details stored in the database, such as model name, manufacturer, and capacity. If you have a question related to the available data, I'd be happy to assist.