{"conversations": [{"content": "Show me all customers who have missing contact information (either phone number or email is null), along with their state and city.", "role": "user"}, {"content": "SELECT first_name, last_name, state, city FROM insurance.customers WHERE phone_number IS NULL OR email IS NULL;", "role": "assistant"}, {"content": "Now filter these to only show customers from Florida or New York who were created in the last year.", "role": "user"}, {"content": "SELECT first_name, last_name, state, city FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '1 year';", "role": "assistant"}, {"content": "I also want to see when these customers were last updated (updated_at field).", "role": "user"}, {"content": "SELECT first_name, last_name, state, city, updated_at FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '1 year';", "role": "assistant"}, {"content": "Finally, order the results by state first, then by the most recently updated customers first.", "role": "user"}, {"content": "SELECT first_name, last_name, state, city, updated_at FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '1 year' ORDER BY state, updated_at DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\n"} {"conversations": [{"content": "List the name and symbol for all assets that do not have a corresponding entry with the key 'website' in the metadata table.", "role": "user"}, {"content": "SELECT T1.name , T1.symbol FROM trading_platform.assets AS T1 LEFT JOIN trading_platform.metadata AS T2 ON T1.asset_id = T2.asset_id AND T2.key = 'website' WHERE T2.metadata_id IS NULL", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\n"} {"conversations": [{"content": "What is the maintenance schedule for platform 3 at station DEF for the next month?", "role": "user"}, {"content": "I'm sorry, but I don't have access to the maintenance schedule for platforms. The data I have only includes static information about platform details such as ID, station, number, track, status, length, and accessibility. For maintenance schedules, you may need to consult the station management or relevant department.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.platforms ( platform_id text, station_id text, platform_number text, track_number text, status text, length_meters numeric, accessible boolean )\n"} {"conversations": [{"content": "What are the specific tools or equipment used during the maintenance with record_id 'REC456'?", "role": "user"}, {"content": "I'm sorry, but I can't provide information about the specific tools or equipment used during a maintenance record. The data in the maintenance_records table does not include details about tools or equipment used.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.maintenance_records ( record_id text PRIMARY KEY, asset_id text, asset_type text, maintenance_type text, staff_id text, start_datetime timestamp, end_datetime timestamp, description text, cost numeric, status text )\n"} {"conversations": [{"content": "Find all contracts where the deployer address is the same as the contract address, indicating self-deployed contracts, and show their network IDs and deployment timestamps.", "role": "user"}, {"content": "SELECT address, network_id, deployed_at FROM web3.contracts WHERE address = deployer_address;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n"} {"conversations": [{"content": "Count the number of law firms founded in each decade. Show the decade (e.g., 1990s, 2000s) and the count.", "role": "user"}, {"content": "SELECT CONCAT(FLOOR(EXTRACT(YEAR FROM founded_date) / 10) * 10, 's') AS decade, COUNT(*) AS firm_count FROM law_firms WHERE founded_date IS NOT NULL GROUP BY decade ORDER BY decade;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.documents ( document_id text PRIMARY KEY, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version int, description text )\n"} {"conversations": [{"content": "List the citizen IDs for individuals who have both uploaded documents and made payments.", "role": "user"}, {"content": "SELECT DISTINCT T1.citizen_id FROM documents AS T1 JOIN payments AS T2 ON T1.citizen_id = T2.citizen_id", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\n"} {"conversations": [{"content": "Show me the number of approval-for-all events for each ERC1155 contract in the erc1155_approval_for_all table.", "role": "user"}, {"content": "SELECT contract_address, COUNT(*) AS approval_count FROM erc1155_approval_for_all GROUP BY contract_address;", "role": "assistant"}, {"content": "Can you also include the number of unique wallets currently holding NFTs from each ERC1155 contract by joining with nft_holders?", "role": "user"}, {"content": "SELECT a.contract_address, COUNT(*) AS approval_count, COUNT(DISTINCT h.wallet_address) AS unique_holder_count FROM erc1155_approval_for_all a LEFT JOIN nft_holders h ON h.contract_address = a.contract_address AND h.contract_type = 'ERC1155' GROUP BY a.contract_address;", "role": "assistant"}, {"content": "Filter the results to only include contracts where the approval_count is greater than 20 and unique_holder_count is more than 5.", "role": "user"}, {"content": "SELECT a.contract_address, COUNT(*) AS approval_count, COUNT(DISTINCT h.wallet_address) AS unique_holder_count FROM erc1155_approval_for_all a LEFT JOIN nft_holders h ON h.contract_address = a.contract_address AND h.contract_type = 'ERC1155' GROUP BY a.contract_address HAVING COUNT(*) > 20 AND COUNT(DISTINCT h.wallet_address) > 5;", "role": "assistant"}, {"content": "Order the results by approval_count descending and limit to the top 5 contracts.", "role": "user"}, {"content": "SELECT a.contract_address, COUNT(*) AS approval_count, COUNT(DISTINCT h.wallet_address) AS unique_holder_count FROM erc1155_approval_for_all a LEFT JOIN nft_holders h ON h.contract_address = a.contract_address AND h.contract_type = 'ERC1155' GROUP BY a.contract_address HAVING COUNT(*) > 20 AND COUNT(DISTINCT h.wallet_address) > 5 ORDER BY approval_count DESC LIMIT 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_info_bitcoin ( 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 )\nCREATE TABLE token_activities_bitcoin ( 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 )\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE 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 )\n"} {"conversations": [{"content": "Show me all maintenance logs for 'Oil Change' services performed in the last 3 months, including the vehicle ID, service date, and cost.", "role": "user"}, {"content": "SELECT vehicle_id, service_date, cost FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months';", "role": "assistant"}, {"content": "Can you also include the mechanic name and order the results by the most expensive services first?", "role": "user"}, {"content": "SELECT vehicle_id, service_date, cost, mechanic_name FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' ORDER BY cost DESC;", "role": "assistant"}, {"content": "Now filter these results to only show oil changes that cost more than $100.", "role": "user"}, {"content": "SELECT vehicle_id, service_date, cost, mechanic_name FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100 ORDER BY cost DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\n"} {"conversations": [{"content": "List the first and last name of each citizen along with the city and state of the service location for their agency.", "role": "user"}, {"content": "SELECT c.first_name, c.last_name, sl.city, sl.state\nFROM government_services.citizens c\nJOIN government_services.payments p ON c.citizen_id = p.citizen_id\nJOIN government_services.employees e ON p.application_id IS NOT NULL AND e.agency_id IS NOT NULL\nJOIN government_services.service_locations sl ON e.agency_id = sl.agency_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\n"} {"conversations": [{"content": "Find all pairs of different insurance records that share the same group_number, and show group_number, the patient_insurance_id of both records, and their corresponding patient_ids.", "role": "user"}, {"content": "SELECT a.group_number,\n a.patient_insurance_id AS pi_id1,\n a.patient_id AS patient1_id,\n b.patient_insurance_id AS pi_id2,\n b.patient_id AS patient2_id\nFROM healthcare.patient_insurance a\nJOIN healthcare.patient_insurance b\n ON a.group_number = b.group_number\n AND a.patient_insurance_id < b.patient_insurance_id\nWHERE a.group_number IS NOT NULL;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n"} {"conversations": [{"content": "What is the reason behind the cost variation for maintenance of asset_id 'ASSET456' over the past year?", "role": "user"}, {"content": "I'm sorry, but I can't provide information on the reasons behind cost variations for maintenance. The data in the maintenance_records table includes only the cost amount and other basic details of each maintenance record, but it does not contain explanations or factors influencing cost changes.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.maintenance_records ( record_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, asset_type character varying(32) NOT NULL, maintenance_type character varying(128) NOT NULL, staff_id character varying(64), start_datetime timestamp NOT NULL, end_datetime timestamp, description text NOT NULL, cost numeric(12, 2), status character varying(32) NOT NULL DEFAULT 'Completed', PRIMARY KEY (record_id), FOREIGN KEY (staff_id) REFERENCES train_station_management.staff(staff_id) )\n"} {"conversations": [{"content": "What is the total revenue generated by ticket sales at the station with ID 'ST101' for the past month?", "role": "user"}, {"content": "I'm sorry, but I can't provide information on the revenue generated by ticket sales as this data is not available in the current database table. The table only contains details about station information such as name, location, and platform count. If you have another question or need assistance with something else related to the station data, I'm happy to help.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.stations ( station_id.text, station_name.text, city.text, state_province.text, country_code.text, address.text, timezone.text, number_of_platforms.integer, created_at.timestamp, last_updated_at.timestamp )\n"} {"conversations": [{"content": "What is the schedule of trains arriving at platform 1A at station XYZ on December 25th, 2023?", "role": "user"}, {"content": "I'm sorry, but I can't provide information about train schedules or specific arrival times as this data is not included in the platform management table. For train schedules, please refer to the train timetable or contact the station's customer service.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.platforms (\n platform_id character varying(64) NOT NULL, -- Unique identifier for the platform\n station_id character varying(64) NOT NULL, -- Foreign key referencing stations\n platform_number character varying(10) NOT NULL, -- Platform identifier (e.g., '1A', '5')\n track_number character varying(10), -- Associated track number, if different\n status character varying(32) NOT NULL DEFAULT 'Operational', -- e.g., Operational, Maintenance, Closed\n length_meters numeric(8,2), -- Length of the platform in meters\n accessible boolean NOT NULL DEFAULT false, -- Is the platform accessible (e.g., wheelchair)?\n PRIMARY KEY (platform_id),\n FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id)\n)\n"} {"conversations": [{"content": "For the 'DeFi' narrative, what is the average ROI and the total net inflow (usd_value where type=1) from smart money token inflow?", "role": "user"}, {"content": "SELECT AVG(sm.roi) AS avg_roi, SUM(smt.usd_value) AS total_net_inflow\nFROM smart_money_token_inflow smt\nJOIN smart_money_profit sm ON smt.chain = sm.chain\nWHERE smt.narrative = 'DeFi' AND smt.type = 1;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\nCREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n"} {"conversations": [{"content": "Show me all events emitted by contracts where the event name contains 'Approval', along with the contract ID and transaction ID, sorted by emitted timestamp in descending order.", "role": "user"}, {"content": "SELECT event_id, contract_id, event_name, transaction_id, emitted_at FROM web3.events WHERE event_name LIKE '%Approval%' ORDER BY emitted_at DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\n"} {"conversations": [{"content": "List the full names and dates of birth for all patients who do not have a phone number on record.", "role": "user"}, {"content": "SELECT first_name, last_name, date_of_birth FROM healthcare.patients WHERE phone_number IS NULL OR TRIM(phone_number) = '';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )\n"} {"conversations": [{"content": "Can you help me retrieve the list of components made of a specific material along with their supplier details?", "role": "user"}, {"content": "SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id", "role": "assistant"}, {"content": "Can you also include the part number for each component in the result?", "role": "user"}, {"content": "SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id\nHGET component: part_number", "role": "assistant"}, {"content": "If I want to filter out components from a specific supplier, how can I modify the query?", "role": "user"}, {"content": "SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id\nHGET component: part_number\nIF HGET component: supplier_id != 'sup:ACME_AERO' THEN INCLUDE", "role": "assistant"}, {"content": "Can you also sort the results based on the part number?", "role": "user"}, {"content": "SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id\nHGET component: part_number\nIF HGET component: supplier_id != 'sup:ACME_AERO' THEN INCLUDE\nSORT BY part_number ASC", "role": "assistant"}], "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. \n##Table Structure\nUse Hashes. Key pattern: 'component:'. Example: HSET component:LGSTRUT01 part_number \"PN-5521-A\" component_name \"Landing Gear Strut\" material_id \"mat:TI64\" supplier_id \"sup:ACME_AERO\" ... Consider Sets for reverse lookups (e.g., 'material_components:' -> Set).\n"} {"conversations": [{"content": "List the first name, last name, license number, and status for all drivers whose license expires in the next 6 months.", "role": "user"}, {"content": "SELECT\n first_name,\n last_name,\n license_number,\n status\nFROM transportation.drivers\nWHERE\n license_expiry_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '6 month'\nORDER BY\n license_expiry_date;", "role": "assistant"}, {"content": "Now, count how many drivers from that list have an 'Active' status.", "role": "user"}, {"content": "SELECT\n COUNT(*)\nFROM transportation.drivers\nWHERE\n license_expiry_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '6 month' AND status = 'Active';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\n"} {"conversations": [{"content": "Give me the total billed amount for each invoice in 2024.", "role": "user"}, {"content": "SELECT invoice_id, SUM(hours_spent * billing_rate) AS total_billed_amount FROM legal_services.time_entries WHERE is_billed = TRUE AND EXTRACT(YEAR FROM date_worked) = 2024 GROUP BY invoice_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "List pairs of citizens who share the same email domain.", "role": "user"}, {"content": "SELECT c1.first_name AS first1,\n c1.last_name AS last1,\n c2.first_name AS first2,\n c2.last_name AS last2,\n SPLIT_PART(c1.contact_email, '@', 2) AS domain\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON SPLIT_PART(c1.contact_email, '@', 2) = SPLIT_PART(c2.contact_email, '@', 2)\n AND c1.citizen_id < c2.citizen_id\nWHERE c1.contact_email IS NOT NULL\n AND c2.contact_email IS NOT NULL;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\n"} {"conversations": [{"content": "Show me each product_type along with the count of products for that type, but only include types where the average base_premium exceeds 500. Order the results by the product count in descending order.", "role": "user"}, {"content": "SELECT product_type,\n COUNT(*) AS product_count\nFROM insurance.insurance_products\nGROUP BY product_type\nHAVING AVG(base_premium) > 500\nORDER BY product_count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\n"} {"conversations": [{"content": "Show me all cryptocurrency assets that have been traded more than 50 times but have never been traded in quantities greater than 100, along with their average trade price.", "role": "user"}, {"content": "SELECT a.asset_id, a.name, a.symbol, COUNT(t.trade_id) AS trade_count, AVG(t.price) AS avg_price FROM trading_platform.assets a JOIN trading_platform.trades t ON a.asset_id = t.asset_id WHERE a.type = 'cryptocurrency' GROUP BY a.asset_id, a.name, a.symbol HAVING COUNT(t.trade_id) > 50 AND MAX(t.quantity) <= 100;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\nCREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) )\nCREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )\n"} {"conversations": [{"content": "Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens where the price is greater than $0.10.", "role": "user"}, {"content": "SELECT tm.name, tm.contract_address, tm.total_supply FROM token_metas tm WHERE tm.is_erc20 = 1 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;", "role": "assistant"}, {"content": "I think there's a typo in your query - it should be 'total_supply' not 'total_supply'. Also, can you join this with the token_prices_latest table to include the current price of each token?", "role": "user"}, {"content": "SELECT tm.name, tm.contract_address, tm.total_supply, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;", "role": "assistant"}, {"content": "The token_prices_latest table isn't in the schema. Can you modify the query to use the erc20_balances table instead to show the total balance held across all wallets for each token?", "role": "user"}, {"content": "SELECT tm.name, tm.contract_address, tm.total_supply, SUM(CAST(eb.amount AS decimal)) AS total_balance FROM token_metas tm JOIN erc20_balances eb ON tm.contract_address = eb.contract_address WHERE tm.is_erc20 = 1 GROUP BY tm.name, tm.contract_address, tm.total_supply ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas (\n block_timestamp timestamp(6) NOT NULL, -- Timestamp of the block when token metadata was recorded\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n transaction_hash varchar NOT NULL, -- Hash value of the transaction\n transaction_index bigint NOT NULL, -- Index of the transaction within the block\n from_address varchar NOT NULL, -- Address from which the transaction originated\n contract_address varchar NOT NULL, -- Address of the token contract\n symbol varchar NOT NULL, -- Symbol of the token\n total_supply varchar NOT NULL, -- erc20 contract total supply\n name varchar NOT NULL, -- Name of the token\n decimals bigint NOT NULL, -- Number of decimal places for the token\n is_erc20 integer NOT NULL, -- Flag indicating if the token is an ERC-20 token (0 or 1)\n is_erc721 integer NOT NULL, -- Flag indicating if the token is an ERC-721 token (0 or 1)\n is_erc1155 integer NOT NULL, -- Flag indicating if the token is an ERC-1155 token (0 or 1)\n is_proxy integer NOT NULL, -- Flag indicating if the token is a proxy (0 or 1)\n extra_info varchar NOT NULL, -- Additional information about the token\n pk integer NOT NULL -- Partition key for the table(floor(block_number / 5760))\n)\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- Number of held NFTs\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar NOT NULL, -- mint | transfer | burn\n tick varchar NOT NULL, -- Token tick\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Mint amount\n from_address varchar(42) NOT NULL, -- Address sending the inscription (matches from_address in transactions table)\n to_address varchar(42) NOT NULL -- Address receiving the inscription (match to_address in transactions table)\n)\nCREATE TABLE token_activities_bitcoin ( 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 )\nCREATE TABLE token_activities_avalanche ( 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 )\n"} {"conversations": [{"content": "Show the number of employees in each department.", "role": "user"}, {"content": "SELECT department, COUNT(*) AS employee_count\nFROM financial_services.employees\ngroup BY department;", "role": "assistant"}, {"content": "Exclude departments that have less than 3 employees.", "role": "user"}, {"content": "SELECT department, COUNT(*) AS employee_count\nFROM financial_services.employees\ngroup BY department\nHAVING COUNT(*) >= 3;", "role": "assistant"}, {"content": "Can you also show the average hire_date for employees in each department?", "role": "user"}, {"content": "SELECT department, COUNT(*) AS employee_count, AVG(hire_date) AS average_hire_date\nFROM financial_services.employees\ngroup BY department\nHAVING COUNT(*) >= 3;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text PRIMARY KEY, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions ( transaction_id text PRIMARY KEY, 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 )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial PRIMARY KEY, 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 )\nCREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n"} {"conversations": [{"content": "Show me the top 5 narratives by market cap, along with their 24-hour trading volume and 7-day price change percentage.", "role": "user"}, {"content": "SELECT narrative.text, volume_24h.numeric, price_change_percentage_7d.numeric FROM narrative_info ORDER BY market_cap.numeric DESC LIMIT 5;", "role": "assistant"}, {"content": "Can you also include the top 3 coins for each of these narratives?", "role": "user"}, {"content": "SELECT narrative.text, volume_24h.numeric, price_change_percentage_7d.numeric, top_3_coins.text FROM narrative_info ORDER BY market_cap.numeric DESC LIMIT 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE narrative_info ( narrative.text, top_3_coins.text, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, market_cap.numeric, volume_24h.numeric, trend_rank.numeric, token_num.numeric )\n"} {"conversations": [{"content": "For each route that originates from a location of type 'Port', list the route number, the name of the origin location, and the total distance accumulated from all completed trips on this route.", "role": "user"}, {"content": "SELECT\n r.route_number,\n l_origin.name AS origin_location_name,\n SUM(t.distance_km) AS total_accumulated_distance\nFROM transportation.routes AS r\nJOIN transportation.locations AS l_origin\n ON r.origin_location_id = l_origin.location_id\nJOIN transportation.trips AS t\n ON r.route_id = t.route_id\nWHERE\n l_origin.type = 'Port' AND t.status = 'Completed'\nGROUP BY\n r.route_id,\n r.route_number,\n l_origin.name;", "role": "assistant"}, {"content": "Now, only include routes where the accumulated distance is greater than 5000 kilometers and order the results by accumulated distance descending.", "role": "user"}, {"content": "SELECT\n r.route_number,\n l_origin.name AS origin_location_name,\n SUM(t.distance_km) AS total_accumulated_distance\nFROM transportation.routes AS r\nJOIN transportation.locations AS l_origin\n ON r.origin_location_id = l_origin.location_id\nJOIN transportation.trips AS t\n ON r.route_id = t.route_id\nWHERE\n l_origin.type = 'Port' AND t.status = 'Completed'\nGROUP BY\n r.route_id,\n r.route_number,\n l_origin.name\nHAVING\n SUM(t.distance_km) > 5000\nORDER BY\n total_accumulated_distance DESC;", "role": "assistant"}, {"content": "Also include the number of completed trips for each of these routes and filter further to only show routes that have had more than 5 completed trips.", "role": "user"}, {"content": "SELECT\n r.route_number,\n l_origin.name AS origin_location_name,\n SUM(t.distance_km) AS total_accumulated_distance,\n COUNT(t.trip_id) AS completed_trip_count\nFROM transportation.routes AS r\nJOIN transportation.locations AS l_origin\n ON r.origin_location_id = l_origin.location_id\nJOIN transportation.trips AS t\n ON r.route_id = t.route_id\nWHERE\n l_origin.type = 'Port' AND t.status = 'Completed'\nGROUP BY\n r.route_id,\n r.route_number,\n l_origin.name\nHAVING\n SUM(t.distance_km) > 5000 AND COUNT(t.trip_id) > 5\nORDER BY\n total_accumulated_distance DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE 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 )\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE transportation.maintenance_logs ( log_id text PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\nCREATE TABLE transportation.bookings ( booking_id text PRIMARY KEY, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n"} {"conversations": [{"content": "List all appointments scheduled in the next 30 days with appointment_id, client_id, case_id, and any invoice_id linked to that case.", "role": "user"}, {"content": "SELECT\n a.appointment_id,\n a.client_id,\n a.case_id,\n i.invoice_id\nFROM legal_services.appointments AS a\nLEFT JOIN legal_services.invoices AS i\n ON a.case_id = i.case_id\nWHERE a.start_time BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days';", "role": "assistant"}, {"content": "Change to include only appointments with status 'Scheduled' and invoices that are not fully paid.", "role": "user"}, {"content": "SELECT\n a.appointment_id,\n a.client_id,\n a.case_id,\n i.invoice_id\nFROM legal_services.appointments AS a\nLEFT JOIN legal_services.invoices AS i\n ON a.case_id = i.case_id\nWHERE a.start_time BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days'\n AND a.status = 'Scheduled'\n AND (i.status IS NULL OR i.status <> 'Paid');", "role": "assistant"}, {"content": "Also include only those where the case_type is 'Corporate'.", "role": "user"}, {"content": "SELECT\n a.appointment_id,\n a.client_id,\n a.case_id,\n i.invoice_id\nFROM legal_services.appointments AS a\nJOIN legal_services.cases AS c\n ON a.case_id = c.case_id\nLEFT JOIN legal_services.invoices AS i\n ON a.case_id = i.case_id\nWHERE a.start_time BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days'\n AND a.status = 'Scheduled'\n AND (i.status IS NULL OR i.status <> 'Paid')\n AND c.case_type = 'Corporate';", "role": "assistant"}, {"content": "Finally, order by start_time ascending and return only the first 10 rows.", "role": "user"}, {"content": "SELECT\n a.appointment_id,\n a.client_id,\n a.case_id,\n i.invoice_id\nFROM legal_services.appointments AS a\nJOIN legal_services.cases AS c\n ON a.case_id = c.case_id\nLEFT JOIN legal_services.invoices AS i\n ON a.case_id = i.case_id\nWHERE a.start_time BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days'\n AND a.status = 'Scheduled'\n AND (i.status IS NULL OR i.status <> 'Paid')\n AND c.case_type = 'Corporate'\nORDER BY a.start_time ASC\nLIMIT 10;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE TABLE legal_services.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n"} {"conversations": [{"content": "List all posts where the content mentions 'meeting'.", "role": "user"}, {"content": "SELECT post_id, user_id, content, created_at FROM social_media.posts WHERE content LIKE '%meeting%'", "role": "assistant"}, {"content": "Also, only include those posts that are public.", "role": "user"}, {"content": "SELECT post_id, user_id, content, created_at FROM social_media.posts WHERE content LIKE '%meeting%' AND visibility = 'public'", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\n"} {"conversations": [{"content": "Show me all customers who have missing contact information (either phone number or email is null), along with their state and city.", "role": "user"}, {"content": "SELECT first_name, last_name, state, city FROM insurance.customers WHERE phone_number IS NULL OR email IS NULL;", "role": "assistant"}, {"content": "Now filter these to only show customers from Florida or New York who were created in the last 2 years.", "role": "user"}, {"content": "SELECT first_name, last_name, state, city FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '2 years';", "role": "assistant"}, {"content": "I also want to see when these customers were last updated (updated_at field).", "role": "user"}, {"content": "SELECT first_name, last_name, state, city, updated_at FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '2 years';", "role": "assistant"}, {"content": "Finally, order the results by state first, then by the most recently updated customers first.", "role": "user"}, {"content": "SELECT first_name, last_name, state, city, updated_at FROM insurance.customers WHERE (phone_number IS NULL OR email IS NULL) AND state IN ('Florida', 'New York') AND created_at >= CURRENT_DATE - INTERVAL '2 years' ORDER BY state ASC, updated_at DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\n"} {"conversations": [{"content": "Show me all business center services (category = 'Business Center') along with their property IDs and descriptions, where the service is available.", "role": "user"}, {"content": "SELECT service_name, property_id, description FROM hospitality_technology.services WHERE category = 'Business Center' AND is_available = true;", "role": "assistant"}, {"content": "Now, join this with another query to include the property names from the properties table (assuming properties table has property_id and property_name columns).", "role": "user"}, {"content": "SELECT s.service_name, s.property_id, p.property_name, s.description FROM hospitality_technology.services s JOIN hospitality_technology.properties p ON s.property_id = p.property_id WHERE s.category = 'Business Center' AND s.is_available = true;", "role": "assistant"}, {"content": "The query is missing the price information. Can you include that as well?", "role": "user"}, {"content": "SELECT s.service_name, s.property_id, p.property_name, s.description, s.price FROM hospitality_technology.services s JOIN hospitality_technology.properties p ON s.property_id = p.property_id WHERE s.category = 'Business Center' AND s.is_available = true;", "role": "assistant"}, {"content": "Actually, I need to see only services priced per hour (unit = 'Per Hour'), and order them by property name in alphabetical order.", "role": "user"}, {"content": "SELECT s.service_name, s.property_id, p.property_name, s.description, s.price FROM hospitality_technology.services s JOIN hospitality_technology.properties p ON s.property_id = p.property_id WHERE s.category = 'Business Center' AND s.is_available = true AND s.unit = 'Per Hour' ORDER BY p.property_name ASC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\n"} {"conversations": [{"content": "Show me all maintenance logs for 'Oil Change' services performed in the last 3 months, including the vehicle ID, service date, and cost.", "role": "user"}, {"content": "SELECT vehicle_id, service_date, cost FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months';", "role": "assistant"}, {"content": "Can you also include the mechanic name and filter to only show services that cost more than $100?", "role": "user"}, {"content": "SELECT vehicle_id, service_date, cost, mechanic_name FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100;", "role": "assistant"}, {"content": "Now order these results by service date with the most recent first and limit to 10 records.", "role": "user"}, {"content": "SELECT vehicle_id, service_date, cost, mechanic_name FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100 ORDER BY service_date DESC LIMIT 10;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\n"} {"conversations": [{"content": "What is the fuel efficiency of the train car with car_id 'TC456'?", "role": "user"}, {"content": "I'm sorry, but I don't have access to information about the fuel efficiency of specific train cars. The data available in the train_cars table only includes details such as car_id, train_id, car_number, car_type, class, capacity, and features. If you have another question or need assistance with something else, I'm happy to help.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.train_cars ( car_id.text, train_id.text, car_number.text, car_type.text, class.text, capacity.integer, features.text )\n"} {"conversations": [{"content": "How many policies were canceled in the previous month, grouped by cancellation reason?", "role": "user"}, {"content": "SELECT cancellation_reason,\n COUNT(*) AS canceled_count\nFROM insurance.policies\nWHERE cancellation_date BETWEEN date_trunc('month', CURRENT_DATE) - INTERVAL '1 month'\n AND date_trunc('month', CURRENT_DATE) - INTERVAL '1 day'\nGROUP BY cancellation_reason;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\n"} {"conversations": [{"content": "List each guest\u2019s full name and the total number of service orders they have placed, ordered by order count descending.", "role": "user"}, {"content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n COUNT(so.order_id) AS order_count\nFROM hospitality_technology.guests g\nLEFT JOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nGROUP BY g.guest_id, full_name\nORDER BY order_count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE 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 )\nCREATE 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) )\n"} {"conversations": [{"content": "List all managers (employees who have other employees reporting to them) along with the count of their direct reports, showing only those with more than 5 reports.", "role": "user"}, {"content": "SELECT e.employee_id, e.first_name, e.last_name, COUNT(r.employee_id) as direct_reports_count FROM financial_services.employees e JOIN financial_services.employees r ON e.employee_id = r.manager_id WHERE e.status = 'Active' GROUP BY e.employee_id, e.first_name, e.last_name HAVING COUNT(r.employee_id) > 5 ORDER BY direct_reports_count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n"} {"conversations": [{"content": "Can you list the number of citizens registered each month in 2024? Please show the month and the citizen count.", "role": "user"}, {"content": "SELECT TO_CHAR(registration_date, 'YYYY-MM') AS registration_month, COUNT(*) AS citizen_count FROM government_services.citizens WHERE registration_date >= '2024-01-01' AND registration_date < '2025-01-01' GROUP BY registration_month ORDER BY registration_month;", "role": "assistant"}, {"content": "Now, can you also show the number of verified citizens for each month?", "role": "user"}, {"content": "SELECT TO_CHAR(registration_date, 'YYYY-MM') AS registration_month, COUNT(*) AS citizen_count, SUM(CASE WHEN is_verified = true THEN 1 ELSE 0 END) AS verified_citizen_count FROM government_services.citizens WHERE registration_date >= '2024-01-01' AND registration_date < '2025-01-01' GROUP BY registration_month ORDER BY registration_month;", "role": "assistant"}, {"content": "I see some months with zero verified citizens, but they still show up. Can you exclude months with zero verified citizens from the result?", "role": "user"}, {"content": "SELECT registration_month, citizen_count, verified_citizen_count FROM (SELECT TO_CHAR(registration_date, 'YYYY-MM') AS registration_month, COUNT(*) AS citizen_count, SUM(CASE WHEN is_verified = true THEN 1 ELSE 0 END) AS verified_citizen_count FROM government_services.citizens WHERE registration_date >= '2024-01-01' AND registration_date < '2025-01-01' GROUP BY registration_month) sub WHERE verified_citizen_count > 0 ORDER BY registration_month;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, 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, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\n"} {"conversations": [{"content": "What are the safety ratings or crash statistics for the Boeing 787 Dreamliner?", "role": "user"}, {"content": "I'm sorry, but I don't have access to safety ratings or crash statistics for specific aircraft models like the Boeing 787 Dreamliner. My data is limited to the information in the aircraft_models table, which includes details such as model name, manufacturer, passenger capacity, and technical specifications. For safety-related information, I recommend consulting official aviation authorities or safety reports.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.aircraft_models ( model_id text, model_name text, manufacturer text, passenger_capacity integer, max_range_km integer, engine_type text, wingspan_m numeric, status text, first_flight_date date )\n"} {"conversations": [{"content": "What is the performance review score for employee with ID 'EMP456' for the last quarter?", "role": "user"}, {"content": "I'm sorry, but I can't assist with information about performance review scores as this data is not included in the employees table.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(128) NOT NULL, skill_certifications text, hire_date date NOT NULL, assigned_line_id character varying(64), employment_status character varying(50) NOT NULL, supervisor_employee_id character varying(64), PRIMARY KEY (employee_id) )\n"} {"conversations": [{"content": "Can you show me the total number of passengers registered in the database?", "role": "user"}, {"content": "db.passengers.countDocuments({})", "role": "assistant"}], "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. \n##Table Structure\n// db.createCollection('passengers')\n// Optional: db.passengers.createIndex({ passenger_id: 1 }, { unique: true })\n// Optional: db.passengers.createIndex({ email: 1 }, { unique: true, sparse: true })\n// Optional: db.passengers.createIndex({ phone_number: 1 }, { unique: true, sparse: true })\n{\n _id: ObjectId(),\n passenger_id: \"pass_pqr\", // String (unique)\n first_name: \"Alice\", // String\n last_name: \"Smith\", // String\n email: \"alice.smith@example.com\", // String (unique, sparse)\n phone_number: \"+15551234567\", // String (unique, sparse)\n date_of_birth: ISODate(\"1990-03-20\"), // Date\n loyalty_program_id: \"LOYALTY123\", // String\n created_at: ISODate(\"2023-02-01T11:00:00Z\") // Date\n}\n"} {"conversations": [{"content": "What is the current location of train number Acela 2151?", "role": "user"}, {"content": "I'm sorry, but I don't have access to real-time location data for trains. The database only contains static information such as train ID, model, capacity, and maintenance schedules. For current location updates, please check with the train operator or a tracking service.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.trains (\n train_id character varying(64) NOT NULL, -- Unique identifier for the train set\n train_number character varying(32) NOT NULL, -- Operational number of the train (e.g., 'Acela 2151')\n model character varying(128), -- Model of the train (e.g., 'Siemens Velaro')\n manufacturer character varying(128), -- Manufacturer of the train\n year_manufactured integer, -- Year the train was built\n capacity integer NOT NULL, -- Total passenger capacity\n status character varying(32) NOT NULL DEFAULT 'Active', -- e.g., Active, Maintenance, Retired\n last_maintenance_date date, -- Date of last scheduled maintenance\n next_maintenance_date date, -- Date of next scheduled maintenance\n PRIMARY KEY (train_id),\n UNIQUE (train_number)\n)\n"} {"conversations": [{"content": "What is the average speed of train number T9876 during its last journey?", "role": "user"}, {"content": "I'm sorry, but I can't provide information on the average speed of train number T9876 during its last journey. The data in the trains table does not include details about travel speed or journey-specific performance metrics.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.trains ( train_id.text, train_number.text, model.text, manufacturer.text, year_manufactured.integer, capacity.integer, status.text, last_maintenance_date.date, next_maintenance_date.date )\n"} {"conversations": [{"content": "What is the current market price of a Boeing 737 MAX aircraft?", "role": "user"}, {"content": "I'm sorry, but I don't have access to the current market price of aircraft models. The data I have is limited to technical specifications and general information about aircraft models such as passenger capacity, range, and status. For pricing information, you may need to consult with manufacturers or industry reports.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.aircraft_models (\n model_id character varying(64) NOT NULL, -- unique identifier for the aircraft model\n model_name character varying(128) NOT NULL, -- commercial name of the model (e.g., 737 MAX, A320neo)\n manufacturer character varying(128) NOT NULL, -- manufacturer name (e.g., Boeing, Airbus)\n passenger_capacity integer, -- typical passenger capacity\n max_range_km integer, -- maximum flight range in kilometers\n engine_type character varying(100), -- type of engines used\n wingspan_m numeric(6,2), -- wingspan in meters\n status character varying(50) NOT NULL, -- e.g., 'In Production', 'Development', 'Discontinued'\n first_flight_date date, -- date of the model's first flight\n PRIMARY KEY (model_id)\n)\n"} {"conversations": [{"content": "For each vehicle, list its vehicle_id, license_plate, and any older vehicle of the same type (showing older_vehicle_id and older year).", "role": "user"}, {"content": "SELECT cur.vehicle_id,\n cur.license_plate,\n old.vehicle_id AS older_vehicle_id,\n old.year AS older_vehicle_year\nFROM transportation.vehicles cur\nJOIN transportation.vehicles old\n ON cur.type = old.type\n AND old.year < cur.year\nORDER BY cur.vehicle_id, old.year DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\n"} {"conversations": [{"content": "For each claim, show the corresponding product_type of the insurance product for the related policy.", "role": "user"}, {"content": "SELECT cl.claim_id, ip.product_type\nFROM insurance.claims cl\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id;", "role": "assistant"}, {"content": "Sorry, there is no policies table, I got an error. Can you try joining claims to insurance_products another way?", "role": "user"}, {"content": "-- Unable to join directly since there is no 'policies' table connecting claims to insurance_products. If policy_id equals product_id, you may try:\nSELECT claim_id, policy_id, product_type\nFROM insurance.claims\nJOIN insurance.insurance_products ON claims.policy_id = insurance_products.product_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )\nCREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )\n"} {"conversations": [{"content": "Find appointments that are longer than 30 minutes.", "role": "user"}, {"content": "SELECT * FROM legal_services.appointments WHERE end_time IS NOT NULL AND start_time IS NOT NULL AND end_time > start_time + INTERVAL '30 minutes'", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "How many lawyers who are partners were hired in each year? Show the hire year and the count.", "role": "user"}, {"content": "SELECT strftime('%Y', hire_date) AS hire_year , count(lawyer_id) FROM legal_services.lawyers WHERE is_partner = true GROUP BY hire_year", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n"} {"conversations": [{"content": "List all users whose email contains the word 'block', along with their username and registration timestamp.", "role": "user"}, {"content": "SELECT user_id, username, email, created_at\nFROM web3.users\nWHERE email ILIKE '%block%';", "role": "assistant"}, {"content": "Can you also include the total number of such users in the result?", "role": "user"}, {"content": "SELECT user_id, username, email, created_at, COUNT(*) OVER() AS total_matching_users\nFROM web3.users\nWHERE email ILIKE '%block%';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} {"conversations": [{"content": "For each event recorded, list its ID, name, and the status and value of the transaction in which it occurred.", "role": "user"}, {"content": "SELECT E.event_id, E.event_name, E.transaction_id, T.status, T.value FROM web3.events AS E JOIN web3.transactions AS T ON E.transaction_id = T.transaction_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\nCREATE 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) )\nCREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} {"conversations": [{"content": "List all claims along with the first and last names of the agent who is currently handling each claim.", "role": "user"}, {"content": "SELECT c.claim_id, c.policy_id, c.incident_date, a.first_name AS agent_first_name, a.last_name AS agent_last_name\nFROM insurance.claims c\nJOIN insurance.agents a ON c.claim_handler_id = a.agent_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )\n"} {"conversations": [{"content": "List tokens with trend rank 5 or better and a price below $1. Show symbol, price, and trend rank.", "role": "user"}, {"content": "SELECT token_symbol, price, trend_rank FROM token_dexpool_info WHERE trend_rank IS NOT NULL AND trend_rank <= 5 AND price < 1;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n"} {"conversations": [{"content": "I need to find all bookings for a specific schedule with schedule_id 'sched_1122' and include the passenger and ticket details.", "role": "user"}, {"content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGETALL ticket:tkt_*", "role": "assistant"}, {"content": "Can you filter the tickets to show only those that are not checked in?", "role": "user"}, {"content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nENDIF", "role": "assistant"}, {"content": "Can you also include the car details for each ticket?", "role": "user"}, {"content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nHGET ticket:tkt_* car_id\nHGETALL car:car_*\nENDIF", "role": "assistant"}], "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. \n##Table Structure\n// Use Hashes for platform details. Key format: platform:\n// HSET platform:plat_123 platform_id \"plat_123\" station_id \"station_xyz\" platform_number \"1A\" track_number \"T1\" status \"Operational\" length_meters 250.50 accessible 1\n\n// To link platforms to stations (optional):\n// SADD station:station_xyz:platforms platform:plat_123 platform:plat_456\n// Use Hashes for train details. Key format: train:\n// HSET train:train_789 train_id \"train_789\" train_number \"Acela 2151\" model \"Siemens Velaro\" ... status \"Active\" ...\n\n// To find train by train_number (optional index):\n// SET train_number:\"Acela 2151\" train:train_789\n// Use Hashes for car details. Key format: car:\n// HSET car:car_abc car_id \"car_abc\" train_id \"train_789\" car_number \"C3\" car_type \"Passenger\" class \"Business\" capacity 60 features \"WiFi,Power Outlet\"\n\n// To link cars to trains (optional):\n// SADD train:train_789:cars car:car_abc car:car_def\n// Use Hashes for details. Key format: route_station:\n// HSET route_station:rs_ne_1 route_station_id \"rs_ne_1\" route_id \"route_ne_corr\" station_id \"station_bos\" sequence_order 1 ...\n\n// To find stops for a route, use a Sorted Set (score by sequence_order):\n// ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1\n// ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2\n// Use Hashes for schedule details. Key format: schedule:\n// HSET schedule:sched_1122 schedule_id \"sched_1122\" train_id \"train_789\" route_id \"route_ne_corr\" departure_datetime \"2024-05-10T08:00:00-04:00\" ... status \"Scheduled\"\n// Use Hashes for details. Key format: schedule_stop:\n// HSET schedule_stop:stop_sched1122_1 stop_id \"stop_sched1122_1\" schedule_id \"sched_1122\" station_id \"station_bos\" ...\n\n// To find stops for a schedule, use a Sorted Set (score by sequence_order):\n// ZADD schedule:sched_1122:stops 1 schedule_stop:stop_sched1122_1\n// ZADD schedule:sched_1122:stops 2 schedule_stop:stop_sched1122_2\n// Use Hashes for passenger details. Key format: passenger:\n// HSET passenger:pass_pqr passenger_id \"pass_pqr\" first_name \"Alice\" last_name \"Smith\" email \"alice.smith@example.com\" ...\n\n// To find passenger by email (optional index):\n// SET passenger_email:\"alice.smith@example.com\" passenger:pass_pqr\n// Use Hashes for booking details. Key format: booking:\n// HSET booking:book_zyx booking_id \"book_zyx\" passenger_id \"pass_pqr\" schedule_id \"sched_1122\" ... status \"Confirmed\" ...\n\n// To link bookings to passengers/schedules (optional):\n// SADD passenger:pass_pqr:bookings booking:book_zyx\n// SADD schedule:sched_1122:bookings booking:book_zyx\n// Use Hashes for ticket details. Key format: ticket:\n// HSET ticket:tkt_1a2b ticket_id \"tkt_1a2b\" booking_id \"book_zyx\" car_id \"car_abc\" seat_number \"12A\" ... is_checked_in 0 ...\n\n// To link tickets to bookings (optional):\n// SADD booking:book_zyx:tickets ticket:tkt_1a2b\n// Use Hashes for staff details. Key format: staff:\n// HSET staff:staff_mno staff_id \"staff_mno\" first_name \"Bob\" ... employee_number \"E12345\" ... is_active 1\n\n// To find staff by employee number (optional index):\n// SET staff_employee_number:\"E12345\" staff:staff_mno\n// Use Hashes for maintenance record details. Key format: maintenance_record:\n// HSET maintenance_record:maint_rec_001 record_id \"maint_rec_001\" asset_id \"train_789\" asset_type \"Train\" ... status \"Completed\"\n\n// To link records to assets (optional):\n// SADD train:train_789:maintenance maintenance_record:maint_rec_001\n// SADD platform:plat_123:maintenance maintenance_record:maint_rec_002\n"} {"conversations": [{"content": "Show a list of all fuel refueling events for each trip, including the trip ID, fuel type, quantity, total cost, and the name of the refueling location.", "role": "user"}, {"content": "SELECT fl.trip_id, fl.fuel_type, fl.quantity, fl.total_cost, l.name AS location_name\nFROM transportation.fuel_logs fl\nJOIN transportation.locations l ON fl.location_id = l.location_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE 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 )\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE 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 )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n"} {"conversations": [{"content": "List the names of employees and the agency they work for who have scheduled at least one appointment. Show the employee's first name, last name, and agency_id.", "role": "user"}, {"content": "SELECT DISTINCT e.first_name, e.last_name, e.agency_id\nFROM government_services.employees e\nJOIN government_services.appointments a ON e.employee_id = a.employee_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE 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 )\nCREATE TABLE government_services.notifications ( notification_id text, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n"} {"conversations": [{"content": "Show me the count of service orders for each distinct status.", "role": "user"}, {"content": "SELECT status, COUNT(order_id) FROM hospitality_technology.service_orders GROUP BY status;", "role": "assistant"}, {"content": "Also, include the total quantity of items ordered for each status.", "role": "user"}, {"content": "SELECT status, COUNT(order_id), SUM(quantity) FROM hospitality_technology.service_orders GROUP BY status;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n"} {"conversations": [{"content": "List game titles released on the 'PC' platform along with the count of servers currently hosting each game.", "role": "user"}, {"content": "SELECT T1.title, count(T2.server_id) FROM games AS T1 JOIN servers AS T2 ON T1.game_id = T2.game_id WHERE T1.platform = 'PC' GROUP BY T1.title;", "role": "assistant"}, {"content": "Now, only show games with more than 3 servers and sort the results by the server count in descending order.", "role": "user"}, {"content": "SELECT T1.title, count(T2.server_id) AS server_count FROM games AS T1 JOIN servers AS T2 ON T1.game_id = T2.game_id WHERE T1.platform = 'PC' GROUP BY T1.title HAVING count(T2.server_id) > 3 ORDER BY server_count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory (\n inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry\n player_id uuid NOT NULL, -- FK linking to the player owning the item\n item_id uuid NOT NULL, -- FK linking to the item definition\n quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)\n acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired\n instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)\n PRIMARY KEY (inventory_id),\n -- Optional unique constraint if items are non-stackable or unique instances\n -- UNIQUE (player_id, item_id) -- Use if quantity is always 1\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)\n)\n"} {"conversations": [{"content": "List the full names and email addresses of staff members who have delivered at least one service order in the past 30 days, along with the count of orders they delivered. Sort by count descending.", "role": "user"}, {"content": "SELECT st.staff_id,\n st.first_name || ' ' || st.last_name AS full_name,\n st.work_email,\n COUNT(so.order_id) AS delivered_count\nFROM hospitality_technology.staff st\nJOIN hospitality_technology.service_orders so\n ON st.staff_id = so.staff_id_delivered\nWHERE so.status = 'Delivered'\n AND so.delivery_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY st.staff_id, st.first_name, st.last_name, st.work_email\nORDER BY delivered_count DESC;", "role": "assistant"}, {"content": "Actually, only include staff who delivered more than 5 orders in that period.", "role": "user"}, {"content": "SELECT st.staff_id,\n st.first_name || ' ' || st.last_name AS full_name,\n st.work_email,\n COUNT(so.order_id) AS delivered_count\nFROM hospitality_technology.staff st\nJOIN hospitality_technology.service_orders so\n ON st.staff_id = so.staff_id_delivered\nWHERE so.status = 'Delivered'\n AND so.delivery_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY st.staff_id, st.first_name, st.last_name, st.work_email\nHAVING COUNT(so.order_id) > 5\nORDER BY delivered_count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.staff ( staff_id text, 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 integer, manager_id text, created_at timestamp )\nCREATE 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 )\n"} {"conversations": [{"content": "Show me the number of distinct room types offered by each property, including the property name and the count.", "role": "user"}, {"content": "SELECT T1.property_name, COUNT(DISTINCT T2.room_type_id) FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id GROUP BY T1.property_id;", "role": "assistant"}, {"content": "Now, only show properties that offer more than 5 distinct room types.", "role": "user"}, {"content": "SELECT T1.property_name, COUNT(DISTINCT T2.room_type_id) FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id GROUP BY T1.property_id HAVING COUNT(DISTINCT T2.room_type_id) > 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, property_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )\nCREATE 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) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE 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 )\nCREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n"} {"conversations": [{"content": "List all rooms, including their room number, the name of the property they belong to, and their room type name, specifically for rooms with 'Maintenance' status.", "role": "user"}, {"content": "SELECT T1.room_number, T2.property_name, T3.type_name FROM rooms AS T1 JOIN properties AS T2 ON T1.property_id = T2.property_id JOIN room_types AS T3 ON T1.room_type_id = T3.room_type_id WHERE T1.status = 'Maintenance'", "role": "assistant"}, {"content": "Also include the floor number and filter to only show rooms located on floors 5 or higher. Sort the results by property name and then by floor.", "role": "user"}, {"content": "SELECT T1.room_number, T2.property_name, T3.type_name, T1.floor FROM rooms AS T1 JOIN properties AS T2 ON T1.property_id = T2.property_id JOIN room_types AS T3 ON T1.room_type_id = T3.room_type_id WHERE T1.status = 'Maintenance' AND T1.floor >= 5 ORDER BY T2.property_name, T1.floor", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\n"} {"conversations": [{"content": "Can you narrow this down to only show cases where the case type is 'Criminal'?", "role": "user"}, {"content": "SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE lead_lawyer_id = 'lawyer_abc' AND status = 'Open' AND case_type = 'Criminal';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "Find all users who registered with a Yahoo email address, along with their registration dates.", "role": "user"}, {"content": "SELECT user_id, username, email, password_hash FROM blockchain.users WHERE email LIKE '%@yahoo.com';", "role": "assistant"}, {"content": "This query doesn't show registration dates. Can you modify it to include the registration date?", "role": "user"}, {"content": "I notice the users table doesn't have a registration date column. Would you like me to show other available information from the users table?", "role": "assistant"}, {"content": "Then just show me the count of Yahoo email users instead.", "role": "user"}, {"content": "SELECT COUNT(*) as yahoo_user_count FROM blockchain.users WHERE email LIKE '%@yahoo.com';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer )\nCREATE TABLE blockchain.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n block_id character varying(64) NOT NULL, -- identifier of the block containing the transaction\n sender_address character varying(128) NOT NULL, -- address of the sender\n receiver_address character varying(128) NOT NULL, -- address of the receiver\n amount numeric(38,14) NOT NULL, -- amount transferred\n timestamp timestamp NOT NULL, -- time when the transaction was created\n signature text NOT NULL, -- digital signature of the transaction\n PRIMARY KEY (transaction_id)\n)\nCREATE TABLE blockchain.addresses ( address_id text PRIMARY KEY, public_key text, balance numeric )\nCREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) )\n"} {"conversations": [{"content": "Show the full names and contact emails of all citizens who have applied for services with a standard fee greater than 100.", "role": "user"}, {"content": "SELECT c.first_name || ' ' || c.last_name AS full_name, c.contact_email\nFROM government_services.citizens c\nJOIN government_services.services s ON c.citizen_id IS NOT NULL -- Replace with actual application linking table if exists\nWHERE s.standard_fee > 100;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, 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, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.services ( service_id.text, agency_id.text, service_name.text, description.text, category.text, eligibility_criteria.text, standard_fee.numeric, average_processing_time_days.integer, is_active.boolean, online_application_url.text )\n"} {"conversations": [{"content": "List all invoices that were paid within 7 days of their issue date. Show invoice number, issue date, payment date, and total amount.", "role": "user"}, {"content": "SELECT invoice_number, issue_date, payment_date, total_amount FROM legal_services.invoices WHERE status = 'Paid' AND payment_date IS NOT NULL AND (payment_date::DATE - issue_date) <= 7;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE 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 )\n"} {"conversations": [{"content": "Count the number of trips for each route type.", "role": "user"}, {"content": "SELECT R.type, COUNT(T.trip_id) FROM transportation.trips AS T JOIN transportation.routes AS R ON T.route_id = R.route_id GROUP BY R.type;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n"} {"conversations": [{"content": "For each asset, calculate the total quantity and average price of orders that have status 'filled'.", "role": "user"}, {"content": "SELECT o.asset_id,\n SUM(o.quantity) AS total_quantity,\n AVG(o.price) AS average_price\nFROM trading_platform.orders o\nWHERE o.status = 'filled'\nGROUP BY o.asset_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE trading_platform.orders (\n order_id character varying(64) NOT NULL, -- unique identifier for the order\n user_id character varying(64) NOT NULL, -- identifier of the user placing the order\n wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)\n created_at timestamp NOT NULL, -- time when the order was created\n PRIMARY KEY (order_id)\n)\nCREATE TABLE trading_platform.assets (\n asset_id character varying(64) NOT NULL, -- unique identifier for the asset\n name character varying(128) NOT NULL, -- name of the asset\n symbol character varying(32) NOT NULL, -- symbol of the asset\n type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)\n PRIMARY KEY (asset_id)\n)\nCREATE TABLE trading_platform.utxos (\n utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO\n output_index integer NOT NULL, -- index of the output in the transaction\n address character varying(128) NOT NULL, -- address that can spend the UTXO\n amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO\n spent boolean NOT NULL, -- whether the UTXO has been spent\n PRIMARY KEY (utxo_id)\n)\nCREATE TABLE trading_platform.dapps (\n dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp\n name character varying(128) NOT NULL, -- name of the DApp\n description text NOT NULL, -- description of the DApp\n url character varying(256) NOT NULL, -- URL of the DApp\n PRIMARY KEY (dapp_id)\n)\nCREATE TABLE trading_platform.peers (\n peer_id character varying(64) NOT NULL, -- unique identifier for the peer\n ip_address character varying(15) NOT NULL, -- IP address of the peer\n port integer NOT NULL, -- port number of the peer\n last_seen timestamp NOT NULL, -- last time the peer was active\n PRIMARY KEY (peer_id)\n)\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\nCREATE TABLE trading_platform.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n user_id character varying(64) NOT NULL, -- identifier of the user receiving the notification\n message text NOT NULL, -- message of the notification\n sent_at timestamp NOT NULL, -- time when the notification was sent\n read_at timestamp, -- time when the notification was read\n PRIMARY KEY (notification_id)\n)\n"} {"conversations": [{"content": "Show me each service order along with the next order placed by the same guest, including both order IDs and the time difference in minutes between the two orders.", "role": "user"}, {"content": "SELECT a.order_id,\n b.order_id AS next_order_id,\n EXTRACT(EPOCH FROM (b.order_timestamp - a.order_timestamp)) / 60 AS diff_minutes\nFROM hospitality_technology.service_orders a\nJOIN hospitality_technology.service_orders b\n ON a.guest_id = b.guest_id\n AND b.order_timestamp > a.order_timestamp;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "Show me the top 5 projects by valuation that completed fundraising rounds in the last 12 months, along with their token symbol and price from the token_basic_info table.", "role": "user"}, {"content": "SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) ORDER BY pfr.valuation DESC LIMIT 5;", "role": "assistant"}, {"content": "Can you also include the 24-hour trading volume for these projects' tokens and filter to only include projects with valuation over $100 million?", "role": "user"}, {"content": "SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price, tbi.total_volume FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) AND pfr.valuation > 100000000 ORDER BY pfr.valuation DESC LIMIT 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE project_fundraising_record (\",\n \"id character varying(32) NOT NULL, -- fundraising record id\",\n \"project_id character varying(32) NOT NULL, -- the invested project's id\",\n \"project_name character varying(128) NOT NULL, -- name of the invested project\",\n \"rounds_name character varying(32), -- name of the fundraising round\",\n \"investment_value numeric(38,14), -- amount of the fundraising in USD\",\n \"investment_date character varying(128), -- the date of the investment happened\",\n \"introduction character varying(128), -- the introduction of the invested project\",\n \"valuation numeric(38,14), -- the valuation of the project in USD when invested\",\n\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\nCREATE 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 )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )\n \"CREATE TABLE smart_money_token_performance (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"pnl numeric(38,2), -- the profit users made on this token\",\n \"net_flow numeric(38,2), -- the netflow of the token, means the money user spent minus the the money user sold of this token\",\n \"avg_cost numeric(38,16), -- the average cost price of user spent on this token\",\n \"price double precision, -- the current price of the token\",\n \"realized_ratio numeric(10,2), -- the ratio user sold of the token\",\n \"roi numeric(10,2), -- the roi users made of this token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \"PRIMARY KEY (token_address, chain));\",\n\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n"} {"conversations": [{"content": "Can you show, for each employee, the full name and job title of their direct manager, as well as the employee's department and branch_id?", "role": "user"}, {"content": "SELECT e.employee_id, e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.department AS employee_department, e.branch_id AS employee_branch_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name, m.job_title AS manager_job_title\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id;", "role": "assistant"}, {"content": "Actually, show only employees who have a manager assigned, and include only those where the manager works at a different branch than the employee.", "role": "user"}, {"content": "SELECT e.employee_id, e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.department AS employee_department, e.branch_id AS employee_branch_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name, m.job_title AS manager_job_title, m.branch_id AS manager_branch_id\nFROM financial_services.employees e\nINNER JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.branch_id IS DISTINCT FROM m.branch_id;", "role": "assistant"}, {"content": "Now, only include employees who were hired after 2021-01-01.", "role": "user"}, {"content": "SELECT e.employee_id, e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.department AS employee_department, e.branch_id AS employee_branch_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name, m.job_title AS manager_job_title, m.branch_id AS manager_branch_id\nFROM financial_services.employees e\nINNER JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.branch_id IS DISTINCT FROM m.branch_id\n AND e.hire_date > '2021-01-01';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE 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 )\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\nCREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )\n"} {"conversations": [{"content": "List all medical records, showing the record ID, record date, and the full name of the doctor who created the record. Include the patient ID as well.", "role": "user"}, {"content": "SELECT mr.record_id, mr.record_date, mr.patient_id, d.first_name, d.last_name FROM healthcare.medical_records mr JOIN doctors d ON mr.doctor_id = d.doctor_id;", "role": "assistant"}, {"content": "Refine this to only include records where the chief_complaint is not null or empty and the doctor's specialty is 'Cardiology'.", "role": "user"}, {"content": "SELECT mr.record_id, mr.record_date, mr.patient_id, d.first_name, d.last_name FROM healthcare.medical_records mr JOIN doctors d ON mr.doctor_id = d.doctor_id WHERE (mr.chief_complaint IS NOT NULL AND mr.chief_complaint != '') AND d.specialty = 'Cardiology';", "role": "assistant"}, {"content": "Also, sort the results by record_date in descending order and limit the output to the top 10 records.", "role": "user"}, {"content": "SELECT mr.record_id, mr.record_date, mr.patient_id, d.first_name, d.last_name FROM healthcare.medical_records mr JOIN doctors d ON mr.doctor_id = d.doctor_id WHERE (mr.chief_complaint IS NOT NULL AND mr.chief_complaint != '') AND d.specialty = 'Cardiology' ORDER BY mr.record_date DESC LIMIT 10;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\n"} {"conversations": [{"content": "For projects that have completed more than one fundraising round, calculate the average investment value across all their recorded rounds. Display the project name and this average value.", "role": "user"}, {"content": "SELECT project_name, AVG(investment_value) AS average_investment FROM project_fundraising_record GROUP BY project_name HAVING COUNT(*) > 1;", "role": "assistant"}, {"content": "Can you modify this to only show projects where the average investment value is greater than 10 million USD and order the results by average investment value descending?", "role": "user"}, {"content": "SELECT project_name, AVG(investment_value) AS average_investment FROM project_fundraising_record GROUP BY project_name HAVING COUNT(*) > 1 AND AVG(investment_value) > 10000000 ORDER BY average_investment DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\n"} {"conversations": [{"content": "Show me the top 5 buyers by total trade volume (quantity * price) in the last 30 days, along with their trade count.", "role": "user"}, {"content": "SELECT buyer_id, COUNT(trade_id) AS trade_count, SUM(quantity * price) AS total_volume FROM trading_platform.trades WHERE traded_at >= NOW() - INTERVAL '30 days' GROUP BY buyer_id ORDER BY total_volume DESC LIMIT 5", "role": "assistant"}, {"content": "Now modify the query to also include the average trade price for each buyer.", "role": "user"}, {"content": "SELECT buyer_id, COUNT(trade_id) AS trade_count, SUM(quantity * price) AS total_volume, AVG(price) AS avg_price FROM trading_platform.trades WHERE traded_at >= NOW() - INTERVAL '30 days' GROUP BY buyer_id ORDER BY total_volume DESC LIMIT 5", "role": "assistant"}, {"content": "Actually, I want to see the results for sellers instead of buyers, and include the distinct asset count they traded.", "role": "user"}, {"content": "SELECT seller_id, COUNT(trade_id) AS trade_count, COUNT(DISTINCT asset_id) AS distinct_assets, SUM(quantity * price) AS total_volume, AVG(price) AS avg_price FROM trading_platform.trades WHERE traded_at >= NOW() - INTERVAL '30 days' GROUP BY seller_id ORDER BY total_volume DESC LIMIT 5", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\n"} {"conversations": [{"content": "For each fundraising round in 2022 and 2023, list the round name, the year, the total investment_value, and the count of distinct projects. Also include the average market_cap of associated tokens by matching project_name to token_symbol in token_basic_info.", "role": "user"}, {"content": "SELECT p.rounds_name,\n SUBSTRING(p.investment_date FROM 1 FOR 4) AS year,\n SUM(p.investment_value) AS total_investment,\n COUNT(DISTINCT p.project_id) AS project_count,\n AVG(t.market_cap) AS avg_market_cap\nFROM project_fundraising_record p\nJOIN token_basic_info t\n ON LOWER(p.project_name) = LOWER(t.token_symbol)\nWHERE SUBSTRING(p.investment_date FROM 1 FOR 4) IN ('2022','2023')\nGROUP BY p.rounds_name, SUBSTRING(p.investment_date FROM 1 FOR 4);", "role": "assistant"}, {"content": "The join returns no rows. Please change the join to match when token_symbol is contained within project_name, case-insensitive.", "role": "user"}, {"content": "SELECT p.rounds_name,\n SUBSTRING(p.investment_date FROM 1 FOR 4) AS year,\n SUM(p.investment_value) AS total_investment,\n COUNT(DISTINCT p.project_id) AS project_count,\n AVG(t.market_cap) AS avg_market_cap\nFROM project_fundraising_record p\nJOIN token_basic_info t\n ON LOWER(p.project_name) LIKE '%' || LOWER(t.token_symbol) || '%'\nWHERE SUBSTRING(p.investment_date FROM 1 FOR 4) IN ('2022','2023')\nGROUP BY p.rounds_name, SUBSTRING(p.investment_date FROM 1 FOR 4);", "role": "assistant"}, {"content": "Now only include rounds where the total investment_value exceeds 5000000.", "role": "user"}, {"content": "SELECT p.rounds_name,\n SUBSTRING(p.investment_date FROM 1 FOR 4) AS year,\n SUM(p.investment_value) AS total_investment,\n COUNT(DISTINCT p.project_id) AS project_count,\n AVG(t.market_cap) AS avg_market_cap\nFROM project_fundraising_record p\nJOIN token_basic_info t\n ON LOWER(p.project_name) LIKE '%' || LOWER(t.token_symbol) || '%'\nWHERE SUBSTRING(p.investment_date FROM 1 FOR 4) IN ('2022','2023')\nGROUP BY p.rounds_name, SUBSTRING(p.investment_date FROM 1 FOR 4)\nHAVING SUM(p.investment_value) > 5000000;", "role": "assistant"}, {"content": "Finally, order the results by total_investment descending.", "role": "user"}, {"content": "SELECT p.rounds_name,\n SUBSTRING(p.investment_date FROM 1 FOR 4) AS year,\n SUM(p.investment_value) AS total_investment,\n COUNT(DISTINCT p.project_id) AS project_count,\n AVG(t.market_cap) AS avg_market_cap\nFROM project_fundraising_record p\nJOIN token_basic_info t\n ON LOWER(p.project_name) LIKE '%' || LOWER(t.token_symbol) || '%'\nWHERE SUBSTRING(p.investment_date FROM 1 FOR 4) IN ('2022','2023')\nGROUP BY p.rounds_name, SUBSTRING(p.investment_date FROM 1 FOR 4)\nHAVING SUM(p.investment_value) > 5000000\nORDER BY total_investment DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n"} {"conversations": [{"content": "Find all nodes that were last seen in the last 30 days and have port numbers between 8000 and 9000.", "role": "user"}, {"content": "SELECT node_id, ip_address, port FROM blockchain.nodes WHERE last_seen >= NOW() - INTERVAL '30 days' AND port BETWEEN 8000 AND 9000", "role": "assistant"}, {"content": "Can you also show the count of transactions sent from wallet addresses that share the same IP as these nodes?", "role": "user"}, {"content": "This query isn't possible with the current schema as there's no relationship between nodes IP addresses and wallet addresses.", "role": "assistant"}, {"content": "Then just show me nodes that share the same IP address along with how many nodes share each IP.", "role": "user"}, {"content": "SELECT ip_address, COUNT(*) as node_count FROM blockchain.nodes GROUP BY ip_address HAVING COUNT(*) > 1", "role": "assistant"}, {"content": "Now filter this to only show IP addresses with more than 3 nodes and include the earliest and latest last_seen timestamps.", "role": "user"}, {"content": "SELECT ip_address, COUNT(*) as node_count, MIN(last_seen) as earliest_seen, MAX(last_seen) as latest_seen FROM blockchain.nodes GROUP BY ip_address HAVING COUNT(*) > 3", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.transactions ( transaction_id text, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text )\nCREATE TABLE blockchain.nodes ( node_id text, ip_address text, port integer, last_seen timestamp )\nCREATE TABLE blockchain.wallets ( wallet_id text, user_id text, address_id text, private_key text )\nCREATE TABLE blockchain.smart_contracts ( contract_id text, creator_address text, code text, timestamp timestamp )\n"} {"conversations": [{"content": "For each route, show the route number and the total number of trips associated with it.", "role": "user"}, {"content": "SELECT T2.route_number, count(T1.trip_id) FROM transportation.trips AS T1 JOIN transportation.routes AS T2 ON T1.route_id = T2.route_id GROUP BY T2.route_number", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE 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 )\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE transportation.passengers ( passenger_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n"} {"conversations": [{"content": "Show each policy number and the total amount paid for it across all premium payments received so far.", "role": "user"}, {"content": "SELECT T1.policy_number, SUM(T2.amount_paid) FROM insurance.policies AS T1 JOIN insurance.premium_payments AS T2 ON T1.policy_id = T2.policy_id GROUP BY T1.policy_number;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.agents ( agent_id text, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.premium_payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment\n policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)\n payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received\n amount_paid numeric(12, 2) NOT NULL, -- amount of the payment\n payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check\n transaction_reference character varying(128) UNIQUE, -- reference from payment processor\n due_date date, -- due date for this payment installment\n payment_period_start date, -- start date of the period this payment covers\n payment_period_end date, -- end date of the period this payment covers\n status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded\n PRIMARY KEY (payment_id)\n)\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\n"} {"conversations": [{"content": "List each employee's first and last name along with the count of active services offered by their agency.", "role": "user"}, {"content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name;", "role": "assistant"}, {"content": "Actually, only include employees whose service count is greater than 5.", "role": "user"}, {"content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(s.service_id) > 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, 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, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE 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) )\nCREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )\nCREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n"} {"conversations": [{"content": "Show me wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount, sorted by amount in descending order.", "role": "user"}, {"content": "SELECT b.wallet_address, t.symbol, b.amount FROM erc20_balances b JOIN sui_coins_metadata t ON b.contract_address = t.coin_type WHERE CAST(b.amount AS decimal) > 1000 ORDER BY CAST(b.amount AS decimal) DESC;", "role": "assistant"}, {"content": "Can you also include the current price of each token from the token_prices_latest table?", "role": "user"}, {"content": "SELECT b.wallet_address, t.symbol, b.amount, p.price FROM erc20_balances b JOIN sui_coins_metadata t ON b.contract_address = t.coin_type JOIN token_prices_latest p ON b.contract_address = p.address WHERE CAST(b.amount AS decimal) > 1000 ORDER BY CAST(b.amount AS decimal) DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n token_id varchar NOT NULL, -- The number of the token\n contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n amount bigint NOT NULL, -- amount fields for the functionType in contract\n minter varchar NOT NULL, -- minter fields for the functionType in contract\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract\n mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract\n mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract\n mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract\n token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract\n metadata varchar NOT NULL, -- metadata fields for the functionType in contract\n name varchar NOT NULL, -- name fields for the functionType in contract\n image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n status varchar NOT NULL, -- status fields for the functionType in contract\n rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract\n rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract\n unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(mint_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar 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 )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE 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 )\n"} {"conversations": [{"content": "Can you help me get the total number of operational platforms across all stations?", "role": "user"}, {"content": "db.platforms.countDocuments({ status: 'Operational' });", "role": "assistant"}], "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. \n##Table Structure\n// db.createCollection('platforms')\n// Optional: db.platforms.createIndex({ platform_id: 1 }, { unique: true })\n// Optional: db.platforms.createIndex({ station_id: 1 })\n{\n _id: ObjectId(),\n platform_id: \"plat_123\", // String (unique)\n station_id: \"station_xyz\", // String (references stations.station_id)\n platform_number: \"1A\", // String\n track_number: \"T1\", // String\n status: \"Operational\", // String ('Operational', 'Maintenance', 'Closed')\n length_meters: 250.50, // Decimal128 or Double\n accessible: true // Boolean\n}\n// db.createCollection('routes')\n// Optional: db.routes.createIndex({ route_id: 1 }, { unique: true })\n{\n _id: ObjectId(),\n route_id: \"route_ne_corr\", // String (unique)\n route_name: \"Northeast Corridor\", // String\n description: \"High-speed rail linking Boston and Washington D.C.\", // String\n origin_station_id: \"station_bos\", // String (references stations.station_id)\n destination_station_id: \"station_was\", // String (references stations.station_id)\n is_active: true // Boolean\n}\n// db.createCollection('route_stations')\n// Optional: db.route_stations.createIndex({ route_station_id: 1 }, { unique: true })\n// Optional: db.route_stations.createIndex({ route_id: 1, sequence_order: 1 }, { unique: true })\n{\n _id: ObjectId(),\n route_station_id: \"rs_ne_1\", // String (unique)\n route_id: \"route_ne_corr\", // String (references routes.route_id)\n station_id: \"station_bos\", // String (references stations.station_id)\n sequence_order: 1, // Int32\n distance_from_previous_km: null, // Decimal128 or Double (null for first stop)\n typical_stop_duration_minutes: null // Int32 (null for origin/destination or if no stop)\n}\n// --- OR --- Embed within the Route document:\n// {\n// _id: ObjectId(), route_id: \"route_ne_corr\", ...,\n// stations: [\n// { station_id: \"station_bos\", sequence_order: 1, distance_from_previous_km: null, typical_stop_duration_minutes: null },\n// { station_id: \"station_pvd\", sequence_order: 2, distance_from_previous_km: 70.5, typical_stop_duration_minutes: 5 },\n// ...\n// ]\n// }\n// db.createCollection('schedules')\n// Optional: db.schedules.createIndex({ schedule_id: 1 }, { unique: true })\n// Optional: db.schedules.createIndex({ route_id: 1, departure_datetime: 1 })\n{\n _id: ObjectId(),\n schedule_id: \"sched_1122\", // String (unique)\n train_id: \"train_789\", // String (references trains.train_id)\n route_id: \"route_ne_corr\", // String (references routes.route_id)\n departure_datetime: ISODate(\"2024-05-10T08:00:00-04:00\"), // Date (with timezone)\n arrival_datetime: ISODate(\"2024-05-10T15:30:00-04:00\"), // Date (with timezone)\n status: \"Scheduled\", // String ('Scheduled', 'On Time', 'Delayed', 'Cancelled', 'Arrived')\n notes: \"Track work expected near Philadelphia\" // String\n}\n// db.createCollection('schedule_stops')\n// Optional: db.schedule_stops.createIndex({ stop_id: 1 }, { unique: true })\n// Optional: db.schedule_stops.createIndex({ schedule_id: 1, sequence_order: 1 }, { unique: true })\n{\n _id: ObjectId(),\n stop_id: \"stop_sched1122_1\", // String (unique)\n schedule_id: \"sched_1122\", // String (references schedules.schedule_id)\n station_id: \"station_bos\", // String (references stations.station_id)\n platform_id: \"plat_bos_3\", // String (references platforms.platform_id, nullable)\n sequence_order: 1, // Int32\n scheduled_arrival_time: null, // Date\n scheduled_departure_time: ISODate(\"2024-05-10T08:00:00-04:00\"), // Date\n actual_arrival_time: null, // Date\n actual_departure_time: ISODate(\"2024-05-10T08:01:00-04:00\"), // Date\n status: \"On Time\" // String\n}\n// --- OR --- Embed within the Schedule document using an array 'stops'\n// db.createCollection('passengers')\n// Optional: db.passengers.createIndex({ passenger_id: 1 }, { unique: true })\n// Optional: db.passengers.createIndex({ email: 1 }, { unique: true, sparse: true })\n// Optional: db.passengers.createIndex({ phone_number: 1 }, { unique: true, sparse: true })\n{\n _id: ObjectId(),\n passenger_id: \"pass_pqr\", // String (unique)\n first_name: \"Alice\", // String\n last_name: \"Smith\", // String\n email: \"alice.smith@example.com\", // String (unique, sparse)\n phone_number: \"+15551234567\", // String (unique, sparse)\n date_of_birth: ISODate(\"1990-03-20\"), // Date\n loyalty_program_id: \"LOYALTY123\", // String\n created_at: ISODate(\"2023-02-01T11:00:00Z\") // Date\n}\n// db.createCollection('staff')\n// Optional: db.staff.createIndex({ staff_id: 1 }, { unique: true })\n// Optional: db.staff.createIndex({ employee_number: 1 }, { unique: true })\n// Optional: db.staff.createIndex({ contact_email: 1 }, { unique: true, sparse: true })\n{\n _id: ObjectId(),\n staff_id: \"staff_mno\", // String (unique)\n first_name: \"Bob\", // String\n last_name: \"Jones\", // String\n role: \"Conductor\", // String\n primary_station_id: null, // String (references stations.station_id, nullable)\n employee_number: \"E12345\", // String (unique)\n hire_date: ISODate(\"2018-06-01\"), // Date\n contact_email: \"bob.jones@example-rail.com\", // String (unique, sparse)\n contact_phone: \"+15559876543\", // String\n is_active: true // Boolean\n}\n"} {"conversations": [{"content": "What is the ticket price for a journey on train number T4321?", "role": "user"}, {"content": "I'm sorry, but I don't have access to information about ticket prices for specific trains. The data I have is limited to train details such as model, manufacturer, capacity, and maintenance schedules. For ticket pricing, please consult the ticketing office or the official website.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.trains ( train_id text PRIMARY KEY, train_number text UNIQUE, model text, manufacturer text, year_manufactured int, capacity int, status text, last_maintenance_date date, next_maintenance_date date )\n"} {"conversations": [{"content": "Find all wallets that were created on the same day and list their wallet IDs, addresses, and the creation date.", "role": "user"}, {"content": "SELECT w1.wallet_id, w1.address, w1.created_at::date AS creation_date FROM web3.wallets w1 JOIN (SELECT created_at::date AS creation_date FROM web3.wallets GROUP BY created_at::date HAVING COUNT(*) > 1) w2 ON w1.created_at::date = w2.creation_date ORDER BY creation_date, w1.wallet_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\n"} {"conversations": [{"content": "Which developers have created games that include at least one item of rarity 'Legendary'? Show the developer_id and the item_name.", "role": "user"}, {"content": "SELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.in_game_items igi ON d.developer_id = igi.game_id /* This assumes developer_id = game_id; adjust join logic as needed */\nWHERE igi.rarity = 'Legendary';", "role": "assistant"}, {"content": "I think the join is wrong, it should match developers to games and then in_game_items to games. Please revise the SQL.", "role": "user"}, {"content": "-- Assuming the existence of a 'games' table with columns (game_id, developer_id)\nSELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items igi ON g.game_id = igi.game_id\nWHERE igi.rarity = 'Legendary';", "role": "assistant"}, {"content": "You can only use the given tables. Is it possible to get a list of developers who have legendary items in their games with the available schema?", "role": "user"}, {"content": "-- Based on the given schema alone (without a games table), it's not possible to relate developers to in_game_items directly since there is no relationship between developer_id and game_id in the available tables.", "role": "assistant"}, {"content": "Okay, then just list all 'Legendary' rarity in-game items, including their item_id, item_name, and cost_amount.", "role": "user"}, {"content": "SELECT item_id, item_name, cost_amount\nFROM gaming_technology.in_game_items\nWHERE rarity = 'Legendary';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n"} {"conversations": [{"content": "For each event, display its event_id, the event_id of the previous event in the same transaction (if any), and the log_index of both events.", "role": "user"}, {"content": "SELECT curr.event_id AS current_event_id,\n prev.event_id AS previous_event_id,\n curr.log_index AS current_log_index,\n prev.log_index AS previous_log_index,\n curr.transaction_id\nFROM web3.events curr\nLEFT JOIN web3.events prev\n ON curr.transaction_id = prev.transaction_id\n AND curr.log_index = prev.log_index + 1;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\n"} {"conversations": [{"content": "List all DApps along with the number of metadata entries linked to each, even if the DApp has no linked metadata.", "role": "user"}, {"content": "SELECT d.name, d.url, COUNT(m.metadata_id) AS metadata_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON d.dapp_id = m.asset_id\nGROUP BY d.dapp_id, d.name, d.url;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n"} {"conversations": [{"content": "Show the number of active agents in each license state.", "role": "user"}, {"content": "SELECT license_state,\n COUNT(*) AS active_agent_count\nFROM insurance.agents\nWHERE status = 'active'\nGROUP BY license_state;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\n"} {"conversations": [{"content": "Count the number of completed premium payments grouped by payment_method.", "role": "user"}, {"content": "SELECT payment_method,\n COUNT(*) AS payment_count\nFROM insurance.premium_payments\nWHERE status = 'Completed'\nGROUP BY payment_method;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\n"} {"conversations": [{"content": "Count the total number of chronic diagnoses for each code_type.", "role": "user"}, {"content": "SELECT\n code_type,\n COUNT(*) AS chronic_diagnosis_count\nFROM healthcare.diagnoses\nWHERE is_chronic = TRUE\nGROUP BY code_type;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )\nCREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\n"} {"conversations": [{"content": "List all primary insurance policies that will expire within the next 30 days. Return patient_insurance_id, patient_id, policy_number, and expiration_date.", "role": "user"}, {"content": "SELECT patient_insurance_id,\n patient_id,\n policy_number,\n expiration_date\nFROM healthcare.patient_insurance\nWHERE is_primary = TRUE\n AND expiration_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '30 days';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )\n"} {"conversations": [{"content": "Count the total number of premium payments made in the year 2024.", "role": "user"}, {"content": "SELECT COUNT(*) FROM premium_payments WHERE EXTRACT(YEAR FROM payment_date) = 2024", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE 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) )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\n"} {"conversations": [{"content": "Show me the top 5 projects by valuation that completed fundraising rounds in the last 6 months, along with their narrative information if available.", "role": "user"}, {"content": "SELECT pfr.project_name, pfr.rounds_name, pfr.valuation, pfr.investment_date, ni.narrative, ni.trend_rank\nFROM project_fundraising_record pfr\nLEFT JOIN narrative_info ni ON pfr.project_name = ni.narrative\nWHERE pfr.investment_date >= date_sub(now(), interval 6 month)\nORDER BY pfr.valuation DESC\nLIMIT 5;", "role": "assistant"}, {"content": "Can you filter these results to only include projects with valuation over $50 million and add their 24-hour trading volume from the narrative?", "role": "user"}, {"content": "SELECT pfr.project_name, pfr.rounds_name, pfr.valuation, ni.volume_24h\nFROM project_fundraising_record pfr\nLEFT JOIN narrative_info ni ON pfr.project_name = ni.narrative\nWHERE pfr.investment_date >= date_sub(now(), interval 6 month)\nAND pfr.valuation > 50000000\nORDER BY pfr.valuation DESC\nLIMIT 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\n"} {"conversations": [{"content": "List all applications that have at least one document with a verification status of 'Verified'. Show the application reference number and the name of the service associated with the application.", "role": "user"}, {"content": "SELECT\n T1.reference_number,\n T2.service_name\nFROM government_services.applications AS T1\nINNER JOIN government_services.services AS T2\n ON T1.service_id = T2.service_id\nWHERE EXISTS (\n SELECT\n 1\n FROM government_services.documents AS T3\n WHERE\n T3.application_id = T1.application_id AND T3.verification_status = 'Verified'\n);", "role": "assistant"}, {"content": "Now, only include applications that were submitted in the year 2024.", "role": "user"}, {"content": "SELECT\n T1.reference_number,\n T2.service_name\nFROM government_services.applications AS T1\nINNER JOIN government_services.services AS T2\n ON T1.service_id = T2.service_id\nWHERE EXISTS (\n SELECT\n 1\n FROM government_services.documents AS T3\n WHERE\n T3.application_id = T1.application_id AND T3.verification_status = 'Verified'\n)\nAND EXTRACT(YEAR FROM T1.submitted_at) = 2024;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.agencies (\n agency_id character varying(64) NOT NULL, -- unique identifier for the agency\n agency_name character varying(255) NOT NULL, -- full name of the government agency\n jurisdiction_level character varying(50) NOT NULL, -- e.g., Federal, State, County, City\n primary_contact_email character varying(128),\n main_phone_number character varying(32),\n website_url character varying(255),\n established_date date,\n parent_agency_id character varying(64), -- FK to self for hierarchical structure\n PRIMARY KEY (agency_id)\n)\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n application_id character varying(64), -- FK to applications table (optional)\n message_subject character varying(255),\n message_body text NOT NULL,\n channel character varying(30) NOT NULL, -- e.g., Email, SMS, Portal Message, Mail\n sent_at timestamp NOT NULL,\n status character varying(30) NOT NULL, -- e.g., Queued, Sent, Delivered, Failed, Read\n related_entity_type character varying(50), -- e.g., Application, Appointment, Document Request\n related_entity_id character varying(64), -- ID of the related entity\n PRIMARY KEY (notification_id)\n)\n"} {"conversations": [{"content": "Show all rooms that are on floor 3.", "role": "user"}, {"content": "SELECT room_id, property_id, room_number FROM hospitality_technology.rooms WHERE floor = 3;", "role": "assistant"}, {"content": "For these rooms, include the property name and room number.", "role": "user"}, {"content": "SELECT r.room_number, p.property_name FROM hospitality_technology.rooms AS r JOIN hospitality_technology.properties AS p ON r.property_id = p.property_id WHERE r.floor = 3;", "role": "assistant"}, {"content": "Also, include the type name and current status for each room.", "role": "user"}, {"content": "SELECT r.room_number, p.property_name, rt.type_name, r.status FROM hospitality_technology.rooms AS r JOIN hospitality_technology.properties AS p ON r.property_id = p.property_id JOIN hospitality_technology.room_types AS rt ON r.room_type_id = rt.room_type_id AND r.property_id = rt.property_id WHERE r.floor = 3;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\n"} {"conversations": [{"content": "List all pairs of law firms that were founded on the same month and day, showing their names, and the shared founding date. Exclude firms founded on January 1st.", "role": "user"}, {"content": "SELECT t1.firm_name AS firm1_name, t2.firm_name AS firm2_name, t1.founded_date FROM legal_services.law_firms AS t1 JOIN legal_services.law_firms AS t2 ON MONTH(t1.founded_date) = MONTH(t2.founded_date) AND DAY(t1.founded_date) = DAY(t2.founded_date) AND t1.firm_id < t2.firm_id WHERE MONTH(t1.founded_date) <> 1 OR DAY(t1.founded_date) <> 1;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.law_firms ( firm_id character varying(64) NOT NULL, firm_name character varying(200) NOT NULL, address text NOT NULL, phone character varying(32), website character varying(255), founded_date date, managing_partner_id character varying(64), PRIMARY KEY (firm_id) )\n"} {"conversations": [{"content": "For each developer, can you find the next developer in the same country using a self join, returning developer_ids and names?", "role": "user"}, {"content": "SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN developers d2\n ON d1.country = d2.country\n AND d2.founded_year > d1.founded_year;", "role": "assistant"}, {"content": "Exclude developers who don't have a next developer, and ensure we only pick the closest next by founded_year.", "role": "user"}, {"content": "SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN LATERAL (\n SELECT d2.developer_id, d2.name, d2.founded_year\n FROM developers d2\n WHERE d2.country = d1.country\n AND d2.founded_year > d1.founded_year\n ORDER BY d2.founded_year ASC\n LIMIT 1\n) d2 ON true;", "role": "assistant"}, {"content": "Finally, only include pairs where the difference in founded years is at most 5 years.", "role": "user"}, {"content": "SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN LATERAL (\n SELECT d2.developer_id, d2.name, d2.founded_year\n FROM developers d2\n WHERE d2.country = d1.country\n AND d2.founded_year > d1.founded_year\n ORDER BY d2.founded_year ASC\n LIMIT 1\n) d2 ON true\nWHERE (d2.founded_year - d1.founded_year) <= 5\nORDER BY d1.developer_id, years_diff ASC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\n"} {"conversations": [{"content": "List all ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses.", "role": "user"}, {"content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price BETWEEN 1 AND 10;", "role": "assistant"}, {"content": "I think there's an error in your query - it should be joining with token_prices_latest on address not contract_address. Also, can you add the current price to the results?", "role": "user"}, {"content": "SELECT tm.name, tm.symbol, tm.contract_address, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price BETWEEN 1 AND 10;", "role": "assistant"}, {"content": "Now filter these results to only show tokens with decimals equal to 18 and sort by name alphabetically.", "role": "user"}, {"content": "SELECT tm.name, tm.symbol, tm.contract_address, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price BETWEEN 1 AND 10 AND tm.decimals = 18 ORDER BY tm.name ASC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( 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 )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( 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 )\nCREATE TABLE token_activities_bitcoin ( 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 )\nCREATE TABLE token_activities_avalanche ( 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 )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE 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 )\n"} {"conversations": [{"content": "For each user, list all pairs of read and unread notifications, showing the recipient_user_id, the unread notification_id and type, and the read notification_id and type.", "role": "user"}, {"content": "SELECT\n n_unread.recipient_user_id,\n n_unread.notification_id AS unread_id,\n n_unread.notification_type AS unread_type,\n n_read.notification_id AS read_id,\n n_read.notification_type AS read_type\nFROM social_media.notifications n_unread\nJOIN social_media.notifications n_read\n ON n_unread.recipient_user_id = n_read.recipient_user_id\nWHERE n_unread.read_at IS NULL\n AND n_read.read_at IS NOT NULL;", "role": "assistant"}, {"content": "Actually, only include pairs where the unread notification_type is 'message'.", "role": "user"}, {"content": "SELECT\n n_unread.recipient_user_id,\n n_unread.notification_id AS unread_id,\n n_unread.notification_type AS unread_type,\n n_read.notification_id AS read_id,\n n_read.notification_type AS read_type\nFROM social_media.notifications n_unread\nJOIN social_media.notifications n_read\n ON n_unread.recipient_user_id = n_read.recipient_user_id\nWHERE n_unread.read_at IS NULL\n AND n_read.read_at IS NOT NULL\n AND n_unread.notification_type = 'message';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\n"} {"conversations": [{"content": "List all pairs of fuel log entries for the same vehicle that occurred more than 7 days apart, showing vehicle_id, first_log_id, second_log_id, and the time difference in days.", "role": "user"}, {"content": "SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))/86400 AS days_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days';", "role": "assistant"}, {"content": "Now filter to only include pairs where the quantity increased by at least 50 units.", "role": "user"}, {"content": "SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))/86400 AS days_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days'\nWHERE (f2.quantity - f1.quantity) >= 50;", "role": "assistant"}, {"content": "Also display the difference in total_cost between the two logs.", "role": "user"}, {"content": "SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))/86400 AS days_difference,\n (f2.quantity - f1.quantity) AS quantity_difference,\n (f2.total_cost - f1.total_cost) AS cost_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days'\nWHERE (f2.quantity - f1.quantity) >= 50;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\n"} {"conversations": [{"content": "Show a list of all game developers with their name and founded year.", "role": "user"}, {"content": "SELECT\n name,\n founded_year\nFROM gaming_technology.developers;", "role": "assistant"}, {"content": "Please filter the list to only include developers founded in the year 1998.", "role": "user"}, {"content": "SELECT\n name,\n founded_year\nFROM gaming_technology.developers\nWHERE\n founded_year = 1998;", "role": "assistant"}, {"content": "Can you also include the number of games each of these developers has released?", "role": "user"}, {"content": "SELECT\n T1.name,\n T1.founded_year,\n COUNT(T2.game_id) AS game_count\nFROM gaming_technology.developers AS T1\nLEFT JOIN gaming_technology.games AS T2\n ON T1.developer_id = T2.developer_id\nWHERE\n T1.founded_year = 1998\nGROUP BY\n T1.developer_id,\n T1.name,\n T1.founded_year;", "role": "assistant"}, {"content": "Now, only show the developers who have released exactly 2 games.", "role": "user"}, {"content": "SELECT\n T1.name,\n T1.founded_year,\n COUNT(T2.game_id) AS game_count\nFROM gaming_technology.developers AS T1\nJOIN gaming_technology.games AS T2\n ON T1.developer_id = T2.developer_id\nWHERE\n T1.founded_year = 1998\nGROUP BY\n T1.developer_id,\n T1.name,\n T1.founded_year\nHAVING\n COUNT(T2.game_id) = 2;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.developers (\n developer_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the developer studio\n name character varying(150) NOT NULL UNIQUE, -- name of the development studio\n country character varying(100), -- country where the studio is based\n founded_year integer, -- year the studio was founded\n website character varying(255), -- developer's official website\n created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (developer_id)\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\n"} {"conversations": [{"content": "For all chains, which token held by centralized exchanges (CEX) has the highest ROI according to smart money token performance? Show token symbol, chain, exchange, total USD value held on CEX, and the smart money ROI.", "role": "user"}, {"content": "SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi\nFROM cex_token_balance c\nJOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\nGROUP BY c.token_symbol, c.chain, c.exchange, s.roi\nORDER BY s.roi DESC\nLIMIT 1;", "role": "assistant"}, {"content": "Instead of just the top one, show the top 3 tokens by ROI, and only include cases where the total USD value held on CEX is greater than $2,000,000.", "role": "user"}, {"content": "SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi\nFROM cex_token_balance c\nJOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\nGROUP BY c.token_symbol, c.chain, c.exchange, s.roi\nHAVING SUM(c.usd_value) > 2000000\nORDER BY s.roi DESC\nLIMIT 3;", "role": "assistant"}, {"content": "Add the last recorded price for each token, and sort by total_usd_value in descending order.", "role": "user"}, {"content": "SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi, MAX(c.price) AS last_price\nFROM cex_token_balance c\nJOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\nGROUP BY c.token_symbol, c.chain, c.exchange, s.roi\nHAVING SUM(c.usd_value) > 2000000\nORDER BY total_usd_value DESC\nLIMIT 3;", "role": "assistant"}, {"content": "I got duplicate tokens across exchanges. Can you show only the top exchange (with the greatest USD value) per token and chain combination?", "role": "user"}, {"content": "WITH cex_totals AS (\n SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi, MAX(c.price) AS last_price,\n ROW_NUMBER() OVER (PARTITION BY c.token_symbol, c.chain ORDER BY SUM(c.usd_value) DESC) as rn\n FROM cex_token_balance c\n JOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\n GROUP BY c.token_symbol, c.chain, c.exchange, s.roi\n HAVING SUM(c.usd_value) > 2000000\n)\nSELECT token_symbol, chain, exchange, total_usd_value, roi, last_price\nFROM cex_totals\nWHERE rn = 1\nORDER BY total_usd_value DESC\nLIMIT 3;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, top_3_coins text, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, market_cap double precision, volume_24h double precision, trend_rank bigint, token_num bigint )\nCREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, chain character varying(128) NOT NULL, address character varying(128) NOT NULL, exchange character varying(512) NOT NULL, token_address character varying(128) NOT NULL, token_symbol character varying(512), balance numeric(38,10), usd_value numeric(38,14), price double precision )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, token_symbol character varying(100), token_amount numeric(38,2), usd_value numeric(38,2), avg_price numeric(38,6), type int, address_amount integer, narrative character varying(100), chain character varying(100) )\n"} {"conversations": [{"content": "Show me all room types with 'King' in the bed_type field, along with their property IDs and base rates.", "role": "user"}, {"content": "SELECT room_type_id, property_id, type_name, bed_type, base_rate FROM hospitality_technology.room_types WHERE bed_type LIKE '%King%';", "role": "assistant"}, {"content": "Now, join this with the guests table to show only room types from properties where the guest's country code is 'USA' and the guest is a loyalty member.", "role": "user"}, {"content": "SELECT rt.room_type_id, rt.property_id, rt.type_name, rt.bed_type, rt.base_rate FROM hospitality_technology.room_types rt JOIN hospitality_technology.guests g ON rt.property_id = g.property_id WHERE rt.bed_type LIKE '%King%' AND g.country_code = 'USA' AND g.loyalty_member_id IS NOT NULL;", "role": "assistant"}, {"content": "The query is missing the max occupancy. Can you include that as well?", "role": "user"}, {"content": "SELECT rt.room_type_id, rt.property_id, rt.type_name, rt.bed_type, rt.base_rate, rt.max_occupancy FROM hospitality_technology.room_types rt JOIN hospitality_technology.guests g ON rt.property_id = g.property_id WHERE rt.bed_type LIKE '%King%' AND g.country_code = 'USA' AND g.loyalty_member_id IS NOT NULL;", "role": "assistant"}, {"content": "Actually, I need to see only room types with a base rate below $300, and order them by max occupancy in descending order.", "role": "user"}, {"content": "SELECT rt.room_type_id, rt.property_id, rt.type_name, rt.bed_type, rt.base_rate, rt.max_occupancy FROM hospitality_technology.room_types rt JOIN hospitality_technology.guests g ON rt.property_id = g.property_id WHERE rt.bed_type LIKE '%King%' AND g.country_code = 'USA' AND g.loyalty_member_id IS NOT NULL AND rt.base_rate < 300 ORDER BY rt.max_occupancy DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, property_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\n"} {"conversations": [{"content": "What is the current operational status of the train car with car_id 'CAR123'?", "role": "user"}, {"content": "I'm sorry, but I can't provide information on the current operational status of the train car with car_id 'CAR123'. The data in the train_cars table does not include real-time status updates or operational conditions.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.train_cars ( car_id text PRIMARY KEY, train_id text, car_number text, car_type text, class text, capacity int, features text )\n"} {"conversations": [{"content": "List all rooms that have a 'Jacuzzi' feature, including the room_number, property_id, type_name, and base_rate.", "role": "user"}, {"content": "SELECT r.room_number,\n r.property_id,\n rt.type_name,\n rt.base_rate\nFROM hospitality_technology.rooms AS r\nJOIN hospitality_technology.room_types AS rt\n ON r.room_type_id = rt.room_type_id\n AND r.property_id = rt.property_id\nWHERE r.features ILIKE '%Jacuzzi%';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id.text, 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.integer, manager_id.text, created_at.timestamp )\nCREATE 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 )\nCREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )\nCREATE TABLE hospitality_technology.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )\n"} {"conversations": [{"content": "For each city and state, show the number of service locations available along with their accessibility status.", "role": "user"}, {"content": "SELECT city, state, is_accessible, COUNT(*) AS location_count FROM government_services.service_locations GROUP BY city, state, is_accessible;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\n"} {"conversations": [{"content": "List all users with private profiles who have disabled push notifications, including their user_id and email_notifications_enabled status.", "role": "user"}, {"content": "SELECT user_id,\n email_notifications_enabled\nFROM social_media.user_settings\nWHERE private_profile = true\n AND push_notifications_enabled = false;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE 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 )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n"} {"conversations": [{"content": "Show me the list of hashtags that have been used, along with the time they were first used.", "role": "user"}, {"content": "SELECT tag_name, created_at \nFROM social_media.hashtags;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n"} {"conversations": [{"content": "Show me all users who have wallets but have never placed any orders, along with their wallet addresses and creation dates.", "role": "user"}, {"content": "SELECT u.user_id, u.email, w.address AS wallet_address, w.created_at FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id LEFT JOIN trading_platform.orders o ON u.user_id = o.user_id WHERE o.order_id IS NULL;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )\n"} {"conversations": [{"content": "For each driver, find the other driver whose license_expiry_date is the next one after theirs. Show both IDs, names and their expiry dates.", "role": "user"}, {"content": "SELECT\n d1.driver_id AS driver_id,\n d1.first_name || ' ' || d1.last_name AS driver_name,\n d1.license_expiry_date AS expiry_date,\n d2.driver_id AS next_driver_id,\n d2.first_name || ' ' || d2.last_name AS next_driver_name,\n d2.license_expiry_date AS next_expiry_date\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date = (\n SELECT MIN(d3.license_expiry_date)\n FROM transportation.drivers d3\n WHERE d3.license_expiry_date > d1.license_expiry_date\n );", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "List all ERC20 tokens with their names and symbols where the price is greater than $100, sorted by price in descending order.", "role": "user"}, {"content": "SELECT scm.name, scm.symbol, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.coin_type = tpl.address WHERE tpl.price > 100 ORDER BY tpl.price DESC;", "role": "assistant"}, {"content": "I think there's an error in your query - it should be joining on address not coin_type. Also, can you add the decimals to the results?", "role": "user"}, {"content": "SELECT scm.name, scm.symbol, scm.decimals, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.object_id = tpl.address WHERE tpl.price > 100 ORDER BY tpl.price DESC;", "role": "assistant"}, {"content": "Now filter these results to only show tokens with decimals equal to 18 and limit to the top 10.", "role": "user"}, {"content": "SELECT scm.name, scm.symbol, scm.decimals, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.object_id = tpl.address WHERE tpl.price > 100 AND scm.decimals = 18 ORDER BY tpl.price DESC LIMIT 10;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE 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 )\nCREATE TABLE token_info_bitcoin ( 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 )\nCREATE TABLE token_activities_avalanche ( 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 )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE 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 )\n"} {"conversations": [{"content": "Show me the top 5 most recently minted NFTs on the Ethereum blockchain with their contract_address, token_id, name, and rarity_score from nft_metadata.", "role": "user"}, {"content": "SELECT contract_address, token_id, name, rarity_score\nFROM nft_metadata\nWHERE blockchain = 'Ethereum'\nORDER BY mint_block_number DESC\nLIMIT 5;", "role": "assistant"}, {"content": "Also include the collection name, floor_price, and token_count from nft_collections for each NFT's collection.", "role": "user"}, {"content": "SELECT m.contract_address AS nft_contract,\n m.token_id,\n m.name,\n m.rarity_score,\n c.name AS collection_name,\n c.floor_price,\n c.token_count\nFROM nft_metadata m\nJOIN nft_collections c\n ON m.blockchain = c.blockchain\n AND m.contract_address = c.contract_address\nWHERE m.blockchain = 'Ethereum'\nORDER BY m.mint_block_number DESC\nLIMIT 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number / 7200))\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n"} {"conversations": [{"content": "Which rooms on the 4th floor are non-smoking, along with their property IDs and type IDs?", "role": "user"}, {"content": "SELECT room_id, property_id, room_number, room_type_id FROM hospitality_technology.rooms WHERE floor = 4 AND is_smoking = FALSE;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\n"} {"conversations": [{"content": "What is the count of securities for each security_type in the 'Technology' sector?", "role": "user"}, {"content": "SELECT security_type, COUNT(*) as security_count FROM financial_services.securities WHERE sector = 'Technology' GROUP BY security_type;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.securities (\n security_id character varying(64) NOT NULL, -- unique identifier for the security\n ticker_symbol character varying(20) NOT NULL UNIQUE, -- stock ticker or fund symbol\n isin_code character varying(12) UNIQUE, -- International Securities Identification Number\n cusip_code character varying(9) UNIQUE, -- CUSIP number\n security_name text NOT NULL, -- full name of the security\n security_type character varying(50) NOT NULL, -- e.g., Stock, Bond, ETF, Mutual Fund, Option, Future\n exchange character varying(50), -- primary exchange where traded (e.g., NYSE, NASDAQ)\n currency character varying(3) NOT NULL, -- currency the security is denominated in\n issuer_name character varying(255), -- name of the issuing entity\n sector character varying(100), -- industry sector\n last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (security_id)\n)\n"} {"conversations": [{"content": "List each wallet that has received tokens of more than one distinct token type. Show wallet_id, address, the number of distinct tokens received as distinct_token_count, and the total received value, ordered by total_received_value descending.", "role": "user"}, {"content": "SELECT w.wallet_id,\n w.address,\n COUNT(DISTINCT t.token_id) AS distinct_token_count,\n SUM(tt.value) AS total_received_value\nFROM web3.wallets w\nJOIN web3.token_transfers tt\n ON w.address = tt.to_address\nJOIN web3.tokens t\n ON tt.token_id = t.token_id\nGROUP BY w.wallet_id, w.address\nHAVING COUNT(DISTINCT t.token_id) > 1\nORDER BY total_received_value DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\n"} {"conversations": [{"content": "For each recipient address, count how many token transfers they have received.", "role": "user"}, {"content": "SELECT to_address, COUNT(*) AS received_transfer_count FROM web3.token_transfers GROUP BY to_address;", "role": "assistant"}, {"content": "Only show addresses that have received more than 100 transfers.", "role": "user"}, {"content": "SELECT to_address, COUNT(*) AS received_transfer_count FROM web3.token_transfers GROUP BY to_address HAVING COUNT(*) > 100;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\n"} {"conversations": [{"content": "Find the service locations that are not accessible and located in the state of 'California'. List their name, address, and city.", "role": "user"}, {"content": "SELECT location_name , address , city FROM government_services.service_locations WHERE is_accessible = false AND state = 'California'", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\n"} {"conversations": [{"content": "For each address, show the total amount contained in UTXOs that have been spent.", "role": "user"}, {"content": "SELECT address, SUM(amount) FROM utxos WHERE spent = TRUE GROUP BY address;", "role": "assistant"}, {"content": "Only include addresses where this total spent amount is greater than 500 and order the results by the total amount descending.", "role": "user"}, {"content": "SELECT address, SUM(amount) FROM utxos WHERE spent = TRUE GROUP BY address HAVING SUM(amount) > 500 ORDER BY SUM(amount) DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.utxos (\n utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO\n output_index integer NOT NULL, -- index of the output in the transaction\n address character varying(128) NOT NULL, -- address that can spend the UTXO\n amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO\n spent boolean NOT NULL, -- whether the UTXO has been spent\n PRIMARY KEY (utxo_id)\n)\n"} {"conversations": [{"content": "What is the average ROI for smart money addresses on the Ethereum chain?", "role": "user"}, {"content": "SELECT AVG(roi) FROM smart_money_token_performance WHERE chain = 'Ethereum';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE project_fundraising_record (\",\n \"id character varying(32) NOT NULL, -- fundraising record id\",\n \"project_id character varying(32) NOT NULL, -- the invested project's id\",\n \"project_name character varying(128) NOT NULL, -- name of the invested project\",\n \"rounds_name character varying(32), -- name of the fundraising round\",\n \"investment_value numeric(38,14), -- amount of the fundraising in USD\",\n \"investment_date character varying(128), -- the date of the investment happened\",\n \"introduction character varying(128), -- the introduction of the invested project\",\n \"valuation numeric(38,14), -- the valuation of the project in USD when invested\",\n\n \"CREATE TABLE token_basic_info (\",\n \"coin_id character varying(100) NOT NULL, -- the id of the token\",\n \"token_name character varying(100) NOT NULL, -- the token's name\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"chain text, -- the chain that the token resides\",\n \"price double precision, -- the current price of the token\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days\",\n \"highest_price_24h double precision, -- the highest price of the token in 24 hours\",\n \"lowest_price_24h double precision, -- the lowest price of the token in 24 hours\",\n \"market_cap double precision, -- the market cap of the token\",\n \"market_cap_rank bigint, -- the rank of the token market cap in desc\",\n \"market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours\",\n \"total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX)\", \n \"narrative text, -- the category or narrative of the token\",\n \"trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (coin_id, chain));\",\n\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n \"CREATE TABLE smart_money_token_performance (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"pnl numeric(38,2), -- the profit users made on this token\",\n \"net_flow numeric(38,2), -- the netflow of the token, means the money user spent minus the the money user sold of this token\",\n \"avg_cost numeric(38,16), -- the average cost price of user spent on this token\",\n \"price double precision, -- the current price of the token\",\n \"realized_ratio numeric(10,2), -- the ratio user sold of the token\",\n \"roi numeric(10,2), -- the roi users made of this token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \"PRIMARY KEY (token_address, chain));\",\n\n"} {"conversations": [{"content": "Give me the total number of reservations and the sum of total_amount by month for the year 2023.", "role": "user"}, {"content": "SELECT DATE_TRUNC('month', check_in_date) AS month,\n COUNT(*) AS reservation_count,\n SUM(total_amount) AS total_revenue\nFROM hospitality_technology.reservations\nWHERE EXTRACT(YEAR FROM check_in_date) = 2023\nGROUP BY DATE_TRUNC('month', check_in_date)\nORDER BY month;", "role": "assistant"}, {"content": "Actually, I only want reservations with status 'CheckedOut' or 'Completed'.", "role": "user"}, {"content": "SELECT DATE_TRUNC('month', check_in_date) AS month,\n COUNT(*) AS reservation_count,\n SUM(total_amount) AS total_revenue\nFROM hospitality_technology.reservations\nWHERE EXTRACT(YEAR FROM check_in_date) = 2023\n AND status IN ('CheckedOut', 'Completed')\nGROUP BY DATE_TRUNC('month', check_in_date)\nORDER BY month;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\n"} {"conversations": [{"content": "Show me all policies that expired in the last 60 days, along with their product IDs and premium amounts.", "role": "user"}, {"content": "SELECT policy_id, product_id, premium_amount FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE;", "role": "assistant"}, {"content": "Now include only policies that had a deductible of $1000 or more.", "role": "user"}, {"content": "SELECT policy_id, product_id, premium_amount, deductible FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE AND deductible >= 1000;", "role": "assistant"}, {"content": "I also want to see the count of such expired policies per product ID.", "role": "user"}, {"content": "SELECT product_id, COUNT(*) as policy_count FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE AND deductible >= 1000 GROUP BY product_id ORDER BY policy_count DESC;", "role": "assistant"}, {"content": "Finally, show me the average premium amount for these expired high-deductible policies grouped by product ID.", "role": "user"}, {"content": "SELECT product_id, AVG(premium_amount) as avg_premium FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE AND deductible >= 1000 GROUP BY product_id ORDER BY avg_premium DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\n"} {"conversations": [{"content": "List all wallets holding the NFT with contract_address '0xabc123' and token_id '100' and the amount held.", "role": "user"}, {"content": "SELECT wallet_address, amount\nFROM nft_holders\nWHERE contract_address = '0xabc123'\n AND token_id = '100';", "role": "assistant"}, {"content": "Also include the NFT name from nft_metadata by joining on contract_address and token_id.", "role": "user"}, {"content": "SELECT nh.wallet_address,\n nh.amount,\n nm.name\nFROM nft_holders nh\nJOIN nft_metadata nm ON nh.contract_address = nm.contract_address\n AND nh.token_id = nm.token_id\nWHERE nh.contract_address = '0xabc123'\n AND nh.token_id = '100';", "role": "assistant"}, {"content": "Finally, add the collection name from nft_collections where blockchain is 'Ethereum'.", "role": "user"}, {"content": "SELECT nh.wallet_address,\n nh.amount,\n nm.name,\n nc.name AS collection_name\nFROM nft_holders nh\nJOIN nft_metadata nm ON nh.contract_address = nm.contract_address\n AND nh.token_id = nm.token_id\nJOIN nft_collections nc ON nh.contract_address = nc.contract_address\n AND nc.blockchain = 'Ethereum'\nWHERE nh.contract_address = '0xabc123'\n AND nh.token_id = '100';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata ( object_id varchar NOT NULL, coin_type varchar NOT NULL, status varchar NOT NULL, decimals bigint NOT NULL, description varchar NOT NULL, icon_url varchar NOT NULL, symbol varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id varchar NOT NULL, status varchar NOT NULL, collection_type varchar NOT NULL, package_id varchar NOT NULL, previous_transaction varchar NOT NULL, display varchar NOT NULL, owner varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar 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 )\nCREATE TABLE token_activities ( 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 NOT NULL, tick varchar 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 )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE 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 )\nCREATE TABLE token_activities_bitcoin ( 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(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE 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 )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\n"} {"conversations": [{"content": "Show me the object ID, coin type, and balance for all SUI coins where the status is 'active'.", "role": "user"}, {"content": "SELECT object_id, coin_type, balance FROM sui_coins WHERE status = 'active'", "role": "assistant"}, {"content": "Also, include the owner address in the result.", "role": "user"}, {"content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active'", "role": "assistant"}, {"content": "Filter the results to only show coins where the balance is greater than '100000000000'.", "role": "user"}, {"content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active' AND CAST(balance AS NUMERIC) > 100000000000", "role": "assistant"}, {"content": "Sort the results by balance in descending order and limit the output to 10.", "role": "user"}, {"content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active' AND CAST(balance AS NUMERIC) > 100000000000 ORDER BY CAST(balance AS NUMERIC) DESC LIMIT 10", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar 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 )\nCREATE TABLE token_activities ( 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 NOT NULL, tick varchar 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 )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_activities_bitcoin ( 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(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE 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 )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) 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, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )\n"} {"conversations": [{"content": "List the plan_id, plan_name, and plan_type for all insurance plans where the insurance_provider is 'Humana'.", "role": "user"}, {"content": "SELECT\n plan_id,\n plan_name,\n plan_type\nFROM healthcare.insurance_plans\nWHERE\n insurance_provider = 'Humana';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\n"} {"conversations": [{"content": "Show the plan name and insurance provider for all insurance plans along with the total number of unique patients enrolled in each plan.", "role": "user"}, {"content": "SELECT ip.plan_name, ip.insurance_provider, COUNT(DISTINCT pi.patient_id) AS enrolled_patient_count\nFROM healthcare.insurance_plans ip\nJOIN healthcare.patients_insurance pi ON ip.plan_id = pi.plan_id\nGROUP BY ip.plan_name, ip.insurance_provider;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n"} {"conversations": [{"content": "How many hashtags have been created in March 2024?", "role": "user"}, {"content": "```sql\nSELECT COUNT(*) AS march_2024_hashtag_count\nFROM social_media.hashtags\nWHERE created_at >= '2024-03-01'\n AND created_at < '2024-04-01';\n```", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE 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 )\n"} {"conversations": [{"content": "Find all pairs of transactions that occurred in the same block and were sent to the same address. Show both transaction IDs, the shared recipient address, and the block number.", "role": "user"}, {"content": "SELECT t1.transaction_id AS tx1,\n t2.transaction_id AS tx2,\n t1.to_address,\n t1.block_number\nFROM transactions t1\nJOIN transactions t2\n ON t1.to_address = t2.to_address\n AND t1.block_number = t2.block_number\n AND t1.transaction_id < t2.transaction_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "Return the count of comments for each hashtag.", "role": "user"}, {"content": "SELECT ph.hashtag_id,\n h.tag_name,\n COUNT(c.comment_id) AS comment_count\nFROM social_media.post_hashtags ph\nJOIN social_media.hashtags h\n ON ph.hashtag_id = h.hashtag_id\nJOIN social_media.comments c\n ON ph.post_id = c.post_id\nGROUP BY ph.hashtag_id, h.tag_name;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id text PRIMARY KEY, post_id text, hashtag_id text )\nCREATE 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 )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE 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 )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n"} {"conversations": [{"content": "How many unique patient records are there for each gender?", "role": "user"}, {"content": "SELECT gender, COUNT(DISTINCT patient_id) AS patient_count FROM healthcare.patients GROUP BY gender;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id.text, first_name.text, last_name.text, date_of_birth.date, gender.text, address.text, phone_number.text, email.text, emergency_contact_name.text, emergency_contact_phone.text, created_at.timestamp, updated_at.timestamp )\n"} {"conversations": [{"content": "Summarize the accounts table by account type and currency, showing the average balance for each combination.", "role": "user"}, {"content": "SELECT account_type, currency, AVG(balance) AS average_balance, COUNT(account_id) AS account_count FROM financial_services.accounts GROUP BY account_type, currency ORDER BY account_type, currency;", "role": "assistant"}, {"content": "Only include combinations where the average balance is greater than 5000.", "role": "user"}, {"content": "SELECT account_type, currency, AVG(balance) AS average_balance, COUNT(account_id) AS account_count FROM financial_services.accounts GROUP BY account_type, currency HAVING AVG(balance) > 5000 ORDER BY average_balance DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts (\n account_id character varying(64) NOT NULL, -- unique identifier for the account\n customer_id character varying(64) NOT NULL, -- foreign key linking to the customer\n account_number character varying(128) NOT NULL UNIQUE, -- unique account number visible to customer\n account_type character varying(50) NOT NULL, -- e.g., Checking, Savings, Investment, Loan, Credit Card\n balance numeric(19, 4) NOT NULL DEFAULT 0.00, -- current account balance\n currency character varying(3) NOT NULL, -- currency code (e.g., USD, EUR)\n opened_date date NOT NULL, -- date the account was opened\n status character varying(32) NOT NULL, -- e.g., Open, Closed, Frozen\n interest_rate numeric(5, 4), -- annual interest rate, if applicable\n last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last account update\n PRIMARY KEY (account_id),\n FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id)\n)\n"} {"conversations": [{"content": "List every diagnosis description paired with every insurance plan's website.", "role": "user"}, {"content": "SELECT T1.description, T2.website FROM healthcare.diagnoses AS T1 CROSS JOIN healthcare.insurance_plans AS T2;", "role": "assistant"}, {"content": "Only include chronic diagnoses and plans whose website ends with '.org'.", "role": "user"}, {"content": "SELECT T1.description, T2.website FROM healthcare.diagnoses AS T1 CROSS JOIN healthcare.insurance_plans AS T2 WHERE T1.is_chronic = true AND T2.website LIKE '%.org';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n"} {"conversations": [{"content": "Could you provide the total number of game sessions and the number of distinct players for each game genre? Display the genre, session count, and player count.", "role": "user"}, {"content": "SELECT g.genre, COUNT(gs.session_id) AS session_count, COUNT(DISTINCT gs.player_id) AS player_count FROM gaming_technology.game_sessions AS gs JOIN gaming_technology.games AS g ON gs.game_id = g.game_id WHERE g.genre IS NOT NULL GROUP BY g.genre ORDER BY g.genre;", "role": "assistant"}, {"content": "Thanks. Can you modify the query to only include games that were released after the year 2020?", "role": "user"}, {"content": "SELECT g.genre, COUNT(gs.session_id) AS session_count, COUNT(DISTINCT gs.player_id) AS player_count FROM gaming_technology.game_sessions AS gs JOIN gaming_technology.games AS g ON gs.game_id = g.game_id WHERE g.genre IS NOT NULL AND g.release_date >= '2021-01-01' GROUP BY g.genre ORDER BY g.genre;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\n"} {"conversations": [{"content": "Show me all home loans (loan_id, principal_amount, interest_rate) where the current principal balance is more than 75% of the original principal amount, along with the account_id and employee details (first_name, last_name) of the employee who processed the loan application.", "role": "user"}, {"content": "SELECT l.loan_id, l.principal_amount, l.interest_rate, l.account_id, e.first_name, e.last_name FROM financial_services.loans l JOIN financial_services.employees e ON l.account_id = e.employee_id WHERE l.loan_type = 'Home' AND l.current_principal_balance > (l.principal_amount * 0.75)", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE financial_services.employees ( employee_id.text, first_name.text, last_name.text, job_title.text, department.text, branch_id.text, email.text, phone_extension.text, hire_date.date, termination_date.date, manager_id.text, status.text )\nCREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )\n"} {"conversations": [{"content": "Provide a count of notifications, separated by whether they have been read or not.", "role": "user"}, {"content": "SELECT CASE WHEN T1.read_at IS NULL THEN 'Unread' ELSE 'Read' END, count(T1.notification_id) FROM trading_platform.notifications AS T1 GROUP BY CASE WHEN T1.read_at IS NULL THEN 'Unread' ELSE 'Read' END", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"content": "Find all wallets created by users in the last 7 days along with any tokens that have a total supply greater than 10 million, showing the wallet address and token details.", "role": "user"}, {"content": "SELECT w.address AS wallet_address, t.token_name, t.token_symbol, t.total_supply, t.contract_address FROM web3.wallets w JOIN web3.tokens t ON t.total_supply > 10000000 WHERE w.created_at >= CURRENT_DATE - INTERVAL '7 days';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, contract_address character varying(128) NOT NULL, token_name character varying(128) NOT NULL, token_symbol character varying(32) NOT NULL, decimals integer NOT NULL, total_supply numeric(38,14) NOT NULL, PRIMARY KEY (token_id) )\nCREATE TABLE web3.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\n"} {"conversations": [{"content": "Show me all insurance plans that have more than 5 patients enrolled as their primary insurance, along with the provider name and count of patients, sorted by patient count in descending order.", "role": "user"}, {"content": "SELECT ip.insurance_provider, ip.plan_name, COUNT(pi.patient_id) AS patient_count FROM healthcare.insurance_plans ip JOIN healthcare.patient_insurance pi ON ip.plan_id = pi.plan_id WHERE pi.is_primary = true GROUP BY ip.insurance_provider, ip.plan_name HAVING COUNT(pi.patient_id) > 5 ORDER BY patient_count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\n"} {"conversations": [{"content": "Find all pairs of users where the registration times are within 30 minutes of each other, and show both user IDs, usernames, and the time difference in minutes.", "role": "user"}, {"content": "SELECT u1.user_id AS user1_id, u1.username AS user1_name, u2.user_id AS user2_id, u2.username AS user2_name, ROUND(ABS(EXTRACT(EPOCH FROM u1.created_at - u2.created_at))/60,2) AS diff_minutes FROM web3.users u1 JOIN web3.users u2 ON u1.user_id < u2.user_id WHERE ABS(EXTRACT(EPOCH FROM u1.created_at - u2.created_at))/60 <= 30;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\n"} {"conversations": [{"content": "List the patient ID and subscriber name for all patients who have both at least one diagnosis recorded and at least one primary insurance policy.", "role": "user"}, {"content": "SELECT DISTINCT pi.patient_id, pi.subscriber_name FROM healthcare.patient_insurance pi JOIN healthcare.diagnoses d ON pi.patient_id = d.patient_id WHERE pi.is_primary = true;", "role": "assistant"}, {"content": "Refine this list to only include patients whose most recent diagnosis is marked as chronic.", "role": "user"}, {"content": "WITH LatestDiagnosis AS ( SELECT patient_id, diagnosis_id, diagnosis_date, is_chronic, ROW_NUMBER() OVER(PARTITION BY patient_id ORDER BY diagnosis_date DESC) as rn FROM healthcare.diagnoses ) SELECT DISTINCT pi.patient_id, pi.subscriber_name FROM healthcare.patient_insurance pi JOIN LatestDiagnosis ld ON pi.patient_id = ld.patient_id WHERE pi.is_primary = true AND ld.rn = 1 AND ld.is_chronic = true;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )\n"} {"conversations": [{"content": "How many participants are there in each conversation? Return conversation_id and participant_count.", "role": "user"}, {"content": "SELECT conversation_id,\n COUNT(*) AS participant_count\nFROM social_media.conversation_participants\nGROUP BY conversation_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n"} {"conversations": [{"content": "What is the average number of wallets each user owns?", "role": "user"}, {"content": "SELECT\n AVG(wallet_count) AS avg_wallets_per_user\nFROM (\n SELECT user_id, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY user_id\n) AS sub;", "role": "assistant"}, {"content": "Actually, calculate the average only for users who own more than one wallet.", "role": "user"}, {"content": "SELECT\n AVG(wallet_count) AS avg_wallets_per_user\nFROM (\n SELECT user_id, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY user_id\n HAVING COUNT(*) > 1\n) AS sub;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\n"} {"conversations": [{"content": "Count the number of users for each location where the location is not empty.", "role": "user"}, {"content": "SELECT location, COUNT(user_id) FROM social_media.users WHERE location IS NOT NULL AND location != '' GROUP BY location;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "What is the history of incidents or accidents that occurred on platform 5 at station GHI?", "role": "user"}, {"content": "I'm sorry, but I can't provide information about the history of incidents or accidents on platform 5 at station GHI. My data is limited to the structural and operational details of the platforms, such as platform ID, station ID, and status. For incident history, you may need to consult a different database or contact the relevant authorities.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.platforms ( platform_id.text, station_id.text, platform_number.text, track_number.text, status.text, length_meters.numeric, accessible.boolean )\n"} {"conversations": [{"content": "What is the fuel consumption rate of train number T1234?", "role": "user"}, {"content": "I'm sorry, but I don't have information on the fuel consumption rate of train number T1234. The data available in the system only includes details such as train ID, model, manufacturer, year manufactured, capacity, status, and maintenance dates.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.trains ( train_id character varying(64) NOT NULL, train_number character varying(32) NOT NULL, model character varying(128), manufacturer character varying(128), year_manufactured integer, capacity integer NOT NULL, status character varying(32) NOT NULL DEFAULT 'Active', last_maintenance_date date, next_maintenance_date date, PRIMARY KEY (train_id), UNIQUE (train_number) )\n"} {"conversations": [{"content": "List the first_name, last_name, and email of all clients whose email domain is 'lawfirm.com'.", "role": "user"}, {"content": "SELECT first_name,\n last_name,\n email\nFROM legal_services.clients\nWHERE split_part(email, '@', 2) = 'lawfirm.com';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\nCREATE 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 )\nCREATE TABLE legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, 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 )\n"} {"conversations": [{"content": "List the usernames and emails of users who have set a location in their profile.", "role": "user"}, {"content": "SELECT username, email\nFROM social_media.users\nWHERE location IS NOT NULL AND location != '';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id text, post_id text, hashtag_id text )\nCREATE TABLE social_media.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id text, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE 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 )\n"} {"conversations": [{"content": "Show me the top 5 projects by valuation that completed fundraising rounds in the last 3 months, along with their narrative information if available.", "role": "user"}, {"content": "SELECT pfr.project_name, pfr.valuation, pfr.rounds_name, pfr.investment_date, ni.narrative, ni.trend_rank FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name LEFT JOIN narrative_info ni ON tbi.narrative = ni.narrative WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) ORDER BY pfr.valuation DESC LIMIT 5;", "role": "assistant"}, {"content": "Can you also include the 24-hour trading volume for these projects' narratives and filter to only include projects with valuation over $50 million?", "role": "user"}, {"content": "SELECT pfr.project_name, pfr.valuation, pfr.rounds_name, pfr.investment_date, ni.narrative, ni.trend_rank, ni.volume_24h FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name LEFT JOIN narrative_info ni ON tbi.narrative = ni.narrative WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND pfr.valuation > 50000000 ORDER BY pfr.valuation DESC LIMIT 5;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\nCREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, chain character varying(128) NOT NULL, address character varying(128) NOT NULL, exchange character varying(512) NOT NULL, token_address character varying(128) NOT NULL, token_symbol character varying(512), balance numeric(38,10), usd_value numeric(38,14), price double precision )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\n"} {"conversations": [{"content": "\u7279\u5b9a\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u5728\u5eab\u60c5\u5831\u3092\u53d6\u5f97\u3057\u305f\u3044\u3067\u3059\u3002\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8ID\u3068\u5728\u5eab\u6570\u91cf\u3001\u5009\u5eab\u306e\u5834\u6240\u3092\u542b\u3081\u3066\u304f\u3060\u3055\u3044\u3002", "role": "user"}, {"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id';", "role": "assistant"}, {"content": "\u3055\u3089\u306b\u3001\u53d7\u3051\u53d6\u308a\u65e5\u304c2022\u5e74\u4ee5\u964d\u306e\u8a18\u9332\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3067\u304d\u307e\u3059\u304b\uff1f", "role": "user"}, {"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01';", "role": "assistant"}, {"content": "\u5728\u5eab\u6570\u91cf\u304c100\u672a\u6e80\u306e\u3082\u306e\u3060\u3051\u306b\u7d5e\u308a\u8fbc\u3080\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u304b\uff1f", "role": "user"}, {"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01' AND quantity < 100;", "role": "assistant"}, {"content": "\u6700\u5f8c\u306b\u3001\u53d7\u3051\u53d6\u308a\u65e5\u3092\u65b0\u3057\u3044\u9806\u306b\u4e26\u3079\u66ff\u3048\u3066\u304f\u3060\u3055\u3044\u3002", "role": "user"}, {"content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01' AND quantity < 100 ORDER BY received_date DESC;", "role": "assistant"}], "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. \n##Table Structure\nIndex 'component_inventory'. Mapping: { properties: { inventory_record_id: { type: 'keyword' }, component_id: { type: 'keyword' }, quantity: { type: 'integer' }, location_warehouse: { type: 'keyword' }, location_bin: { type: 'keyword' }, received_date: { type: 'date' }, expiry_date: { type: 'date' }, batch_number: { type: 'keyword' }, last_updated: { type: 'date' } } }. Document _id can be inventory_record_id.\n"} {"conversations": [{"content": "What are the fuel consumption rates per hour for the Boeing 747-8 model?", "role": "user"}, {"content": "I'm sorry, but I can't provide information on the fuel consumption rates for the Boeing 747-8 model as this data is not included in the aircraft_models table. The table contains details such as model name, manufacturer, passenger capacity, and other specifications, but fuel consumption data is not available. If you have another question or need assistance with something else related to the table, I'm happy to help.", "role": "assistant"}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.aircraft_models ( model_id.text, model_name.text, manufacturer.text, passenger_capacity.integer, max_range_km.integer, engine_type.text, wingspan_m.numeric, status.text, first_flight_date.date )\n"} {"conversations": [{"content": "Now, sort the results by the date opened, oldest first, and show only the top 10.", "role": "user"}, {"content": "SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE lead_lawyer_id = 'lawyer_abc' AND status = 'Open' AND case_type = 'Criminal' ORDER BY date_opened ASC LIMIT 10;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"content": "Get the number of agents grouped by status. Return status and agent_count.", "role": "user"}, {"content": "SELECT status,\n COUNT(*) AS agent_count\n FROM insurance.agents\n GROUP BY status;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\n"} {"conversations": [{"content": "List all ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses.", "role": "user"}, {"content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.contract_address WHERE tm.is_erc20 = 1 AND tpl.price BETWEEN 1 AND 10;", "role": "assistant"}, {"content": "I think there's an error in your query - the token_prices_latest table isn't in the schema. Can you modify it to use the token_balances table instead?", "role": "user"}, {"content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_balances tb ON tm.contract_address = tb.wallet_address WHERE tm.is_erc20 = 1 AND CAST(tb.amount AS decimal) BETWEEN 1 AND 10;", "role": "assistant"}, {"content": "That doesn't seem right either. Let's just get the basic ERC20 token information without price filtering for now.", "role": "user"}, {"content": "SELECT name, symbol, contract_address FROM token_metas WHERE is_erc20 = 1 LIMIT 100;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE 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 )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_avalanche ( 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 )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n"} {"conversations": [{"content": "Provide a count of how many peers were last seen on each distinct day recorded in the system.", "role": "user"}, {"content": "SELECT DATE(last_seen), COUNT(*) FROM trading_platform.peers GROUP BY DATE(last_seen) ORDER BY DATE(last_seen);", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\nCREATE TABLE trading_platform.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id text, transaction_id text, output_index integer, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id text, ip_address text, port integer, last_seen timestamp )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n"} {"conversations": [{"content": "How many documents are there for each document_type? Show document_type and count ordered by the count in descending order.", "role": "user"}, {"content": "SELECT document_type,\n COUNT(*) AS count\nFROM legal_services.documents\nGROUP BY document_type\nORDER BY count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\n"} {"conversations": [{"content": "Find cases where an address received tokens in one transfer and then sent tokens in another. List the receive transfer_id, the send transfer_id, the address, and both transfer values.", "role": "user"}, {"content": "SELECT recv.transfer_id AS receive_transfer_id,\n send.transfer_id AS send_transfer_id,\n recv.to_address AS address,\n recv.value AS received_value,\n send.value AS sent_value\nFROM web3.token_transfers recv\nJOIN web3.token_transfers send\n ON recv.to_address = send.from_address;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\n"} {"conversations": [{"content": "How many distinct ports have been used by peers in the system?", "role": "user"}, {"content": "SELECT COUNT(DISTINCT port) AS distinct_port_count\nFROM trading_platform.peers;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\nCREATE TABLE trading_platform.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.assets (\n asset_id character varying(64) NOT NULL, -- unique identifier for the asset\n name character varying(128) NOT NULL, -- name of the asset\n symbol character varying(32) NOT NULL, -- symbol of the asset\n type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)\n PRIMARY KEY (asset_id)\n)\nCREATE TABLE trading_platform.utxos (\n utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO\n output_index integer NOT NULL, -- index of the output in the transaction\n address character varying(128) NOT NULL, -- address that can spend the UTXO\n amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO\n spent boolean NOT NULL, -- whether the UTXO has been spent\n PRIMARY KEY (utxo_id)\n)\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id.text, user_id.text, status.text, reviewed_at.timestamp )\nCREATE TABLE trading_platform.logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the log entry\n user_id character varying(64), -- identifier of the user associated with the log entry\n action character varying(128) NOT NULL, -- action performed\n details text NOT NULL, -- details of the action\n logged_at timestamp NOT NULL, -- time when the log entry was created\n PRIMARY KEY (log_id)\n)\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"content": "List all unique claim handler IDs present in the claims table.", "role": "user"}, {"content": "SELECT DISTINCT claim_handler_id FROM insurance.claims WHERE claim_handler_id IS NOT NULL", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\n"} {"conversations": [{"content": "Find all medical records where the vitals JSON field contains a blood pressure reading with systolic higher than 140, and show the patient_id, record_date, and vitals.", "role": "user"}, {"content": "SELECT patient_id, record_date, vitals FROM healthcare.medical_records WHERE (vitals->>'blood_pressure_systolic')::integer > 140;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\n"} {"conversations": [{"content": "For each asset, I want to know how many orders have the status 'filled', showing the asset symbol.", "role": "user"}, {"content": "SELECT m.value AS asset_symbol,\n COUNT(*) AS filled_order_count\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m\n ON o.asset_id = m.asset_id\n AND m.key = 'symbol'\nWHERE o.status = 'filled'\nGROUP BY m.value;", "role": "assistant"}, {"content": "Include assets that have zero filled orders, showing filled_order_count as 0.", "role": "user"}, {"content": "WITH asset_symbols AS (\n SELECT DISTINCT asset_id,\n value AS asset_symbol\n FROM trading_platform.metadata\n WHERE key = 'symbol'\n)\nSELECT a.asset_symbol,\n COALESCE(f.filled_order_count, 0) AS filled_order_count\nFROM asset_symbols a\nLEFT JOIN (\n SELECT asset_id,\n COUNT(*) AS filled_order_count\n FROM trading_platform.orders\n WHERE status = 'filled'\n GROUP BY asset_id\n) f\n ON a.asset_id = f.asset_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\nCREATE TABLE trading_platform.orders (\n order_id character varying(64) NOT NULL, -- unique identifier for the order\n user_id character varying(64) NOT NULL, -- identifier of the user placing the order\n wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)\n created_at timestamp NOT NULL, -- time when the order was created\n PRIMARY KEY (order_id)\n)\nCREATE TABLE trading_platform.dapps (\n dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp\n name character varying(128) NOT NULL, -- name of the DApp\n description text NOT NULL, -- description of the DApp\n url character varying(256) NOT NULL, -- URL of the DApp\n PRIMARY KEY (dapp_id)\n)\nCREATE TABLE trading_platform.peers (\n peer_id character varying(64) NOT NULL, -- unique identifier for the peer\n ip_address character varying(15) NOT NULL, -- IP address of the peer\n port integer NOT NULL, -- port number of the peer\n last_seen timestamp NOT NULL, -- last time the peer was active\n PRIMARY KEY (peer_id)\n)\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the log entry\n user_id character varying(64), -- identifier of the user associated with the log entry\n action character varying(128) NOT NULL, -- action performed\n details text NOT NULL, -- details of the action\n logged_at timestamp NOT NULL, -- time when the log entry was created\n PRIMARY KEY (log_id)\n)\n"} {"conversations": [{"content": "\u80fd\u5426\u5e2e\u6211\u67e5\u8be2\u7279\u5b9a\u8def\u7ebf(route_id \u4e3a 'route_ne_corr')\u4e0a\u7684\u6240\u6709\u8f66\u7ad9\u4fe1\u606f\uff0c\u5e76\u5305\u542b\u6bcf\u4e2a\u8f66\u7ad9\u7684\u5e73\u53f0\u6570\u91cf\uff1f", "role": "user"}, {"content": "ZRANGE route:route_ne_corr:stops 0 -1\nHGETALL route_station: for each route_station_id in result\nHGETALL station: for each station_id in result\nSCARD station::platforms for each station_id in result", "role": "assistant"}, {"content": "\u80fd\u5426\u5c06\u7ed3\u679c\u6309\u7167\u8f66\u7ad9\u7684\u987a\u5e8f(sequence_order)\u8fdb\u884c\u6392\u5e8f\uff1f", "role": "user"}, {"content": "ZRANGE route:route_ne_corr:stops 0 -1 WITHSCORES\nHGETALL route_station: for each route_station_id in result\nHGETALL station: for each station_id in result\nSCARD station::platforms for each station_id in result\nSort results by sequence_order (score from ZRANGE)", "role": "assistant"}, {"content": "\u80fd\u5426\u53ea\u663e\u793a\u6709\u8d85\u8fc75\u4e2a\u5e73\u53f0\u7684\u8f66\u7ad9\u4fe1\u606f\uff1f", "role": "user"}, {"content": "ZRANGE route:route_ne_corr:stops 0 -1 WITHSCORES\nHGETALL route_station: for each route_station_id in result\nHGETALL station: for each station_id in result\nSCARD station::platforms for each station_id in result\nFilter results where SCARD result > 5\nSort results by sequence_order (score from ZRANGE)", "role": "assistant"}], "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. \n##Table Structure\n// Use Hashes to store station details. Key format: station:\n// Example:\n// HSET station:station_xyz station_id \"station_xyz\" station_name \"Grand Central Terminal\" city \"New York\" state_province \"NY\" country_code \"USA\" address \"89 E 42nd St...\" timezone \"America/New_York\" number_of_platforms 44 created_at \"2023-01-15T10:00:00Z\" last_updated_at \"2023-10-28T15:30:00Z\"\n\n// To quickly find stations by city (optional index):\n// SADD stations:city:NewYork station:station_xyz\n// Use Hashes for platform details. Key format: platform:\n// HSET platform:plat_123 platform_id \"plat_123\" station_id \"station_xyz\" platform_number \"1A\" track_number \"T1\" status \"Operational\" length_meters 250.50 accessible 1\n\n// To link platforms to stations (optional):\n// SADD station:station_xyz:platforms platform:plat_123 platform:plat_456\n// Use Hashes for train details. Key format: train:\n// HSET train:train_789 train_id \"train_789\" train_number \"Acela 2151\" model \"Siemens Velaro\" ... status \"Active\" ...\n\n// To find train by train_number (optional index):\n// SET train_number:\"Acela 2151\" train:train_789\n// Use Hashes for car details. Key format: car:\n// HSET car:car_abc car_id \"car_abc\" train_id \"train_789\" car_number \"C3\" car_type \"Passenger\" class \"Business\" capacity 60 features \"WiFi,Power Outlet\"\n\n// To link cars to trains (optional):\n// SADD train:train_789:cars car:car_abc car:car_def\n// Use Hashes for route details. Key format: route:\n// HSET route:route_ne_corr route_id \"route_ne_corr\" route_name \"Northeast Corridor\" ... origin_station_id \"station_bos\" ... is_active 1\n// Use Hashes for details. Key format: route_station:\n// HSET route_station:rs_ne_1 route_station_id \"rs_ne_1\" route_id \"route_ne_corr\" station_id \"station_bos\" sequence_order 1 ...\n\n// To find stops for a route, use a Sorted Set (score by sequence_order):\n// ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1\n// ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2\n// Use Hashes for passenger details. Key format: passenger:\n// HSET passenger:pass_pqr passenger_id \"pass_pqr\" first_name \"Alice\" last_name \"Smith\" email \"alice.smith@example.com\" ...\n\n// To find passenger by email (optional index):\n// SET passenger_email:\"alice.smith@example.com\" passenger:pass_pqr\n// Use Hashes for booking details. Key format: booking:\n// HSET booking:book_zyx booking_id \"book_zyx\" passenger_id \"pass_pqr\" schedule_id \"sched_1122\" ... status \"Confirmed\" ...\n\n// To link bookings to passengers/schedules (optional):\n// SADD passenger:pass_pqr:bookings booking:book_zyx\n// SADD schedule:sched_1122:bookings booking:book_zyx\n// Use Hashes for ticket details. Key format: ticket:\n// HSET ticket:tkt_1a2b ticket_id \"tkt_1a2b\" booking_id \"book_zyx\" car_id \"car_abc\" seat_number \"12A\" ... is_checked_in 0 ...\n\n// To link tickets to bookings (optional):\n// SADD booking:book_zyx:tickets ticket:tkt_1a2b\n"} {"conversations": [{"content": "How many notifications have been sent for comments in total?", "role": "user"}, {"content": "SELECT COUNT(*)\nFROM social_media.notifications\nWHERE target_entity_type = 'comment';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users ( user_id.text, username.text, email.text, password_hash.text, full_name.text, profile_picture_url.text, bio.text, location.text, created_at.timestamp, updated_at.timestamp, is_verified.boolean )\nCREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"content": "List all auto loans (loan_id, principal_amount, interest_rate) where the current principal balance is less than 40% of the original principal amount, along with the account_id and the difference between principal_amount and current_principal_balance.", "role": "user"}, {"content": "SELECT loan_id, principal_amount, interest_rate, account_id, (principal_amount - current_principal_balance) AS amount_paid FROM financial_services.loans WHERE loan_type = 'Auto' AND current_principal_balance < (0.4 * principal_amount);", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )\n"} {"conversations": [{"content": "List all pairs of token IDs that share the same decimals value, and show the shared decimals.", "role": "user"}, {"content": "SELECT t1.token_id AS token1_id,\n t2.token_id AS token2_id,\n t1.decimals\nFROM web3.tokens t1\nJOIN web3.tokens t2\n ON t1.decimals = t2.decimals\n AND t1.token_id < t2.token_id;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\n"} {"conversations": [{"content": "For each state, count the number of customers and display state as state and the count as customer_count, ordered by customer_count descending.", "role": "user"}, {"content": "SELECT state,\n COUNT(*) AS customer_count\nFROM insurance.customers\nGROUP BY state\nORDER BY customer_count DESC;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\n"} {"conversations": [{"content": "Can you provide a list of all medical records created by doctors for patients who are associated with 'PPO' type insurance plans? I need the record ID, patient ID, doctor ID, record date, and insurance plan name.", "role": "user"}, {"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.patient_id IS NOT NULL -- placeholder JOIN, fix below if you have a patient-insurance mapping table\nWHERE ip.plan_type = 'PPO';", "role": "assistant"}, {"content": "The SQL seems off because there's no direct mapping between patients and insurance_plans in the schema. Can you adjust the query so that it only lists medical records with the plan details if the doctor creating the record has a contact phone number that matches the plan's contact_phone? Still need the same output columns.", "role": "user"}, {"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL;", "role": "assistant"}, {"content": "Actually, please sort the results by record_date in descending order and return only the latest 20 records.", "role": "user"}, {"content": "SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL\nORDER BY mr.record_date DESC\nLIMIT 20;", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n"} {"conversations": [{"content": "Find the names of service locations where services categorized as 'Licensing' have had appointments scheduled.", "role": "user"}, {"content": "SELECT DISTINCT T1.location_name FROM service_locations AS T1 JOIN appointments AS T2 ON T1.location_id = T2.location_id JOIN services AS T3 ON T2.service_id = T3.service_id WHERE T3.category = 'Licensing';", "role": "assistant"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\n"} {"conversations": [{"role": "user", "content": "List the application reference numbers, the corresponding message subjects, and the sent dates for notifications related to each application."}, {"role": "assistant", "content": "SELECT a.reference_number, n.message_subject, n.sent_at\nFROM government_services.applications a\nJOIN government_services.notifications n ON a.application_id = n.application_id;"}, {"role": "user", "content": "Only include applications that have a status of 'Approved'."}, {"role": "assistant", "content": "SELECT a.reference_number, n.message_subject, n.sent_at\nFROM government_services.applications a\nJOIN government_services.notifications n ON a.application_id = n.application_id\nWHERE a.status = 'Approved';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.notifications ( notification_id text, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n"} {"conversations": [{"role": "user", "content": "How many users have push notifications disabled?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS user_count\nFROM social_media.user_settings\nWHERE push_notifications_enabled = false;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show a list of all DApps together with the total number of unique assets linked to each via the metadata table."}, {"role": "assistant", "content": "SELECT d.dapp_id, d.name, d.url, COUNT(DISTINCT m.asset_id) AS unique_asset_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON m.asset_id IS NOT NULL\nGROUP BY d.dapp_id, d.name, d.url;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List all pairs of lawyers who have unbilled billable time entries for the same case. Include both lawyer IDs and the case_id."}, {"role": "assistant", "content": "SELECT t1.lawyer_id AS lawyer1_id,\n t2.lawyer_id AS lawyer2_id,\n t1.case_id\nFROM legal_services.time_entries t1\nJOIN legal_services.time_entries t2\n ON t1.case_id = t2.case_id\n AND t1.is_billable = TRUE\n AND t1.is_billed = FALSE\n AND t2.is_billable = TRUE\n AND t2.is_billed = FALSE\nWHERE t1.lawyer_id <> t2.lawyer_id;"}, {"role": "user", "content": "Only include each pair once (avoid duplicate pairs)."}, {"role": "assistant", "content": "SELECT t1.lawyer_id AS lawyer1_id,\n t2.lawyer_id AS lawyer2_id,\n t1.case_id\nFROM legal_services.time_entries t1\nJOIN legal_services.time_entries t2\n ON t1.case_id = t2.case_id\n AND t1.is_billable = TRUE\n AND t1.is_billed = FALSE\n AND t2.is_billable = TRUE\n AND t2.is_billed = FALSE\nWHERE t1.lawyer_id < t2.lawyer_id;"}, {"role": "user", "content": "Sort the results by lawyer1_id and then by case_id."}, {"role": "assistant", "content": "SELECT t1.lawyer_id AS lawyer1_id,\n t2.lawyer_id AS lawyer2_id,\n t1.case_id\nFROM legal_services.time_entries t1\nJOIN legal_services.time_entries t2\n ON t1.case_id = t2.case_id\n AND t1.is_billable = TRUE\n AND t1.is_billed = FALSE\n AND t2.is_billable = TRUE\n AND t2.is_billed = FALSE\nWHERE t1.lawyer_id < t2.lawyer_id\nORDER BY t1.lawyer_id, t1.case_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.time_entries ( entry_id.text, case_id.text, lawyer_id.text, date_worked.date, hours_spent.numeric, billing_rate.numeric, description.text, is_billable.boolean, is_billed.boolean, invoice_id.text, created_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "For each post, show the number of different users who have commented on it, along with the post_id."}, {"role": "assistant", "content": "SELECT post_id, COUNT(DISTINCT user_id) AS unique_commenters\nFROM social_media.comments\nGROUP BY post_id;"}, {"role": "user", "content": "Now, show only those posts that have at least three unique commenters and include the usernames of these commenters."}, {"role": "assistant", "content": "SELECT c.post_id, u.username\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nWHERE c.post_id IN (\n SELECT post_id\n FROM social_media.comments\n GROUP BY post_id\n HAVING COUNT(DISTINCT user_id) >= 3\n);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "Find all active policies with a coverage limit of at least 1,000,000. List the policy_id, policy_number, and coverage_limit."}, {"role": "assistant", "content": "SELECT policy_id, policy_number, coverage_limit\nFROM insurance.policies\nWHERE status = 'active' AND coverage_limit >= 1000000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\n"} {"conversations": [{"role": "user", "content": "List all reservations made by guests from 'US', showing the reservation ID, guest first name, last name, and the property name."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T2.first_name, T2.last_name, T3.property_name FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.guests AS T2 ON T1.guest_id = T2.guest_id JOIN hospitality_technology.properties AS T3 ON T1.property_id = T3.property_id WHERE T2.country_code = 'US';"}, {"role": "user", "content": "Only show reservations with status 'Confirmed'."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T2.first_name, T2.last_name, T3.property_name FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.guests AS T2 ON T1.guest_id = T2.guest_id JOIN hospitality_technology.properties AS T3 ON T1.property_id = T3.property_id WHERE T2.country_code = 'US' AND T1.status = 'Confirmed';"}, {"role": "user", "content": "Also include the check-in and check-out dates, and order by check-in date descending."}, {"role": "assistant", "content": "SELECT T1.reservation_id, T2.first_name, T2.last_name, T3.property_name, T1.check_in_date, T1.check_out_date FROM hospitality_technology.reservations AS T1 JOIN hospitality_technology.guests AS T2 ON T1.guest_id = T2.guest_id JOIN hospitality_technology.properties AS T3 ON T1.property_id = T3.property_id WHERE T2.country_code = 'US' AND T1.status = 'Confirmed' ORDER BY T1.check_in_date DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE 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) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE 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 )\nCREATE TABLE hospitality_technology.payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment transaction\n reservation_id character varying(64), -- FK to reservations (if payment is for a stay)\n guest_id character varying(64) NOT NULL, -- FK to guests (who paid)\n bill_id character varying(64), -- FK to bills/invoices this payment applies to\n amount numeric(12,2) NOT NULL, -- amount of the payment\n currency_code character varying(3) NOT NULL, -- ISO currency code (e.g., USD, EUR)\n payment_method character varying(50) NOT NULL, -- e.g., CreditCard, Cash, BankTransfer, Points, Voucher\n card_type character varying(50), -- e.g., Visa, MasterCard, Amex (if CC)\n card_last_four character varying(4), -- last 4 digits of CC (if CC)\n transaction_ref character varying(128), -- reference ID from payment gateway or processor\n payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the payment occurred\n status character varying(50) NOT NULL, -- e.g., Pending, Succeeded, Failed, Refunded, Disputed\n staff_id_processed character varying(64), -- FK to staff (who processed the payment)\n notes text, -- notes about the payment\n PRIMARY KEY (payment_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.reviews ( review_id text PRIMARY KEY, property_id text, reservation_id text, guest_id text, rating_overall int, rating_cleanliness int, rating_service int, rating_location int, rating_value int, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n"} {"conversations": [{"role": "user", "content": "Show a count of drivers per status."}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count\nFROM transportation.drivers\nGROUP BY status;"}, {"role": "user", "content": "Can you also list the earliest hire date for each status?"}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count, MIN(hire_date) AS earliest_hire_date\nFROM transportation.drivers\nGROUP BY status;"}, {"role": "user", "content": "I only want to see statuses with more than 5 drivers."}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count, MIN(hire_date) AS earliest_hire_date\nFROM transportation.drivers\nGROUP BY status\nHAVING COUNT(*) > 5;"}, {"role": "user", "content": "Please sort the output by driver_count in descending order."}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS driver_count, MIN(hire_date) AS earliest_hire_date\nFROM transportation.drivers\nGROUP BY status\nHAVING COUNT(*) > 5\nORDER BY driver_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "List each genre and the number of games in that genre."}, {"role": "assistant", "content": "SELECT genre,\n COUNT(*) AS game_count\nFROM gaming_technology.games\nGROUP BY genre;"}, {"role": "user", "content": "Now filter to only include genres with more than 5 games."}, {"role": "assistant", "content": "SELECT genre,\n COUNT(*) AS game_count\nFROM gaming_technology.games\nGROUP BY genre\nHAVING COUNT(*) > 5;"}, {"role": "user", "content": "Exclude entries where genre is NULL."}, {"role": "assistant", "content": "SELECT genre,\n COUNT(*) AS game_count\nFROM gaming_technology.games\nWHERE genre IS NOT NULL\nGROUP BY genre\nHAVING COUNT(*) > 5;"}, {"role": "user", "content": "Finally, order the results by game_count in descending order."}, {"role": "assistant", "content": "SELECT genre,\n COUNT(*) AS game_count\nFROM gaming_technology.games\nWHERE genre IS NOT NULL\nGROUP BY genre\nHAVING COUNT(*) > 5\nORDER BY game_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\n"} {"conversations": [{"role": "user", "content": "Retrieve the name and city of all locations that act as both origin and destination for any route."}, {"role": "assistant", "content": "SELECT l.name, l.city\nFROM transportation.locations l\nWHERE l.location_id IN (SELECT origin_location_id FROM transportation.routes)\n AND l.location_id IN (SELECT destination_location_id FROM transportation.routes);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\n"} {"conversations": [{"role": "user", "content": "Show me all locations in California that are of type 'gas station', including their name, city, and postal code."}, {"role": "assistant", "content": "SELECT name, city, postal_code FROM transportation.locations WHERE state_province = 'California' AND type = 'gas station';"}, {"role": "user", "content": "Now filter these results to only show gas stations in Los Angeles, and include their full address."}, {"role": "assistant", "content": "SELECT name, city, postal_code, address_line1 FROM transportation.locations WHERE state_province = 'California' AND type = 'gas station' AND city = 'Los Angeles';"}, {"role": "user", "content": "Can you also include the latitude and longitude coordinates, and order the results by postal code in ascending order?"}, {"role": "assistant", "content": "SELECT name, city, postal_code, address_line1, latitude, longitude FROM transportation.locations WHERE state_province = 'California' AND type = 'gas station' AND city = 'Los Angeles' ORDER BY postal_code ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\n"} {"conversations": [{"role": "user", "content": "How many insurance policies have 'Group' in their group_number?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM healthcare.patient_insurance WHERE group_number ILIKE '%Group%';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n"} {"conversations": [{"role": "user", "content": "For each transaction, find its immediate next transaction by the same sender, listing the original transaction_id, the next transaction_id, and the time difference in minutes between them."}, {"role": "assistant", "content": "SELECT t1.transaction_id AS current_tx, t2.transaction_id AS next_tx, EXTRACT(EPOCH FROM (t2.timestamp - t1.timestamp)) / 60 AS diff_minutes FROM web3.transactions t1 JOIN web3.transactions t2 ON t2.from_address = t1.from_address AND t2.timestamp = (SELECT MIN(timestamp) FROM web3.transactions WHERE from_address = t1.from_address AND timestamp > t1.timestamp);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.transactions ( transaction_id text PRIMARY KEY, from_address text, to_address text, value numeric, gas_used int, gas_price numeric, block_number int, timestamp timestamp, input_data text, status text, nonce int )\n"} {"conversations": [{"role": "user", "content": "Show all payments made for reservations that had more than 2 adults. Include the payment ID, amount, currency, reservation ID, guest full name, and the number of adults in the reservation."}, {"role": "assistant", "content": "SELECT T1.payment_id, T1.amount, T1.currency_code, T1.reservation_id, T3.first_name, T3.last_name, T2.num_adults FROM hospitality_technology.payments AS T1 JOIN hospitality_technology.reservations AS T2 ON T1.reservation_id = T2.reservation_id JOIN hospitality_technology.guests AS T3 ON T1.guest_id = T3.guest_id WHERE T2.num_adults > 2;"}, {"role": "user", "content": "Filter these payments to only include those with a status of 'Succeeded'. Also, include the property name associated with the reservation."}, {"role": "assistant", "content": "SELECT T1.payment_id, T1.amount, T1.currency_code, T1.reservation_id, T3.first_name, T3.last_name, T2.num_adults, T4.property_name FROM hospitality_technology.payments AS T1 JOIN hospitality_technology.reservations AS T2 ON T1.reservation_id = T2.reservation_id JOIN hospitality_technology.guests AS T3 ON T1.guest_id = T3.guest_id JOIN hospitality_technology.properties AS T4 ON T2.property_id = T4.property_id WHERE T2.num_adults > 2 AND T1.status = 'Succeeded';"}, {"role": "user", "content": "Further filter to only show payments made using the 'CreditCard' method and order the results by payment timestamp descending."}, {"role": "assistant", "content": "SELECT T1.payment_id, T1.amount, T1.currency_code, T1.reservation_id, T3.first_name, T3.last_name, T2.num_adults, T4.property_name FROM hospitality_technology.payments AS T1 JOIN hospitality_technology.reservations AS T2 ON T1.reservation_id = T2.reservation_id JOIN hospitality_technology.guests AS T3 ON T1.guest_id = T3.guest_id JOIN hospitality_technology.properties AS T4 ON T2.property_id = T4.property_id WHERE T2.num_adults > 2 AND T1.status = 'Succeeded' AND T1.payment_method = 'CreditCard' ORDER BY T1.payment_timestamp DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE 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) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE 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) )\n"} {"conversations": [{"role": "user", "content": "I need the average close_price per sector for the last month."}, {"role": "assistant", "content": "SELECT s.sector, AVG(m.close_price) AS avg_close_price\nFROM financial_services.market_data m\nJOIN financial_services.securities s ON m.security_id = s.security_id\nWHERE m.data_timestamp >= date_trunc('month', current_date) - interval '1 month'\n AND m.data_timestamp < date_trunc('month', current_date)\nGROUP BY s.sector;"}, {"role": "user", "content": "Can you also include the maximum volume per sector?"}, {"role": "assistant", "content": "SELECT s.sector,\n AVG(m.close_price) AS avg_close_price,\n MAX(m.volume) AS max_volume\nFROM financial_services.market_data m\nJOIN financial_services.securities s ON m.security_id = s.security_id\nWHERE m.data_timestamp >= date_trunc('month', current_date) - interval '1 month'\n AND m.data_timestamp < date_trunc('month', current_date)\nGROUP BY s.sector;"}, {"role": "user", "content": "Now I only want data from source 'Reuters'."}, {"role": "assistant", "content": "SELECT s.sector,\n AVG(m.close_price) AS avg_close_price,\n MAX(m.volume) AS max_volume\nFROM financial_services.market_data m\nJOIN financial_services.securities s ON m.security_id = s.security_id\nWHERE m.data_timestamp >= date_trunc('month', current_date) - interval '1 month'\n AND m.data_timestamp < date_trunc('month', current_date)\n AND m.source = 'Reuters'\nGROUP BY s.sector;"}, {"role": "user", "content": "Finally, only include sectors with total volume over 1000000 and order by avg_close_price descending."}, {"role": "assistant", "content": "SELECT s.sector,\n AVG(m.close_price) AS avg_close_price,\n MAX(m.volume) AS max_volume\nFROM financial_services.market_data m\nJOIN financial_services.securities s ON m.security_id = s.security_id\nWHERE m.data_timestamp >= date_trunc('month', current_date) - interval '1 month'\n AND m.data_timestamp < date_trunc('month', current_date)\n AND m.source = 'Reuters'\nGROUP BY s.sector\nHAVING SUM(m.volume) > 1000000\nORDER BY avg_close_price DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\n"} {"conversations": [{"role": "user", "content": "Which SUI coins are owned by the address '0xSuperOwner'? Please list the object_id, coin_type, and balance."}, {"role": "assistant", "content": "SELECT object_id, coin_type, balance\nFROM sui_coins\nWHERE owner = '0xSuperOwner';"}, {"role": "user", "content": "Add the name and symbol of each coin by joining with the sui_coins_metadata table (assume the metadata table has columns: coin_type, name, symbol)."}, {"role": "assistant", "content": "SELECT sc.object_id, sc.coin_type, sc.balance, scm.name, scm.symbol\nFROM sui_coins sc\nJOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.owner = '0xSuperOwner';"}, {"role": "user", "content": "Only include coins with a balance greater than 1,000,000."}, {"role": "assistant", "content": "SELECT sc.object_id, sc.coin_type, sc.balance, scm.name, scm.symbol\nFROM sui_coins sc\nJOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.owner = '0xSuperOwner' AND CAST(sc.balance AS DECIMAL) > 1000000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE 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 )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_info_bitcoin ( 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 )\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "List pairs of routes where one route\u2019s origin matches another route\u2019s destination. Show both route numbers."}, {"role": "assistant", "content": "SELECT r1.route_number AS route1, r2.route_number AS route2\nFROM transportation.routes r1\nJOIN transportation.routes r2\n ON r1.origin_location_id = r2.destination_location_id;"}, {"role": "user", "content": "Filter these pairs to include only those where the absolute difference in distance_km between the two routes is more than 50."}, {"role": "assistant", "content": "SELECT r1.route_number AS route1, r2.route_number AS route2, ABS(r1.distance_km - r2.distance_km) AS distance_diff\nFROM transportation.routes r1\nJOIN transportation.routes r2\n ON r1.origin_location_id = r2.destination_location_id\nWHERE ABS(r1.distance_km - r2.distance_km) > 50;"}, {"role": "user", "content": "Also include the type of each route and order the results by the distance difference descending."}, {"role": "assistant", "content": "SELECT r1.route_number AS route1, r2.route_number AS route2,\n r1.type AS type1, r2.type AS type2,\n ABS(r1.distance_km - r2.distance_km) AS distance_diff\nFROM transportation.routes r1\nJOIN transportation.routes r2\n ON r1.origin_location_id = r2.destination_location_id\nWHERE ABS(r1.distance_km - r2.distance_km) > 50\nORDER BY distance_diff DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "List all ERC20 tokens where the total supply is less than 100,000, including their names and symbols."}, {"role": "assistant", "content": "SELECT name, symbol FROM token_metas WHERE is_erc20 = 1 AND CAST(total_supply AS decimal) < 100000;"}, {"role": "user", "content": "I think there's an error in your query - it should be CAST(total_supply AS decimal) not CAST(total_supply AS decimal). Also, can you add the contract address to the results?"}, {"role": "assistant", "content": "SELECT name, symbol, contract_address FROM token_metas WHERE is_erc20 = 1 AND CAST(total_supply AS decimal) < 100000;"}, {"role": "user", "content": "Now, join this with the token_prices_latest table to include the current price of each token."}, {"role": "assistant", "content": "SELECT t.name, t.symbol, t.contract_address, p.price FROM token_metas t JOIN token_prices_latest p ON t.contract_address = p.address WHERE t.is_erc20 = 1 AND CAST(t.total_supply AS decimal) < 100000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( 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 )\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_activities_avalanche ( 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 )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "Show me all active managers along with their property names and the number of staff they supervise."}, {"role": "assistant", "content": "SELECT m.staff_id, CONCAT(m.first_name, ' ', m.last_name) AS manager_name, p.property_name, COUNT(s.staff_id) AS supervised_staff_count FROM hospitality_technology.staff m JOIN hospitality_technology.properties p ON m.property_id = p.property_id LEFT JOIN hospitality_technology.staff s ON m.staff_id = s.manager_id WHERE m.is_active = true AND m.position LIKE '%Manager%' GROUP BY m.staff_id, m.first_name, m.last_name, p.property_name;"}, {"role": "user", "content": "Now, include only managers who supervise at least 3 staff members."}, {"role": "assistant", "content": "SELECT m.staff_id, CONCAT(m.first_name, ' ', m.last_name) AS manager_name, p.property_name, COUNT(s.staff_id) AS supervised_staff_count FROM hospitality_technology.staff m JOIN hospitality_technology.properties p ON m.property_id = p.property_id LEFT JOIN hospitality_technology.staff s ON m.staff_id = s.manager_id WHERE m.is_active = true AND m.position LIKE '%Manager%' GROUP BY m.staff_id, m.first_name, m.last_name, p.property_name HAVING COUNT(s.staff_id) >= 3;"}, {"role": "user", "content": "The query should also show their email addresses and hire dates."}, {"role": "assistant", "content": "SELECT m.staff_id, CONCAT(m.first_name, ' ', m.last_name) AS manager_name, p.property_name, m.work_email, m.hire_date, COUNT(s.staff_id) AS supervised_staff_count FROM hospitality_technology.staff m JOIN hospitality_technology.properties p ON m.property_id = p.property_id LEFT JOIN hospitality_technology.staff s ON m.staff_id = s.manager_id WHERE m.is_active = true AND m.position LIKE '%Manager%' GROUP BY m.staff_id, m.first_name, m.last_name, p.property_name, m.work_email, m.hire_date HAVING COUNT(s.staff_id) >= 3;"}, {"role": "user", "content": "Actually, I need to see the results ordered by the number of supervised staff in descending order."}, {"role": "assistant", "content": "SELECT m.staff_id, CONCAT(m.first_name, ' ', m.last_name) AS manager_name, p.property_name, m.work_email, m.hire_date, COUNT(s.staff_id) AS supervised_staff_count FROM hospitality_technology.staff m JOIN hospitality_technology.properties p ON m.property_id = p.property_id LEFT JOIN hospitality_technology.staff s ON m.staff_id = s.manager_id WHERE m.is_active = true AND m.position LIKE '%Manager%' GROUP BY m.staff_id, m.first_name, m.last_name, p.property_name, m.work_email, m.hire_date HAVING COUNT(s.staff_id) >= 3 ORDER BY supervised_staff_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.staff (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\n"} {"conversations": [{"role": "user", "content": "List all pairs of games developed by the same developer, returning developer_id, title of the first game, and title of the second game."}, {"role": "assistant", "content": "SELECT g1.developer_id, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.developer_id = g2.developer_id\n AND g1.game_id < g2.game_id;"}, {"role": "user", "content": "Only include developers who have created more than 3 games."}, {"role": "assistant", "content": "SELECT g1.developer_id, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.developer_id = g2.developer_id\n AND g1.game_id < g2.game_id\nWHERE g1.developer_id IN (\n SELECT developer_id\n FROM gaming_technology.games\n GROUP BY developer_id\n HAVING COUNT(*) > 3\n);"}, {"role": "user", "content": "Also show the total number of games each developer has made alongside each pair."}, {"role": "assistant", "content": "SELECT g1.developer_id, cnt.total_games, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.developer_id = g2.developer_id\n AND g1.game_id < g2.game_id\nJOIN (\n SELECT developer_id, COUNT(*) AS total_games\n FROM gaming_technology.games\n GROUP BY developer_id\n) cnt ON g1.developer_id = cnt.developer_id\nWHERE cnt.total_games > 3;"}, {"role": "user", "content": "I only want pairs where both games were released after '2021-01-01'."}, {"role": "assistant", "content": "SELECT g1.developer_id, cnt.total_games, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.developer_id = g2.developer_id\n AND g1.game_id < g2.game_id\nJOIN (\n SELECT developer_id, COUNT(*) AS total_games\n FROM gaming_technology.games\n GROUP BY developer_id\n) cnt ON g1.developer_id = cnt.developer_id\nWHERE cnt.total_games > 3\n AND g1.release_date > '2021-01-01'\n AND g2.release_date > '2021-01-01';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\n"} {"conversations": [{"role": "user", "content": "List all pairs of tokens where the absolute difference in their decimals is exactly 2, showing both token_ids and their decimals."}, {"role": "assistant", "content": "SELECT t1.token_id AS token_id1,\n t1.decimals AS decimals1,\n t2.token_id AS token_id2,\n t2.decimals AS decimals2\nFROM web3.tokens t1\nJOIN web3.tokens t2\n ON ABS(t1.decimals - t2.decimals) = 2\n AND t1.token_id < t2.token_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )\n"} {"conversations": [{"role": "user", "content": "Show me all wallet addresses that belong to user_id 'U1001', along with their private keys."}, {"role": "assistant", "content": "SELECT address_id, private_key FROM blockchain.wallets WHERE user_id = 'U1001';"}, {"role": "user", "content": "Now join this with another table to show the count of transactions for each of these wallet addresses."}, {"role": "assistant", "content": "Note: The schema only includes the wallets table. Without a transactions table in the schema, this query cannot be executed. Please provide the transactions table structure if you need this analysis."}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.wallets ( wallet_id text, user_id text, address_id text, private_key text )\n"} {"conversations": [{"role": "user", "content": "Which services charge more than the average standard fee of their category? Show the service name, its fee, and the average fee for that category."}, {"role": "assistant", "content": "SELECT\n s.service_name,\n s.standard_fee,\n avg_fees.avg_fee\nFROM government_services.services s\nJOIN (\n SELECT\n category,\n AVG(standard_fee) AS avg_fee\n FROM government_services.services\n GROUP BY category\n) avg_fees\n ON s.category = avg_fees.category\nWHERE s.standard_fee > avg_fees.avg_fee;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )\n"} {"conversations": [{"role": "user", "content": "List all routes that have a distance greater than 100 km, showing the route number, origin and destination location IDs."}, {"role": "assistant", "content": "SELECT route_number, origin_location_id, destination_location_id FROM transportation.routes WHERE distance_km > 100;"}, {"role": "user", "content": "Can you include the estimated duration in hours instead of minutes, and filter to only show intercity routes?"}, {"role": "assistant", "content": "SELECT route_number, origin_location_id, destination_location_id, (estimated_duration_minutes/60) AS estimated_duration_hours FROM transportation.routes WHERE distance_km > 100 AND type = 'intercity';"}, {"role": "user", "content": "Now order the results by distance in descending order and include the count of bookings for each route."}, {"role": "assistant", "content": "SELECT r.route_number, r.origin_location_id, r.destination_location_id, (r.estimated_duration_minutes/60) AS estimated_duration_hours, r.distance_km, COUNT(b.booking_id) AS booking_count FROM transportation.routes r LEFT JOIN transportation.bookings b ON r.route_id = b.trip_id WHERE r.distance_km > 100 AND r.type = 'intercity' GROUP BY r.route_number, r.origin_location_id, r.destination_location_id, r.estimated_duration_minutes, r.distance_km ORDER BY r.distance_km DESC;"}, {"role": "user", "content": "I only want to see routes with more than 10 bookings and distance between 100 and 500 km."}, {"role": "assistant", "content": "SELECT r.route_number, r.origin_location_id, r.destination_location_id, (r.estimated_duration_minutes/60) AS estimated_duration_hours, r.distance_km, COUNT(b.booking_id) AS booking_count FROM transportation.routes r LEFT JOIN transportation.bookings b ON r.route_id = b.trip_id WHERE r.distance_km BETWEEN 100 AND 500 AND r.type = 'intercity' GROUP BY r.route_number, r.origin_location_id, r.destination_location_id, r.estimated_duration_minutes, r.distance_km HAVING COUNT(b.booking_id) > 10 ORDER BY r.distance_km DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id character varying(64) NOT NULL, employee_id character varying(64) NOT NULL UNIQUE, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, license_number character varying(64) NOT NULL UNIQUE, license_expiry_date date NOT NULL, contact_number character varying(32), email character varying(128) UNIQUE, hire_date date NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (driver_id) )\nCREATE TABLE transportation.routes ( route_id character varying(64) NOT NULL, route_number character varying(32) NOT NULL UNIQUE, description text, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, distance_km numeric(10, 2), estimated_duration_minutes integer, type character varying(32) NOT NULL, PRIMARY KEY (route_id) )\nCREATE TABLE transportation.passengers ( passenger_id character varying(64) NOT NULL, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32) UNIQUE, date_of_birth date, loyalty_program_id character varying(64), created_at timestamp with time zone NOT NULL, PRIMARY KEY (passenger_id) )\nCREATE 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) )\n"} {"conversations": [{"role": "user", "content": "Show me all users whose email address contains the word 'test', along with their user IDs and the date they registered."}, {"role": "assistant", "content": "SELECT user_id, username, email, created_at FROM trading_platform.users WHERE email ILIKE '%test%';"}, {"role": "user", "content": "Actually, only include users who registered after January 1, 2024, and sort them by newest registration date first."}, {"role": "assistant", "content": "SELECT user_id, username, email, created_at FROM trading_platform.users WHERE email ILIKE '%test%' AND created_at > '2024-01-01' ORDER BY created_at DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n"} {"conversations": [{"role": "user", "content": "List each blockchain (chain) and the centralized exchange that holds the highest total USD value of tokens, as well as the exchange with the lowest total USD value of tokens. Show chain, max_exchange, max_value, min_exchange, and min_value."}, {"role": "assistant", "content": "WITH totals AS (\n SELECT chain, exchange, SUM(usd_value) AS total_usd\n FROM cex_token_balance\n GROUP BY chain, exchange\n),\nmax_totals AS (\n SELECT chain, exchange AS max_exchange, total_usd AS max_value\n FROM (\n SELECT chain, exchange, total_usd,\n ROW_NUMBER() OVER (PARTITION BY chain ORDER BY total_usd DESC) AS rn\n FROM totals\n ) t\n WHERE rn = 1\n),\nmin_totals AS (\n SELECT chain, exchange AS min_exchange, total_usd AS min_value\n FROM (\n SELECT chain, exchange, total_usd,\n ROW_NUMBER() OVER (PARTITION BY chain ORDER BY total_usd ASC) AS rn\n FROM totals\n ) t\n WHERE rn = 1\n)\nSELECT m.chain, m.max_exchange, m.max_value, n.min_exchange, n.min_value\nFROM max_totals m\nJOIN min_totals n USING (chain);"}, {"role": "user", "content": "Actually, restrict the analysis to the latest snapshot_time only."}, {"role": "assistant", "content": "WITH latest AS (\n SELECT MAX(snapshot_time) AS snap\n FROM cex_token_balance\n),\ntotals AS (\n SELECT chain, exchange, SUM(usd_value) AS total_usd\n FROM cex_token_balance\n WHERE snapshot_time = (SELECT snap FROM latest)\n GROUP BY chain, exchange\n),\nmax_totals AS (\n SELECT chain, exchange AS max_exchange, total_usd AS max_value\n FROM (\n SELECT chain, exchange, total_usd,\n ROW_NUMBER() OVER (PARTITION BY chain ORDER BY total_usd DESC) AS rn\n FROM totals\n ) t WHERE rn = 1\n),\nmin_totals AS (\n SELECT chain, exchange AS min_exchange, total_usd AS min_value\n FROM (\n SELECT chain, exchange, total_usd,\n ROW_NUMBER() OVER (PARTITION BY chain ORDER BY total_usd ASC) AS rn\n FROM totals\n ) t WHERE rn = 1\n)\nSELECT m.chain, m.max_exchange, m.max_value, n.min_exchange, n.min_value\nFROM max_totals m\nJOIN min_totals n USING (chain);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n"} {"conversations": [{"role": "user", "content": "Show each player's ID and the number of different achievement IDs they have unlocked."}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT achievement_id) AS achievement_count\nFROM gaming_technology.player_achievements\ngroup by player_id;"}, {"role": "user", "content": "Now also include, for each player, the number of different item types they have in their inventory."}, {"role": "assistant", "content": "SELECT pa.player_id, COUNT(DISTINCT pa.achievement_id) AS achievement_count, COUNT(DISTINCT igi.item_type) AS item_types_owned\nFROM gaming_technology.player_achievements pa\nLEFT JOIN gaming_technology.player_inventory pi ON pa.player_id = pi.player_id\nLEFT JOIN gaming_technology.in_game_items igi ON pi.item_id = igi.item_id\nGROUP BY pa.player_id;"}, {"role": "user", "content": "Please only show players who have unlocked at least 3 achievements and own at least 2 different item types."}, {"role": "assistant", "content": "SELECT pa.player_id, COUNT(DISTINCT pa.achievement_id) AS achievement_count, COUNT(DISTINCT igi.item_type) AS item_types_owned\nFROM gaming_technology.player_achievements pa\nLEFT JOIN gaming_technology.player_inventory pi ON pa.player_id = pi.player_id\nLEFT JOIN gaming_technology.in_game_items igi ON pi.item_id = igi.item_id\nGROUP BY pa.player_id\nHAVING COUNT(DISTINCT pa.achievement_id) >= 3 AND COUNT(DISTINCT igi.item_type) >= 2;"}, {"role": "user", "content": "Sort the result by achievement_count in descending order."}, {"role": "assistant", "content": "SELECT pa.player_id, COUNT(DISTINCT pa.achievement_id) AS achievement_count, COUNT(DISTINCT igi.item_type) AS item_types_owned\nFROM gaming_technology.player_achievements pa\nLEFT JOIN gaming_technology.player_inventory pi ON pa.player_id = pi.player_id\nLEFT JOIN gaming_technology.in_game_items igi ON pi.item_id = igi.item_id\nGROUP BY pa.player_id\nHAVING COUNT(DISTINCT pa.achievement_id) >= 3 AND COUNT(DISTINCT igi.item_type) >= 2\nORDER BY achievement_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n"} {"conversations": [{"role": "user", "content": "Show the count of vehicles for each type."}, {"role": "assistant", "content": "SELECT type, COUNT(*) AS vehicle_count FROM transportation.vehicles GROUP BY type;"}, {"role": "user", "content": "Only include types where the vehicle count is greater than 2 and order the results by vehicle_count descending."}, {"role": "assistant", "content": "SELECT type, COUNT(*) AS vehicle_count FROM transportation.vehicles GROUP BY type HAVING COUNT(*) > 2 ORDER BY vehicle_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\n"} {"conversations": [{"role": "user", "content": "For each project in project_fundraising_record, show the project's earliest and latest fundraising rounds with their corresponding investment_date and investment_value. Include project_name, earliest_round, earliest_date, earliest_value, latest_round, latest_date, and latest_value."}, {"role": "assistant", "content": "SELECT\n r1.project_name,\n r1.rounds_name AS earliest_round,\n r1.investment_date AS earliest_date,\n r1.investment_value AS earliest_value,\n r2.rounds_name AS latest_round,\n r2.investment_date AS latest_date,\n r2.investment_value AS latest_value\nFROM (\n SELECT project_id, MIN(investment_date) AS min_date, MAX(investment_date) AS max_date\n FROM project_fundraising_record\n GROUP BY project_id\n) m\nJOIN project_fundraising_record r1\n ON r1.project_id = m.project_id AND r1.investment_date = m.min_date\nJOIN project_fundraising_record r2\n ON r2.project_id = m.project_id AND r2.investment_date = m.max_date;"}, {"role": "user", "content": "Actually, I also want to include the introduction for both the earliest and latest rounds."}, {"role": "assistant", "content": "SELECT\n m.project_id,\n r1.project_name,\n r1.rounds_name AS earliest_round,\n r1.investment_date AS earliest_date,\n r1.investment_value AS earliest_value,\n r1.introduction AS earliest_introduction,\n r2.rounds_name AS latest_round,\n r2.investment_date AS latest_date,\n r2.investment_value AS latest_value,\n r2.introduction AS latest_introduction\nFROM (\n SELECT project_id, MIN(investment_date) AS min_date, MAX(investment_date) AS max_date\n FROM project_fundraising_record\n GROUP BY project_id\n) m\nJOIN project_fundraising_record r1\n ON r1.project_id = m.project_id AND r1.investment_date = m.min_date\nJOIN project_fundraising_record r2\n ON r2.project_id = m.project_id AND r2.investment_date = m.max_date;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )\n"} {"conversations": [{"role": "user", "content": "How many total appointments have been recorded?"}, {"role": "assistant", "content": "SELECT count(*) FROM appointments;"}, {"role": "user", "content": "What is the count of appointments that have the status 'Completed'?"}, {"role": "assistant", "content": "SELECT count(*) FROM appointments WHERE status = 'Completed';"}, {"role": "user", "content": "For completed appointments, list the purpose and the name of the related service."}, {"role": "assistant", "content": "SELECT T1.purpose, T2.service_name FROM appointments AS T1 JOIN services AS T2 ON T1.service_id = T2.service_id WHERE T1.status = 'Completed';"}, {"role": "user", "content": "Also include the location name for these completed appointments, specifically those booked via 'Online'."}, {"role": "assistant", "content": "SELECT T1.purpose, T2.service_name, T3.location_name FROM appointments AS T1 JOIN services AS T2 ON T1.service_id = T2.service_id JOIN service_locations AS T3 ON T1.location_id = T3.location_id WHERE T1.status = 'Completed' AND T1.booking_method = 'Online';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\n"} {"conversations": [{"role": "user", "content": "List the first and last names of employees who verified documents, along with the document type they verified."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, d.document_type\nFROM government_services.documents d\nJOIN government_services.employees e ON d.verified_by_employee_id = e.employee_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id text PRIMARY KEY, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, 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 )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n"} {"conversations": [{"role": "user", "content": "For each mechanic, show the total number of maintenance logs they have performed and the average cost of these logs."}, {"role": "assistant", "content": "SELECT mechanic_name, COUNT(*) AS log_count, AVG(cost) AS average_cost FROM transportation.maintenance_logs GROUP BY mechanic_name;"}, {"role": "user", "content": "Filter this list to only show mechanics who have performed more than 5 logs and order the results by average cost descending."}, {"role": "assistant", "content": "SELECT mechanic_name, COUNT(*) AS log_count, AVG(cost) AS average_cost FROM transportation.maintenance_logs GROUP BY mechanic_name HAVING COUNT(*) > 5 ORDER BY average_cost DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\n"} {"conversations": [{"role": "user", "content": "Give me the number of achievements unlocked each day, returning unlock_date and unlock_count."}, {"role": "assistant", "content": "SELECT date_trunc('day', unlocked_at)::date AS unlock_date,\n COUNT(*) AS unlock_count\nFROM gaming_technology.player_achievements\nGROUP BY date_trunc('day', unlocked_at)::date;"}, {"role": "user", "content": "Only include days where unlock_count is greater than 10."}, {"role": "assistant", "content": "SELECT date_trunc('day', unlocked_at)::date AS unlock_date,\n COUNT(*) AS unlock_count\nFROM gaming_technology.player_achievements\nGROUP BY date_trunc('day', unlocked_at)::date\nHAVING COUNT(*) > 10;"}, {"role": "user", "content": "Also include the number of distinct players who unlocked achievements each day as player_count."}, {"role": "assistant", "content": "SELECT date_trunc('day', unlocked_at)::date AS unlock_date,\n COUNT(*) AS unlock_count,\n COUNT(DISTINCT player_id) AS player_count\nFROM gaming_technology.player_achievements\nGROUP BY date_trunc('day', unlocked_at)::date\nHAVING COUNT(*) > 10;"}, {"role": "user", "content": "Order the results by unlock_count descending."}, {"role": "assistant", "content": "SELECT date_trunc('day', unlocked_at)::date AS unlock_date,\n COUNT(*) AS unlock_count,\n COUNT(DISTINCT player_id) AS player_count\nFROM gaming_technology.player_achievements\nGROUP BY date_trunc('day', unlocked_at)::date\nHAVING COUNT(*) > 10\nORDER BY unlock_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n"} {"conversations": [{"role": "user", "content": "Show me the total fare collected from all completed bookings (status = 'completed') grouped by passenger_id."}, {"role": "assistant", "content": "SELECT passenger_id, SUM(fare) AS total_fare FROM transportation.bookings WHERE status = 'completed' GROUP BY passenger_id;"}, {"role": "user", "content": "Now include only passengers who have spent more than $200 in total and order by total_fare in descending order."}, {"role": "assistant", "content": "SELECT passenger_id, SUM(fare) AS total_fare FROM transportation.bookings WHERE status = 'completed' GROUP BY passenger_id HAVING SUM(fare) > 200 ORDER BY total_fare DESC;"}, {"role": "user", "content": "Can you also include the count of bookings for each passenger in the results?"}, {"role": "assistant", "content": "SELECT passenger_id, SUM(fare) AS total_fare, COUNT(*) AS booking_count FROM transportation.bookings WHERE status = 'completed' GROUP BY passenger_id HAVING SUM(fare) > 200 ORDER BY total_fare DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.bookings ( booking_id text PRIMARY KEY, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n"} {"conversations": [{"role": "user", "content": "List NFT collections deployed after block number 10000000 with more than 500 tokens, showing contract_address, name, and token_count."}, {"role": "assistant", "content": "SELECT contract_address, name, token_count\nFROM nft_collections\nWHERE deploy_block_number > 10000000\n AND token_count > 500;"}, {"role": "user", "content": "Join with nft_metadata to calculate the average rarity_score per collection."}, {"role": "assistant", "content": "SELECT nc.contract_address,\n nc.name,\n nc.token_count,\n AVG(nm.rarity_score) AS avg_rarity\nFROM nft_collections nc\nLEFT JOIN nft_metadata nm\n ON nc.contract_address = nm.contract_address\nWHERE nc.deploy_block_number > 10000000\n AND nc.token_count > 500\nGROUP BY nc.contract_address, nc.name, nc.token_count;"}, {"role": "user", "content": "Filter collections with average rarity_score above 80 and include floor_price."}, {"role": "assistant", "content": "SELECT nc.contract_address,\n nc.name,\n nc.token_count,\n AVG(nm.rarity_score) AS avg_rarity,\n nc.floor_price\nFROM nft_collections nc\nLEFT JOIN nft_metadata nm\n ON nc.contract_address = nm.contract_address\nWHERE nc.deploy_block_number > 10000000\n AND nc.token_count > 500\nGROUP BY nc.contract_address, nc.name, nc.token_count, nc.floor_price\nHAVING AVG(nm.rarity_score) > 80;"}, {"role": "user", "content": "Order the results by floor_price descending and limit to the top 5 collections."}, {"role": "assistant", "content": "SELECT nc.contract_address,\n nc.name,\n nc.token_count,\n AVG(nm.rarity_score) AS avg_rarity,\n nc.floor_price\nFROM nft_collections nc\nLEFT JOIN nft_metadata nm\n ON nc.contract_address = nm.contract_address\nWHERE nc.deploy_block_number > 10000000\n AND nc.token_count > 500\nGROUP BY nc.contract_address, nc.name, nc.token_count, nc.floor_price\nHAVING AVG(nm.rarity_score) > 80\nORDER BY CAST(nc.floor_price AS numeric) DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n name varchar NOT NULL, -- name fields for the functionType in contract\n symbol varchar NOT NULL, -- symbol fields for the functionType in contract\n deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract\n deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n description varchar NOT NULL, -- description fields for the functionType in contract\n slug varchar NOT NULL, -- slug fields for the functionType in contract\n media_info varchar NOT NULL, -- media_info fields for the functionType in contract\n image_url varchar NOT NULL, -- image_url fields for the functionType in contract\n banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n banner varchar NOT NULL, -- banner fields for the functionType in contract\n token_count bigint NOT NULL, -- token_count fields for the functionType in contract\n floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract\n floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract\n floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE 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 )\nCREATE TABLE token_activities_bitcoin ( 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 )\nCREATE 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 )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "Find all patients who have both an emergency contact and a phone number, and show their full names along with the emergency contact name and phone number, sorted by last name."}, {"role": "assistant", "content": "SELECT CONCAT(first_name, ' ', last_name) AS patient_full_name, emergency_contact_name, emergency_contact_phone FROM healthcare.patients WHERE emergency_contact_name IS NOT NULL AND phone_number IS NOT NULL ORDER BY last_name;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Which achievement has the highest point value for each game?"}, {"role": "assistant", "content": "SELECT a1.game_id, a1.achievement_id, a1.name, a1.points FROM gaming_technology.achievements a1 WHERE a1.points = (SELECT MAX(a2.points) FROM gaming_technology.achievements a2 WHERE a2.game_id = a1.game_id)"}, {"role": "user", "content": "Can you also include the number of players who have unlocked each of these top achievements?"}, {"role": "assistant", "content": "SELECT a1.game_id, a1.achievement_id, a1.name, a1.points, COUNT(pa.player_id) AS players_unlocked FROM gaming_technology.achievements a1 LEFT JOIN gaming_technology.player_achievements pa ON a1.achievement_id = pa.achievement_id WHERE a1.points = (SELECT MAX(a2.points) FROM gaming_technology.achievements a2 WHERE a2.game_id = a1.game_id) GROUP BY a1.game_id, a1.achievement_id, a1.name, a1.points"}, {"role": "user", "content": "Only include those where at least 10 players have unlocked that achievement."}, {"role": "assistant", "content": "SELECT a1.game_id, a1.achievement_id, a1.name, a1.points, COUNT(pa.player_id) AS players_unlocked FROM gaming_technology.achievements a1 LEFT JOIN gaming_technology.player_achievements pa ON a1.achievement_id = pa.achievement_id WHERE a1.points = (SELECT MAX(a2.points) FROM gaming_technology.achievements a2 WHERE a2.game_id = a1.game_id) GROUP BY a1.game_id, a1.achievement_id, a1.name, a1.points HAVING COUNT(pa.player_id) >= 10"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid PRIMARY KEY, player_id uuid, achievement_id uuid, unlocked_at timestamptz )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )\n"} {"conversations": [{"role": "user", "content": "List all item names and their rarity, along with the title of the game they belong to."}, {"role": "assistant", "content": "SELECT T1.item_name, T1.rarity, T2.title FROM in_game_items AS T1 JOIN games AS T2 ON T1.game_id = T2.game_id;"}, {"role": "user", "content": "Only show items with a rarity of 'Rare' or 'Epic' and a cost amount greater than 50."}, {"role": "assistant", "content": "SELECT T1.item_name, T1.rarity, T2.title FROM in_game_items AS T1 JOIN games AS T2 ON T1.game_id = T2.game_id WHERE T1.rarity IN ('Rare', 'Epic') AND T1.cost_amount > 50;"}, {"role": "user", "content": "Also, only include items belonging to games released after 2020."}, {"role": "assistant", "content": "SELECT T1.item_name, T1.rarity, T2.title FROM in_game_items AS T1 JOIN games AS T2 ON T1.game_id = T2.game_id WHERE T1.rarity IN ('Rare', 'Epic') AND T1.cost_amount > 50 AND T2.release_date > '2020-12-31';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE 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 )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "Can you give me the total number of appointments grouped by status?"}, {"role": "assistant", "content": "SELECT status,\n COUNT(*) AS total_appointments\nFROM healthcare.appointments\nGROUP BY status;"}, {"role": "user", "content": "Filter the result to show only statuses with more than 50 appointments."}, {"role": "assistant", "content": "SELECT status,\n COUNT(*) AS total_appointments\nFROM healthcare.appointments\nGROUP BY status\nHAVING COUNT(*) > 50;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.appointments ( appointment_id text PRIMARY KEY, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes int, reason text, status text, location_id text, notes text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "For each service location, find the nearest accessible service location. Show the location_id, location_name, nearest_location_id, and the distance."}, {"role": "assistant", "content": "SELECT l.location_id,\n l.location_name,\n nearest.location_id AS nearest_location_id,\n SQRT(POWER(l.latitude - nearest.latitude, 2) + POWER(l.longitude - nearest.longitude, 2)) AS distance\nFROM service_locations l\nJOIN LATERAL (\n SELECT sl.location_id, sl.latitude, sl.longitude\n FROM service_locations sl\n WHERE sl.location_id <> l.location_id\n AND sl.is_accessible = TRUE\n ORDER BY POWER(l.latitude - sl.latitude, 2) + POWER(l.longitude - sl.longitude, 2)\n LIMIT 1\n) AS nearest ON TRUE;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\n"} {"conversations": [{"role": "user", "content": "List the top 3 addresses with the highest profit on the Arbitrum chain, including roi and most_profit_token."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}, {"role": "user", "content": "Please add the realized_ratio and last_trade_time for each result."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token, realized_ratio, last_trade_time FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_profit ( address.text, rank.numeric, profit.numeric, roi.numeric, realized_ratio.numeric, most_profit_token.text, last_trade_time.text, chain.text )\n"} {"conversations": [{"role": "user", "content": "Retrieve the first and last names of all doctors who specialize in Cardiology."}, {"role": "assistant", "content": "SELECT first_name, last_name\nFROM healthcare.doctors\nWHERE specialty = 'Cardiology';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n"} {"conversations": [{"role": "user", "content": "For each appointment, show the appointment ID, scheduled start time, and the category of the service associated with it."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.scheduled_start_time, s.category\nFROM government_services.appointments a\nJOIN government_services.services s ON a.service_id = s.service_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )\nCREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, 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 )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n"} {"conversations": [{"role": "user", "content": "List all prescriptions with medication details. Return prescription_id, patient full name, medication_name, and prescription_date."}, {"role": "assistant", "content": "SELECT pr.prescription_id,\n p.first_name || ' ' || p.last_name AS patient_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.prescriptions pr\nJOIN healthcare.patients p ON pr.patient_id = p.patient_id\nJOIN healthcare.medications m ON pr.medication_id = m.medication_id;"}, {"role": "user", "content": "Filter to only include prescriptions where the quantity_dispensed is greater than 30."}, {"role": "assistant", "content": "SELECT pr.prescription_id,\n p.first_name || ' ' || p.last_name AS patient_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.prescriptions pr\nJOIN healthcare.patients p ON pr.patient_id = p.patient_id\nJOIN healthcare.medications m ON pr.medication_id = m.medication_id\nWHERE pr.quantity_dispensed > 30;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n"} {"conversations": [{"role": "user", "content": "List the usernames of players who own at least one item from the game with title 'Game Title X'."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM players AS T1 INNER JOIN player_inventory AS T2 ON T1.player_id = T2.player_id INNER JOIN items AS T3 ON T2.item_id = T3.item_id INNER JOIN games AS T4 ON T3.game_id = T4.game_id WHERE T4.title = 'Game Title X';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n"} {"conversations": [{"role": "user", "content": "What is the average ROI for tokens with a realized ratio above 50% across all chains?"}, {"role": "assistant", "content": "SELECT AVG(roi) AS average_roi FROM smart_money_token_performance WHERE realized_ratio > 50;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol pnl numeric(38,2), -- the profit users made on this token net_flow numeric(38,2), -- the netflow of the token, means the money user spent minus the the money user sold of this token avg_cost numeric(38,16), -- the average cost price of user spent on this token price double precision, -- the current price of the token realized_ratio numeric(10,2), -- the ratio user sold of the token roi numeric(10,2), -- the roi users made of this token chain character varying(100), -- the chain that the token resides PRIMARY KEY (token_address, chain) )\n"} {"conversations": [{"role": "user", "content": "List the user ID and username for all users, ordered by username alphabetically."}, {"role": "assistant", "content": "SELECT user_id, username FROM blockchain.users ORDER BY username ASC;"}, {"role": "user", "content": "From that list, only show users whose username contains the word 'test'."}, {"role": "assistant", "content": "SELECT user_id, username FROM blockchain.users WHERE username LIKE '%test%' ORDER BY username ASC;"}, {"role": "user", "content": "Also include their email address in the results."}, {"role": "assistant", "content": "SELECT user_id, username, email FROM blockchain.users WHERE username LIKE '%test%' ORDER BY username 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. \n##Table Structure\nCREATE TABLE blockchain.users ( user_id.text, username.text, email.text, password_hash.text )\n"} {"conversations": [{"role": "user", "content": "List all time entries, showing the date worked, hours spent, description, the first and last name of the lawyer, and the name of the case."}, {"role": "assistant", "content": "SELECT T1.date_worked, T1.hours_spent, T1.description, T2.first_name, T2.last_name, T3.case_name FROM legal_services.time_entries AS T1 JOIN legal_services.lawyers AS T2 ON T1.lawyer_id = T2.lawyer_id JOIN legal_services.cases AS T3 ON T1.case_id = T3.case_id;"}, {"role": "user", "content": "Only show me entries that are billable but not yet billed."}, {"role": "assistant", "content": "SELECT T1.date_worked, T1.hours_spent, T1.description, T2.first_name, T2.last_name, T3.case_name FROM legal_services.time_entries AS T1 JOIN legal_services.lawyers AS T2 ON T1.lawyer_id = T2.lawyer_id JOIN legal_services.cases AS T3 ON T1.case_id = T3.case_id WHERE T1.is_billable = TRUE AND T1.is_billed = FALSE;"}, {"role": "user", "content": "Also, order the results by the date worked in descending order and include the billing rate."}, {"role": "assistant", "content": "SELECT T1.date_worked, T1.hours_spent, T1.description, T2.first_name, T2.last_name, T3.case_name, T1.billing_rate FROM legal_services.time_entries AS T1 JOIN legal_services.lawyers AS T2 ON T1.lawyer_id = T2.lawyer_id JOIN legal_services.cases AS T3 ON T1.case_id = T3.case_id WHERE T1.is_billable = TRUE AND T1.is_billed = FALSE ORDER BY T1.date_worked DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\nCREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE 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 )\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE 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 )\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n"} {"conversations": [{"role": "user", "content": "For each server, show its name and the total number of achievements available for the game it hosts."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, COUNT(a.achievement_id) AS achievement_count\nFROM gaming_technology.servers s\nLEFT JOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY s.server_name, s.region;"}, {"role": "user", "content": "Exclude servers hosting games with no achievements."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, COUNT(a.achievement_id) AS achievement_count\nFROM gaming_technology.servers s\nLEFT JOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY s.server_name, s.region\nHAVING COUNT(a.achievement_id) > 0;"}, {"role": "user", "content": "Also include each server's current_players and max_players."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, s.current_players, s.max_players, COUNT(a.achievement_id) AS achievement_count\nFROM gaming_technology.servers s\nLEFT JOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY s.server_name, s.region, s.current_players, s.max_players\nHAVING COUNT(a.achievement_id) > 0;"}, {"role": "user", "content": "Sort by usage ratio (current_players divided by max_players) in descending order."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, s.current_players, s.max_players, COUNT(a.achievement_id) AS achievement_count\nFROM gaming_technology.servers s\nLEFT JOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY s.server_name, s.region, s.current_players, s.max_players\nHAVING COUNT(a.achievement_id) > 0\nORDER BY (s.current_players::numeric / s.max_players) DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid NOT NULL DEFAULT gen_random_uuid(), name character varying(150) NOT NULL UNIQUE, country character varying(100), founded_year integer, website character varying(255), created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (developer_id) )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )\nCREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, name character varying(150) NOT NULL, description text NOT NULL, icon_url character varying(255), points integer DEFAULT 0, hidden boolean DEFAULT false, PRIMARY KEY (achievement_id) )\n"} {"conversations": [{"role": "user", "content": "How many smart money addresses fall into each rank bracket: 1-100, 101-1000, and 1001-5000? Show the bracket and the count of addresses."}, {"role": "assistant", "content": "SELECT CASE WHEN rank BETWEEN 1 AND 100 THEN '1-100' WHEN rank BETWEEN 101 AND 1000 THEN '101-1000' WHEN rank BETWEEN 1001 AND 5000 THEN '1001-5000' ELSE 'Other' END AS rank_bracket, COUNT(address) AS address_count FROM smart_money_profit WHERE rank BETWEEN 1 AND 5000 GROUP BY rank_bracket ORDER BY MIN(rank);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\n"} {"conversations": [{"role": "user", "content": "For every guest, show their first and last names, and the name of each property where they have made a reservation."}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, p.property_name\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.reservations r ON g.guest_id = r.guest_id\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nGROUP BY g.first_name, g.last_name, p.property_name\nORDER BY g.last_name, p.property_name;"}, {"role": "user", "content": "Now, only include guests who have made a reservation at more than one property."}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, p.property_name\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.reservations r ON g.guest_id = r.guest_id\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE g.guest_id IN (\n SELECT guest_id\n FROM hospitality_technology.reservations\n GROUP BY guest_id\n HAVING COUNT(DISTINCT property_id) > 1\n)\nGROUP BY g.first_name, g.last_name, p.property_name\nORDER BY g.last_name, p.property_name;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, 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 integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\nCREATE TABLE hospitality_technology.reviews (\n review_id character varying(64) NOT NULL, -- unique identifier for the review\n property_id character varying(64) NOT NULL, -- FK to properties table\n reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good)\n guest_id character varying(64) NOT NULL, -- FK to guests table\n rating_overall integer, -- overall score (e.g., 1-5 or 1-10)\n rating_cleanliness integer,\n rating_service integer,\n rating_location integer,\n rating_value integer,\n comment text, -- guest's written feedback\n review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com\n review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted\n is_public boolean DEFAULT true, -- whether the review is publicly visible\n staff_response text, -- official response from the property\n response_staff_id character varying(64), -- FK to staff (who responded)\n response_date timestamp with time zone, -- when the response was posted\n PRIMARY KEY (review_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id)\n)\n"} {"conversations": [{"role": "user", "content": "For each ERC20 token, find the count of distinct historical holders and the sum of balances using erc20_balances_historical."}, {"role": "assistant", "content": "SELECT contract_address,\n COUNT(DISTINCT wallet_address) AS holder_count,\n SUM(CAST(amount AS numeric)) AS total_balance\nFROM erc20_balances_historical\nGROUP BY contract_address;"}, {"role": "user", "content": "Join with token_metas to include symbol and name for each token."}, {"role": "assistant", "content": "SELECT h.contract_address,\n m.symbol,\n m.name,\n h.holder_count,\n h.total_balance\nFROM (\n SELECT contract_address,\n COUNT(DISTINCT wallet_address) AS holder_count,\n SUM(CAST(amount AS numeric)) AS total_balance\n FROM erc20_balances_historical\n GROUP BY contract_address\n) h\nLEFT JOIN token_metas m\n ON h.contract_address = m.contract_address;"}, {"role": "user", "content": "Filter to only include tokens with holder_count greater than 100 and sort by total_balance descending."}, {"role": "assistant", "content": "SELECT h.contract_address,\n m.symbol,\n m.name,\n h.holder_count,\n h.total_balance\nFROM (\n SELECT contract_address,\n COUNT(DISTINCT wallet_address) AS holder_count,\n SUM(CAST(amount AS numeric)) AS total_balance\n FROM erc20_balances_historical\n GROUP BY contract_address\n) h\nLEFT JOIN token_metas m\n ON h.contract_address = m.contract_address\nWHERE h.holder_count > 100\nORDER BY h.total_balance DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances_historical ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n token_id varchar NOT NULL, -- The number of the token\n contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n amount bigint NOT NULL, -- amount fields for the functionType in contract\n minter varchar NOT NULL, -- minter fields for the functionType in contract\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract\n mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract\n mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract\n mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract\n token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract\n metadata varchar NOT NULL, -- metadata fields for the functionType in contract\n name varchar NOT NULL, -- name fields for the functionType in contract\n image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n status varchar NOT NULL, -- status fields for the functionType in contract\n rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract\n rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract\n unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(mint_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_info_bitcoin ( 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 )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "List the first_name, last_name, and email of all clients whose email domain is 'gmail.com'."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.clients WHERE SUBSTRING(email FROM POSITION('@' IN email) + 1) = 'gmail.com';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "I want to list all employees who currently manage at least one other employee, showing their full name, email, and the total number of direct reports for each manager."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email;"}, {"role": "user", "content": "Can you also include the job_title and department of each manager in the result?"}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, e.job_title, e.department, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email, e.job_title, e.department;"}, {"role": "user", "content": "I noticed some managers don't have any reports\u2014that shouldn't be the case. Only show managers who have at least two direct reports."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, e.job_title, e.department, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email, e.job_title, e.department\nHAVING COUNT(r.employee_id) >= 2;"}, {"role": "user", "content": "Please order the output by the number of direct reports in descending order."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, e.job_title, e.department, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email, e.job_title, e.department\nHAVING COUNT(r.employee_id) >= 2\nORDER BY direct_report_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts (\n account_id character varying(64) NOT NULL, -- unique identifier for the account\n customer_id character varying(64) NOT NULL, -- foreign key linking to the customer\n account_number character varying(128) NOT NULL UNIQUE, -- unique account number visible to customer\n account_type character varying(50) NOT NULL, -- e.g., Checking, Savings, Investment, Loan, Credit Card\n balance numeric(19, 4) NOT NULL DEFAULT 0.00, -- current account balance\n currency character varying(3) NOT NULL, -- currency code (e.g., USD, EUR)\n opened_date date NOT NULL, -- date the account was opened\n status character varying(32) NOT NULL, -- e.g., Open, Closed, Frozen\n interest_rate numeric(5, 4), -- annual interest rate, if applicable\n last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last account update\n PRIMARY KEY (account_id),\n FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id)\n)\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\n"} {"conversations": [{"role": "user", "content": "List policy pairs for the same customer where one policy was cancelled and another active policy started within 30 days after the cancellation. Show customer_id, cancelled policy_number, cancellation_date, active policy_number, start_date."}, {"role": "assistant", "content": "SELECT p1.customer_id,\n p1.policy_number AS cancelled_policy_number,\n p1.cancellation_date,\n p2.policy_number AS active_policy_number,\n p2.start_date\nFROM insurance.policies p1\nJOIN insurance.policies p2\n ON p1.customer_id = p2.customer_id\n AND p1.status = 'cancelled'\n AND p2.status = 'active'\n AND p2.start_date BETWEEN p1.cancellation_date AND p1.cancellation_date + INTERVAL '30 days';"}, {"role": "user", "content": "Also include the number of days between cancellation and new policy start as days_to_new."}, {"role": "assistant", "content": "SELECT p1.customer_id,\n p1.policy_number AS cancelled_policy_number,\n p1.cancellation_date,\n p2.policy_number AS active_policy_number,\n p2.start_date,\n EXTRACT(DAY FROM (p2.start_date - p1.cancellation_date)) AS days_to_new\nFROM insurance.policies p1\nJOIN insurance.policies p2\n ON p1.customer_id = p2.customer_id\n AND p1.status = 'cancelled'\n AND p2.status = 'active'\n AND p2.start_date BETWEEN p1.cancellation_date AND p1.cancellation_date + INTERVAL '30 days';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\n"} {"conversations": [{"role": "user", "content": "For each property, list the name of the room type and the number of rooms of that type at the property."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.type_name, count(T3.room_id) AS room_count FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.rooms AS T3 ON T2.room_type_id = T3.room_type_id GROUP BY T1.property_name, T2.type_name ORDER BY T1.property_name, T2.type_name;"}, {"role": "user", "content": "Only include room types that have a base rate above 150, and sort the results by property name and then by room type count descending."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.type_name, count(T3.room_id) AS room_count FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.rooms AS T3 ON T2.room_type_id = T3.room_type_id WHERE T2.base_rate > 150 GROUP BY T1.property_name, T2.type_name ORDER BY T1.property_name, room_count DESC;"}, {"role": "user", "content": "The SQL failed. I meant available rooms, not just any room. Please rewrite the query to only count rooms with status 'Available'."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.type_name, count(T3.room_id) AS room_count FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id JOIN hospitality_technology.rooms AS T3 ON T2.room_type_id = T3.room_type_id WHERE T2.base_rate > 150 AND T3.status = 'Available' GROUP BY T1.property_name, T2.type_name ORDER BY T1.property_name, room_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\nCREATE 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) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE 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) )\nCREATE 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) )\nCREATE 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) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE 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) )\n"} {"conversations": [{"role": "user", "content": "Show all active staff members' full names and their positions."}, {"role": "assistant", "content": "SELECT staff_id, first_name || ' ' || last_name AS staff_full_name, position\nFROM hospitality_technology.staff\nWHERE is_active = true;"}, {"role": "user", "content": "Also include the name of the property they work at."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name || ' ' || s.last_name AS staff_full_name, s.position, p.property_name\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.is_active = true;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\nCREATE 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) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE 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) )\nCREATE 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) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE 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) )\n"} {"conversations": [{"role": "user", "content": "Find projects from the project_fundraising_record table that have completed both a 'Seed' fundraising round and a 'Series A' fundraising round."}, {"role": "assistant", "content": "SELECT pf_seed.project_name FROM project_fundraising_record pf_seed JOIN project_fundraising_record pf_seriesa ON pf_seed.project_id = pf_seriesa.project_id WHERE pf_seed.rounds_name = 'Seed' AND pf_seriesa.rounds_name = 'Series A';"}, {"role": "user", "content": "For these projects that had both a 'Seed' and 'Series A' round, show the investment value for both rounds side by side."}, {"role": "assistant", "content": "SELECT pf_seed.project_name, pf_seed.investment_value AS seed_investment, pf_seriesa.investment_value AS seriesa_investment FROM project_fundraising_record pf_seed JOIN project_fundraising_record pf_seriesa ON pf_seed.project_id = pf_seriesa.project_id WHERE pf_seed.rounds_name = 'Seed' AND pf_seriesa.rounds_name = 'Series A';"}, {"role": "user", "content": "Filter the results to only include projects where the investment value in the 'Series A' round was greater than the investment value in the 'Seed' round."}, {"role": "assistant", "content": "SELECT pf_seed.project_name, pf_seed.investment_value AS seed_investment, pf_seriesa.investment_value AS seriesa_investment FROM project_fundraising_record pf_seed JOIN project_fundraising_record pf_seriesa ON pf_seed.project_id = pf_seriesa.project_id WHERE pf_seed.rounds_name = 'Seed' AND pf_seriesa.rounds_name = 'Series A' AND pf_seriesa.investment_value > pf_seed.investment_value;"}, {"role": "user", "content": "Order the results by the 'Series A' investment value in descending order and show the top 5 projects."}, {"role": "assistant", "content": "SELECT pf_seed.project_name, pf_seed.investment_value AS seed_investment, pf_seriesa.investment_value AS seriesa_investment FROM project_fundraising_record pf_seed JOIN project_fundraising_record pf_seriesa ON pf_seed.project_id = pf_seriesa.project_id WHERE pf_seed.rounds_name = 'Seed' AND pf_seriesa.rounds_name = 'Series A' AND pf_seriesa.investment_value > pf_seed.investment_value ORDER BY seriesa_investment DESC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\n"} {"conversations": [{"role": "user", "content": "For each contract, can you list the token symbols and total supply of all tokens created by that contract, along with the contract's current status?"}, {"role": "assistant", "content": "SELECT c.contract_id, c.address AS contract_address, c.status, t.token_symbol, t.total_supply\nFROM web3.contracts c\nJOIN web3.tokens t ON c.address = t.contract_address\nORDER BY c.contract_id, t.token_symbol;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts ( contract_id text, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\nCREATE TABLE web3.events ( event_id text, contract_id text, event_name text, data text, emitted_at timestamp, transaction_id text, log_index integer )\nCREATE 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 )\nCREATE TABLE web3.tokens ( token_id text, contract_address text, token_name text, token_symbol text, decimals integer, total_supply numeric )\nCREATE TABLE web3.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me each comment ID and the total number of likes it has received."}, {"role": "assistant", "content": "SELECT c.comment_id,\n COUNT(l.like_id) AS likes_count\nFROM social_media.comments c\nLEFT JOIN social_media.likes l ON c.comment_id = l.comment_id\nGROUP BY c.comment_id;"}, {"role": "user", "content": "Now include only comments with at least 5 likes and show the username of the comment author."}, {"role": "assistant", "content": "SELECT c.comment_id,\n u.username,\n COUNT(l.like_id) AS likes_count\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nLEFT JOIN social_media.likes l ON c.comment_id = l.comment_id\nGROUP BY c.comment_id, u.username\nHAVING COUNT(l.like_id) >= 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id text, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "List all hashtags that have never been associated with any post, showing hashtag_id and tag_name."}, {"role": "assistant", "content": "SELECT h.hashtag_id, h.tag_name\nFROM social_media.hashtags h\nLEFT JOIN social_media.post_hashtags ph ON h.hashtag_id = ph.hashtag_id\nWHERE ph.post_hashtag_id IS NULL;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE 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 )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "Can you retrieve a list of all case numbers, their names, the client's full name, and the date_opened, sorted by date_opened descending?"}, {"role": "assistant", "content": "SELECT c.case_number,\n c.case_name,\n CONCAT(cl.first_name, ' ', cl.last_name) AS client_name,\n c.date_opened\nFROM legal_services.cases c\nJOIN legal_services.clients cl ON c.client_id = cl.client_id\nORDER BY c.date_opened DESC;"}, {"role": "user", "content": "Actually, I only want those cases of type 'Civil Litigation' and that are still open."}, {"role": "assistant", "content": "SELECT c.case_number,\n c.case_name,\n CONCAT(cl.first_name, ' ', cl.last_name) AS client_name,\n c.date_opened\nFROM legal_services.cases c\nJOIN legal_services.clients cl ON c.client_id = cl.client_id\nWHERE c.case_type = 'Civil Litigation'\n AND c.status = 'Open'\nORDER BY c.date_opened DESC;"}, {"role": "user", "content": "Also, could you include the total number of documents uploaded for each case?"}, {"role": "assistant", "content": "SELECT c.case_number,\n c.case_name,\n CONCAT(cl.first_name, ' ', cl.last_name) AS client_name,\n c.date_opened,\n COUNT(d.document_id) AS document_count\nFROM legal_services.cases c\nJOIN legal_services.clients cl ON c.client_id = cl.client_id\nLEFT JOIN legal_services.documents d ON c.case_id = d.case_id\nWHERE c.case_type = 'Civil Litigation'\n AND c.status = 'Open'\nGROUP BY c.case_number, c.case_name, cl.first_name, cl.last_name, c.date_opened\nORDER BY c.date_opened DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) )\nCREATE TABLE legal_services.law_firms ( firm_id character varying(64) NOT NULL, firm_name character varying(200) NOT NULL, address text NOT NULL, phone character varying(32), website character varying(255), founded_date date, managing_partner_id character varying(64), PRIMARY KEY (firm_id) )\nCREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )\nCREATE TABLE legal_services.documents ( document_id character varying(64) NOT NULL, case_id character varying(64) NOT NULL, document_name character varying(255) NOT NULL, document_type character varying(100), storage_path text NOT NULL, uploaded_by_lawyer_id character varying(64), upload_timestamp timestamp NOT NULL, version integer DEFAULT 1, description text, PRIMARY KEY (document_id) )\nCREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) )\nCREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 most recent medical records with a fever recorded. Return record_id, patient_id, record_date, and the temperature value from vitals."}, {"role": "assistant", "content": "SELECT record_id,\n patient_id,\n record_date,\n vitals->>'temperature' AS temperature\nFROM healthcare.medical_records\nWHERE (vitals->>'temperature')::numeric > 38\nORDER BY record_date DESC\nLIMIT 5;"}, {"role": "user", "content": "Actually, include only records where assessment is not empty."}, {"role": "assistant", "content": "SELECT record_id,\n patient_id,\n record_date,\n vitals->>'temperature' AS temperature\nFROM healthcare.medical_records\nWHERE (vitals->>'temperature')::numeric > 38\n AND assessment IS NOT NULL\n AND assessment <> ''\nORDER BY record_date DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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) )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n"} {"conversations": [{"role": "user", "content": "For each insurance product type, retrieve the total premium_amount and average coverage_limit for policies under active products. Include product_type, total_premium, and avg_coverage_limit, sorted by total_premium descending."}, {"role": "assistant", "content": "SELECT ip.product_type,\n SUM(p.premium_amount) AS total_premium,\n AVG(p.coverage_limit) AS avg_coverage_limit\nFROM insurance.policies p\nJOIN insurance.insurance_products ip\n ON p.product_id = ip.product_id\nWHERE ip.is_active = TRUE\nGROUP BY ip.product_type\nORDER BY total_premium DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies (\n policy_id character varying(64) NOT NULL, -- unique identifier for the policy\n customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)\n product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)\n agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)\n policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number\n start_date date NOT NULL, -- date the policy coverage begins\n end_date date NOT NULL, -- date the policy coverage ends\n premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term\n coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered\n deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in\n status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending\n issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the policy was issued\n cancellation_date date,\n cancellation_reason text,\n PRIMARY KEY (policy_id)\n)\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.insurance_products (\n product_id character varying(64) NOT NULL, -- unique identifier for the insurance product\n product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')\n product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'\n description text, -- detailed description of the product\n base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments\n coverage_details text, -- details about what is covered (could be JSON or structured text)\n underwriting_rules text, -- rules used for assessing risk and eligibility\n is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at timestamp,\n PRIMARY KEY (product_id)\n)\nCREATE TABLE insurance.agents (\n agent_id character varying(64) NOT NULL, -- unique identifier for the agent\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n agency_name character varying(150),\n license_number character varying(100) NOT NULL UNIQUE, -- state insurance license number\n license_state character varying(50) NOT NULL,\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(30),\n hire_date date,\n termination_date date,\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Terminated, On Leave\n commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, -- percentage commission\n manager_id character varying(64), -- identifier for the agent's manager (FK to agents or employees)\n PRIMARY KEY (agent_id)\n)\nCREATE TABLE insurance.premium_payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment\n policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)\n payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received\n amount_paid numeric(12, 2) NOT NULL, -- amount of the payment\n payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check\n transaction_reference character varying(128) UNIQUE, -- reference from payment processor\n due_date date, -- due date for this payment installment\n payment_period_start date, -- start date of the period this payment covers\n payment_period_end date, -- end date of the period this payment covers\n status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded\n PRIMARY KEY (payment_id)\n)\nCREATE TABLE insurance.claim_documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n claim_id character varying(64) NOT NULL, -- identifier of the claim this document relates to (FK to claims)\n document_type character varying(50) NOT NULL, -- e.g., Police Report, Photo, Invoice, Medical Bill\n file_name character varying(255) NOT NULL, -- original name of the uploaded file\n file_path character varying(512) NOT NULL, -- storage path (e.g., S3 URL, network path)\n file_size_bytes integer, -- size of the file in bytes\n mime_type character varying(100), -- MIME type of the file (e.g., 'image/jpeg', 'application/pdf')\n uploaded_by character varying(64), -- identifier of the user/system who uploaded (FK to users/customers)\n uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- time of upload\n description text, -- optional description of the document\n PRIMARY KEY (document_id)\n)\nCREATE TABLE insurance.policy_beneficiaries (\n beneficiary_id character varying(64) NOT NULL, -- unique identifier for the beneficiary entry\n policy_id character varying(64) NOT NULL, -- identifier of the life/relevant policy (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the beneficiary (could be FK to customers or store info directly)\n first_name character varying(100) NOT NULL, -- beneficiary first name (if not linking to customers table)\n last_name character varying(100) NOT NULL, -- beneficiary last name\n relationship character varying(50) NOT NULL, -- relationship to the policyholder (e.g., Spouse, Child, Parent)\n percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), -- percentage of payout\n contact_info text, -- contact details for the beneficiary\n added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (beneficiary_id),\n UNIQUE (policy_id, customer_id) -- Ensure a person is listed only once per policy\n)\n"} {"conversations": [{"role": "user", "content": "List all ERC20 tokens from the sui_coins_metadata table where the decimals are 18, including their names and symbols."}, {"role": "assistant", "content": "SELECT name, symbol FROM sui_coins_metadata WHERE decimals = 18;"}, {"role": "user", "content": "Can you join this with the token_prices_latest table to include the current price of each token?"}, {"role": "assistant", "content": "SELECT scm.name, scm.symbol, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.coin_type = tpl.address WHERE scm.decimals = 18;"}, {"role": "user", "content": "I think there's an error in your join condition - it should be on coin_type not address. Also, can you filter to only show tokens with price greater than $1?"}, {"role": "assistant", "content": "SELECT scm.name, scm.symbol, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.coin_type = tpl.address WHERE scm.decimals = 18 AND tpl.price > 1;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n"} {"conversations": [{"role": "user", "content": "List the user ID, username, and wallet address for all users who have at least one unspent UTXO associated with any of their wallets."}, {"role": "assistant", "content": "SELECT DISTINCT T1.user_id, T1.username, T2.address FROM trading_platform.users AS T1 JOIN trading_platform.wallets AS T2 ON T1.user_id = T2.user_id JOIN trading_platform.utxos AS T3 ON T2.address = T3.address WHERE T3.spent = FALSE;"}, {"role": "user", "content": "For the results from the previous query, also include the total amount of all unspent UTXOs for each listed wallet."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.username, T2.address, SUM(T3.amount) FROM trading_platform.users AS T1 JOIN trading_platform.wallets AS T2 ON T1.user_id = T2.user_id JOIN trading_platform.utxos AS T3 ON T2.address = T3.address WHERE T3.spent = FALSE GROUP BY T1.user_id, T1.username, T2.address;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\nCREATE TABLE trading_platform.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id text, transaction_id text, output_index integer, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id text, ip_address text, port integer, last_seen timestamp )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me all doctors specializing in Oncology along with their hospital affiliation IDs, ordered by their last name in ascending order."}, {"role": "assistant", "content": "SELECT first_name, last_name, specialty, hospital_affiliation_id FROM healthcare.doctors WHERE specialty = 'Oncology' ORDER BY last_name ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show a summary of each user, including their user_id, the count of orders they've placed, and the total traded value as buyers."}, {"role": "assistant", "content": "SELECT o.user_id,\n COUNT(o.order_id) AS order_count,\n SUM(t.quantity * t.price) AS total_traded_value\nFROM trading_platform.orders o\nJOIN trading_platform.trades t\n ON o.order_id = t.order_id\n AND t.buyer_id = o.user_id\nGROUP BY o.user_id;"}, {"role": "user", "content": "Filter to only include users who have placed at least 5 orders."}, {"role": "assistant", "content": "SELECT o.user_id,\n COUNT(o.order_id) AS order_count,\n SUM(t.quantity * t.price) AS total_traded_value\nFROM trading_platform.orders o\nJOIN trading_platform.trades t\n ON o.order_id = t.order_id\n AND t.buyer_id = o.user_id\nGROUP BY o.user_id\nHAVING COUNT(o.order_id) >= 5;"}, {"role": "user", "content": "Also include the date of their latest trade."}, {"role": "assistant", "content": "SELECT o.user_id,\n COUNT(o.order_id) AS order_count,\n SUM(t.quantity * t.price) AS total_traded_value,\n MAX(t.traded_at) AS last_trade_date\nFROM trading_platform.orders o\nJOIN trading_platform.trades t\n ON o.order_id = t.order_id\n AND t.buyer_id = o.user_id\nGROUP BY o.user_id\nHAVING COUNT(o.order_id) >= 5;"}, {"role": "user", "content": "What if some users have never traded? Please still show them with a null last_trade_date."}, {"role": "assistant", "content": "SELECT o.user_id,\n COUNT(o.order_id) AS order_count,\n SUM(t.quantity * t.price) AS total_traded_value,\n MAX(t.traded_at) AS last_trade_date\nFROM trading_platform.orders o\nLEFT JOIN trading_platform.trades t\n ON o.order_id = t.order_id\n AND t.buyer_id = o.user_id\nGROUP BY o.user_id\nHAVING COUNT(o.order_id) >= 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\n"} {"conversations": [{"role": "user", "content": "List each insurance product's name and type, along with the number of active policies and the total premium_amount collected for those policies. Only include products that have at least one active policy."}, {"role": "assistant", "content": "SELECT p.product_name,\n p.product_type,\n COUNT(pl.policy_id) AS active_policy_count,\n SUM(pl.premium_amount) AS total_premium\nFROM insurance.insurance_products p\nJOIN insurance.policies pl ON p.product_id = pl.product_id\nWHERE pl.status = 'Active'\nGROUP BY p.product_name, p.product_type\nHAVING COUNT(pl.policy_id) > 0;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text PRIMARY KEY, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Can you show me the number of items per rarity and item type combination, along with the minimum and maximum cost for each group?"}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS num_items, MIN(cost_amount) AS min_cost, MAX(cost_amount) AS max_cost FROM gaming_technology.in_game_items GROUP BY item_type, rarity;"}, {"role": "user", "content": "Could you only show the combinations where there are more than 2 items in that group?"}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS num_items, MIN(cost_amount) AS min_cost, MAX(cost_amount) AS max_cost FROM gaming_technology.in_game_items GROUP BY item_type, rarity HAVING COUNT(*) > 2;"}, {"role": "user", "content": "Additionally, can you add the average cost for each group to the results?"}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS num_items, MIN(cost_amount) AS min_cost, MAX(cost_amount) AS max_cost, AVG(cost_amount) AS avg_cost FROM gaming_technology.in_game_items GROUP BY item_type, rarity HAVING COUNT(*) > 2;"}, {"role": "user", "content": "Now, please only include groups where rarity is not null and order the output by avg_cost descending."}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS num_items, MIN(cost_amount) AS min_cost, MAX(cost_amount) AS max_cost, AVG(cost_amount) AS avg_cost FROM gaming_technology.in_game_items WHERE rarity IS NOT NULL GROUP BY item_type, rarity HAVING COUNT(*) > 2 ORDER BY avg_cost DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me the name and type for all the locations."}, {"role": "assistant", "content": "SELECT name, type FROM transportation.locations"}, {"role": "user", "content": "Now, filter this list to only include locations whose type is either 'Distribution Center' or 'Warehouse'."}, {"role": "assistant", "content": "SELECT name, type FROM transportation.locations WHERE type IN ('Distribution Center', 'Warehouse')"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.locations ( location_id.text, name.text, type.text, address_line1.text, city.text, state_province.text, postal_code.text, country.text, latitude.numeric, longitude.numeric, timezone.text )\n"} {"conversations": [{"role": "user", "content": "Show me the appointment ID, subject, and start time for appointments that are linked to a case, along with the case number and case name."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.subject, T1.start_time, T2.case_number, T2.case_name FROM legal_services.appointments AS T1 JOIN legal_services.cases AS T2 ON T1.case_id = T2.case_id;"}, {"role": "user", "content": "Restrict this to appointments starting after '2024-01-01' and where the case status is 'Open'."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.subject, T1.start_time, T2.case_number, T2.case_name FROM legal_services.appointments AS T1 JOIN legal_services.cases AS T2 ON T1.case_id = T2.case_id WHERE T1.start_time >= '2024-01-01' AND T2.status = 'Open';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE 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 )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "List each lawyer's full name with the full name of the partner at the same firm."}, {"role": "assistant", "content": "SELECT l.lawyer_id,\n CONCAT(l.first_name, ' ', l.last_name) AS lawyer_name,\n CONCAT(p.first_name, ' ', p.last_name) AS partner_name\nFROM legal_services.lawyers l\nJOIN legal_services.lawyers p\n ON l.firm_id = p.firm_id\n AND p.is_partner = true;"}, {"role": "user", "content": "Actually, I only want those lawyers whose specialization includes 'Corporate Law'. Could you update the query?"}, {"role": "assistant", "content": "SELECT l.lawyer_id,\n CONCAT(l.first_name, ' ', l.last_name) AS lawyer_name,\n CONCAT(p.first_name, ' ', p.last_name) AS partner_name\nFROM legal_services.lawyers l\nJOIN legal_services.lawyers p\n ON l.firm_id = p.firm_id\n AND p.is_partner = true\nWHERE l.specialization ILIKE '%Corporate Law%';"}, {"role": "user", "content": "Also only show those who were hired after 2020-01-01."}, {"role": "assistant", "content": "SELECT l.lawyer_id,\n CONCAT(l.first_name, ' ', l.last_name) AS lawyer_name,\n CONCAT(p.first_name, ' ', p.last_name) AS partner_name\nFROM legal_services.lawyers l\nJOIN legal_services.lawyers p\n ON l.firm_id = p.firm_id\n AND p.is_partner = true\nWHERE l.specialization ILIKE '%Corporate Law%'\n AND l.hire_date > '2020-01-01';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n"} {"conversations": [{"role": "user", "content": "Could you provide the firm_id, firm_name, total number of lawyers, and number of partners per firm?"}, {"role": "assistant", "content": "SELECT lf.firm_id,\n lf.firm_name,\n COUNT(lw.lawyer_id) AS total_lawyers,\n SUM(CASE WHEN lw.is_partner THEN 1 ELSE 0 END) AS partner_count\nFROM legal_services.law_firms lf\nJOIN legal_services.lawyers lw ON lf.firm_id = lw.firm_id\nGROUP BY lf.firm_id, lf.firm_name;"}, {"role": "user", "content": "Now restrict to firms with more than 5 lawyers."}, {"role": "assistant", "content": "SELECT lf.firm_id,\n lf.firm_name,\n COUNT(lw.lawyer_id) AS total_lawyers,\n SUM(CASE WHEN lw.is_partner THEN 1 ELSE 0 END) AS partner_count\nFROM legal_services.law_firms lf\nJOIN legal_services.lawyers lw ON lf.firm_id = lw.firm_id\nGROUP BY lf.firm_id, lf.firm_name\nHAVING COUNT(lw.lawyer_id) > 5;"}, {"role": "user", "content": "Also include the managing partner's full name."}, {"role": "assistant", "content": "SELECT lf.firm_id,\n lf.firm_name,\n mp.first_name || ' ' || mp.last_name AS managing_partner_name,\n COUNT(lw.lawyer_id) AS total_lawyers,\n SUM(CASE WHEN lw.is_partner THEN 1 ELSE 0 END) AS partner_count\nFROM legal_services.law_firms lf\nJOIN legal_services.lawyers lw ON lf.firm_id = lw.firm_id\nLEFT JOIN legal_services.lawyers mp ON lf.managing_partner_id = mp.lawyer_id\nGROUP BY lf.firm_id, lf.firm_name, managing_partner_name\nHAVING COUNT(lw.lawyer_id) > 5;"}, {"role": "user", "content": "Finally, only include firms founded before '2010-01-01' and order by partner_count descending."}, {"role": "assistant", "content": "SELECT lf.firm_id,\n lf.firm_name,\n mp.first_name || ' ' || mp.last_name AS managing_partner_name,\n COUNT(lw.lawyer_id) AS total_lawyers,\n SUM(CASE WHEN lw.is_partner THEN 1 ELSE 0 END) AS partner_count\nFROM legal_services.law_firms lf\nJOIN legal_services.lawyers lw ON lf.firm_id = lw.firm_id\nLEFT JOIN legal_services.lawyers mp ON lf.managing_partner_id = mp.lawyer_id\nWHERE lf.founded_date < '2010-01-01'\nGROUP BY lf.firm_id, lf.firm_name, managing_partner_name\nHAVING COUNT(lw.lawyer_id) > 5\nORDER BY partner_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\nCREATE 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 )\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 projects by valuation that completed fundraising rounds in the last 6 months, along with their narrative information if available."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.valuation, pfr.investment_date, ni.narrative, ni.trend_rank FROM project_fundraising_record pfr LEFT JOIN narrative_info ni ON pfr.project_name = ni.narrative WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH) ORDER BY pfr.valuation DESC LIMIT 5;"}, {"role": "user", "content": "Can you also include the 24-hour trading volume for these projects' narratives and filter to only include projects with valuation over $50 million?"}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.valuation, pfr.investment_date, ni.narrative, ni.trend_rank, ni.volume_24h FROM project_fundraising_record pfr LEFT JOIN narrative_info ni ON pfr.project_name = ni.narrative WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 6 MONTH) AND pfr.valuation > 50000000 ORDER BY pfr.valuation DESC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\nCREATE TABLE token_dexpool_info ( pair_address text, token_name text, token_symbol text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_6h numeric, price_change_percentage_24h numeric, makers_24h numeric, volume_24h numeric, liquidity numeric, market_cap numeric, trend_rank numeric )\nCREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n"} {"conversations": [{"role": "user", "content": "I want to list all claims with their claim_id, incident_date, and the customer's full name for claims where estimated_loss is above 10000."}, {"role": "assistant", "content": "SELECT cl.claim_id, cl.incident_date, c.first_name || ' ' || c.last_name AS customer_name\nFROM insurance.claims cl\nJOIN insurance.customers c ON cl.customer_id = c.customer_id\nWHERE cl.estimated_loss > 10000;"}, {"role": "user", "content": "Actually, I also need the policy_number associated with each claim."}, {"role": "assistant", "content": "SELECT cl.claim_id, cl.incident_date, c.first_name || ' ' || c.last_name AS customer_name, p.policy_number\nFROM insurance.claims cl\nJOIN insurance.customers c ON cl.customer_id = c.customer_id\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nWHERE cl.estimated_loss > 10000;"}, {"role": "user", "content": "Additionally, only include claims that are still open (status = 'Open') and order by incident_date descending."}, {"role": "assistant", "content": "SELECT cl.claim_id, cl.incident_date, c.first_name || ' ' || c.last_name AS customer_name, p.policy_number\nFROM insurance.claims cl\nJOIN insurance.customers c ON cl.customer_id = c.customer_id\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nWHERE cl.estimated_loss > 10000\n AND cl.status = 'Open'\nORDER BY cl.incident_date DESC;"}, {"role": "user", "content": "That's good, but limit to the top 10 results."}, {"role": "assistant", "content": "SELECT cl.claim_id, cl.incident_date, c.first_name || ' ' || c.last_name AS customer_name, p.policy_number\nFROM insurance.claims cl\nJOIN insurance.customers c ON cl.customer_id = c.customer_id\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nWHERE cl.estimated_loss > 10000\n AND cl.status = 'Open'\nORDER BY cl.incident_date DESC\nLIMIT 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_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, ssn_hash character varying(128), address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL DEFAULT 'USA', phone_number character varying(30), email character varying(128) UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, status character varying(20) NOT NULL DEFAULT 'Active', PRIMARY KEY (customer_id) )\nCREATE 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) )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n"} {"conversations": [{"role": "user", "content": "List all appointments with status 'Completed' and location 'LOC001' that occurred in December 2023. Show appointment ID, time, duration, and notes."}, {"role": "assistant", "content": "SELECT appointment_id, appointment_time, duration_minutes, notes FROM healthcare.appointments WHERE status = 'Completed' AND location_id = 'LOC001' AND appointment_time >= '2023-12-01 00:00:00' AND appointment_time < '2024-01-01 00:00:00';"}, {"role": "user", "content": "Actually, change the location to 'LOC002' and the status to 'Scheduled'."}, {"role": "assistant", "content": "SELECT appointment_id, appointment_time, duration_minutes, notes FROM healthcare.appointments WHERE status = 'Scheduled' AND location_id = 'LOC002' AND appointment_time >= '2023-12-01 00:00:00' AND appointment_time < '2024-01-01 00:00:00';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, appointment_time timestamp with time zone NOT NULL, duration_minutes integer NOT NULL, reason text, status character varying(32) NOT NULL, location_id character varying(64), notes text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) )\n"} {"conversations": [{"role": "user", "content": "For each completed trip, list the trip ID, the driver's full name, and the name of the origin location."}, {"role": "assistant", "content": "SELECT t.trip_id, d.first_name || ' ' || d.last_name AS driver_name, l.name AS origin_location_name\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.locations l ON t.origin_location_id = l.location_id\nWHERE t.status = 'Completed';"}, {"role": "user", "content": "Can you also include the scheduled and actual departure times in the results?"}, {"role": "assistant", "content": "SELECT t.trip_id, d.first_name || ' ' || d.last_name AS driver_name, l.name AS origin_location_name, t.scheduled_departure, t.actual_departure\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.locations l ON t.origin_location_id = l.location_id\nWHERE t.status = 'Completed';"}, {"role": "user", "content": "Add the city of the origin location and sort the list by scheduled departure in ascending order."}, {"role": "assistant", "content": "SELECT t.trip_id, d.first_name || ' ' || d.last_name AS driver_name, l.name AS origin_location_name, l.city AS origin_city, t.scheduled_departure, t.actual_departure\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.locations l ON t.origin_location_id = l.location_id\nWHERE t.status = 'Completed'\nORDER BY t.scheduled_departure ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers (\n driver_id character varying(64) NOT NULL, -- unique identifier for the driver\n employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number\n first_name character varying(128) NOT NULL, -- driver's first name\n last_name character varying(128) NOT NULL, -- driver's last name\n license_number character varying(64) NOT NULL UNIQUE, -- driving license number\n license_expiry_date date NOT NULL, -- expiry date of the license\n contact_number character varying(32), -- phone number\n email character varying(128) UNIQUE, -- email address\n hire_date date NOT NULL, -- date the driver was hired\n status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated\n PRIMARY KEY (driver_id)\n)\nCREATE TABLE transportation.routes (\n route_id character varying(64) NOT NULL, -- unique identifier for the route\n route_number character varying(32) NOT NULL UNIQUE, -- public-facing route number/name\n description text, -- description of the route\n origin_location_id character varying(64) NOT NULL, -- identifier of the starting location\n destination_location_id character varying(64) NOT NULL, -- identifier of the ending location\n distance_km numeric(10, 2), -- estimated distance in kilometers\n estimated_duration_minutes integer, -- estimated travel time in minutes\n type character varying(32) NOT NULL, -- e.g., City Bus, Intercity Train, Cargo Delivery\n PRIMARY KEY (route_id)\n)\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\nCREATE TABLE transportation.locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the location\n name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)\n type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address\n address_line1 character varying(255), -- street address\n city character varying(128), -- city name\n state_province character varying(128), -- state or province\n postal_code character varying(32), -- postal code\n country character varying(64) NOT NULL, -- country name\n latitude numeric(9, 6), -- geographic latitude\n longitude numeric(9, 6), -- geographic longitude\n timezone character varying(64), -- IANA timezone name (e.g., America/New_York)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\nCREATE TABLE transportation.bookings (\n booking_id character varying(64) NOT NULL, -- unique identifier for the booking\n passenger_id character varying(64) NOT NULL, -- identifier of the passenger making the booking\n trip_id character varying(64) NOT NULL, -- identifier of the trip being booked\n seat_number character varying(16), -- assigned seat number (if applicable)\n booking_time timestamp with time zone NOT NULL, -- time when the booking was made\n status character varying(32) NOT NULL, -- e.g., Confirmed, Cancelled, Pending Payment\n fare numeric(10, 2) NOT NULL, -- price paid for the booking\n payment_transaction_id character varying(128), -- reference to the payment transaction\n special_requests text, -- any special requests from the passenger\n PRIMARY KEY (booking_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show each player's username along with the number of unique games they've played, and also include the total number of sessions for each player."}, {"role": "assistant", "content": "SELECT p.player_id, p.username, COUNT(DISTINCT gs.game_id) AS unique_games_played, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.players p\nLEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nGROUP BY p.player_id, p.username;"}, {"role": "user", "content": "Can you only show players who have played more than one unique game and at least 3 sessions?"}, {"role": "assistant", "content": "SELECT p.player_id, p.username, COUNT(DISTINCT gs.game_id) AS unique_games_played, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.players p\nLEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nGROUP BY p.player_id, p.username\nHAVING COUNT(DISTINCT gs.game_id) > 1 AND COUNT(gs.session_id) >= 3;"}, {"role": "user", "content": "Please add the last_login timestamp for each player to the results."}, {"role": "assistant", "content": "SELECT p.player_id, p.username, p.last_login, COUNT(DISTINCT gs.game_id) AS unique_games_played, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.players p\nLEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nGROUP BY p.player_id, p.username, p.last_login\nHAVING COUNT(DISTINCT gs.game_id) > 1 AND COUNT(gs.session_id) >= 3;"}, {"role": "user", "content": "I only want to see players whose status is 'active' and order the results by total_sessions descending."}, {"role": "assistant", "content": "SELECT p.player_id, p.username, p.last_login, COUNT(DISTINCT gs.game_id) AS unique_games_played, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.players p\nLEFT JOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nWHERE p.status = 'active'\nGROUP BY p.player_id, p.username, p.last_login\nHAVING COUNT(DISTINCT gs.game_id) > 1 AND COUNT(gs.session_id) >= 3\nORDER BY total_sessions DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n"} {"conversations": [{"role": "user", "content": "Which centralized exchange holds the highest total USD value of tokens in the 'AI' narrative, and what is that amount?"}, {"role": "assistant", "content": "SELECT cb.exchange, SUM(cb.usd_value) AS total_usd_value\nFROM cex_token_balance cb\nJOIN smart_money_token_inflow si ON cb.token_address = si.token_address AND cb.chain = si.chain\nWHERE si.narrative = 'AI'\nGROUP BY cb.exchange\nORDER BY total_usd_value DESC\nLIMIT 1;"}, {"role": "user", "content": "Can you show the top 3 exchanges by total USD value instead of just the top one?"}, {"role": "assistant", "content": "SELECT cb.exchange, SUM(cb.usd_value) AS total_usd_value\nFROM cex_token_balance cb\nJOIN smart_money_token_inflow si ON cb.token_address = si.token_address AND cb.chain = si.chain\nWHERE si.narrative = 'AI'\nGROUP BY cb.exchange\nORDER BY total_usd_value DESC\nLIMIT 3;"}, {"role": "user", "content": "Please also include the chain for each exchange in the results."}, {"role": "assistant", "content": "SELECT cb.exchange, cb.chain, SUM(cb.usd_value) AS total_usd_value\nFROM cex_token_balance cb\nJOIN smart_money_token_inflow si ON cb.token_address = si.token_address AND cb.chain = si.chain\nWHERE si.narrative = 'AI'\nGROUP BY cb.exchange, cb.chain\nORDER BY total_usd_value DESC\nLIMIT 3;"}, {"role": "user", "content": "Actually, only show results where the total USD value is greater than 5,000,000."}, {"role": "assistant", "content": "SELECT cb.exchange, cb.chain, SUM(cb.usd_value) AS total_usd_value\nFROM cex_token_balance cb\nJOIN smart_money_token_inflow si ON cb.token_address = si.token_address AND cb.chain = si.chain\nWHERE si.narrative = 'AI'\nGROUP BY cb.exchange, cb.chain\nHAVING SUM(cb.usd_value) > 5000000\nORDER BY total_usd_value DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n \"CREATE TABLE smart_money_profit (\",\n \"address character varying(100) NOT NULL, -- the user's address\",\n \"rank INT, -- the rank of the address in trade performance, value 1 expresses the best address.\",\n \"profit numeric(38,6), -- the profit user made in a month\",\n \"roi numeric(38,2), -- the roi of the user in a month\",\n \"realized_ratio numeric(38,2), -- the percentage of the user's realized profit\",\n \"most_profit_token character varying(100), -- the token symbol of the user's most profitable trade\",\n \"last_trade_time character varying(100), -- the last trade time of the user\",\n \"chain character varying(100), -- the chain that the address resides\",\n \"PRIMARY KEY (address, chain));\",\n\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n"} {"conversations": [{"role": "user", "content": "List the names of active services and their categories provided by agencies with a 'Federal' jurisdiction level."}, {"role": "assistant", "content": "SELECT T1.service_name, T1.category FROM government_services.services AS T1 JOIN government_services.agencies AS T2 ON T1.agency_id = T2.agency_id WHERE T1.is_active = TRUE AND T2.jurisdiction_level = 'Federal';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )\nCREATE TABLE government_services.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n"} {"conversations": [{"role": "user", "content": "List all policies that were issued in the year 2023, showing the policy number, start date, end date, and premium amount."}, {"role": "assistant", "content": "SELECT policy_number, start_date, end_date, premium_amount FROM insurance.policies WHERE issued_at >= '2023-01-01 00:00:00' AND issued_at < '2024-01-01 00:00:00';"}, {"role": "user", "content": "From those policies, only show ones with a premium amount greater than 3000 and a deductible less than 1000."}, {"role": "assistant", "content": "SELECT policy_number, start_date, end_date, premium_amount FROM insurance.policies WHERE issued_at >= '2023-01-01 00:00:00' AND issued_at < '2024-01-01 00:00:00' AND premium_amount > 3000 AND deductible < 1000;"}, {"role": "user", "content": "Also, include the customer ID and order the results by premium amount descending."}, {"role": "assistant", "content": "SELECT customer_id, policy_number, start_date, end_date, premium_amount FROM insurance.policies WHERE issued_at >= '2023-01-01 00:00:00' AND issued_at < '2024-01-01 00:00:00' AND premium_amount > 3000 AND deductible < 1000 ORDER BY premium_amount DESC;"}, {"role": "user", "content": "Finally, only show policies that are still active."}, {"role": "assistant", "content": "SELECT customer_id, policy_number, start_date, end_date, premium_amount FROM insurance.policies WHERE issued_at >= '2023-01-01 00:00:00' AND issued_at < '2024-01-01 00:00:00' AND premium_amount > 3000 AND deductible < 1000 AND status = 'Active' ORDER BY premium_amount DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\n"} {"conversations": [{"role": "user", "content": "Show me all active customers from New York who have at least one active policy with coverage limit above $500,000, along with their policy details."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, p.policy_id, p.policy_number, p.start_date, p.end_date, p.coverage_limit, p.premium_amount FROM insurance.customers c JOIN insurance.policies p ON c.customer_id = p.customer_id WHERE c.state = 'New York' AND c.status = 'Active' AND p.status = 'Active' AND p.coverage_limit > 500000;"}, {"role": "user", "content": "Now include only customers who were born before 1980 and add the product name for each policy."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, p.policy_id, p.policy_number, p.start_date, p.end_date, p.coverage_limit, p.premium_amount, ip.product_name FROM insurance.customers c JOIN insurance.policies p ON c.customer_id = p.customer_id JOIN insurance.insurance_products ip ON p.product_id = ip.product_id WHERE c.state = 'New York' AND c.status = 'Active' AND p.status = 'Active' AND p.coverage_limit > 500000 AND EXTRACT(YEAR FROM c.date_of_birth) < 1980;"}, {"role": "user", "content": "I also want to see how many claims each of these customers has had in total."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, p.policy_id, p.policy_number, p.coverage_limit, p.premium_amount, ip.product_name, COUNT(cl.claim_id) AS total_claims FROM insurance.customers c JOIN insurance.policies p ON c.customer_id = p.customer_id JOIN insurance.insurance_products ip ON p.product_id = ip.product_id LEFT JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE c.state = 'New York' AND c.status = 'Active' AND p.status = 'Active' AND p.coverage_limit > 500000 AND EXTRACT(YEAR FROM c.date_of_birth) < 1980 GROUP BY c.customer_id, c.first_name, c.last_name, p.policy_id, p.policy_number, p.coverage_limit, p.premium_amount, ip.product_name;"}, {"role": "user", "content": "Finally, order the results by the highest coverage limit first, then by the number of claims in descending order."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, p.policy_id, p.policy_number, p.coverage_limit, p.premium_amount, ip.product_name, COUNT(cl.claim_id) AS total_claims FROM insurance.customers c JOIN insurance.policies p ON c.customer_id = p.customer_id JOIN insurance.insurance_products ip ON p.product_id = ip.product_id LEFT JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE c.state = 'New York' AND c.status = 'Active' AND p.status = 'Active' AND p.coverage_limit > 500000 AND EXTRACT(YEAR FROM c.date_of_birth) < 1980 GROUP BY c.customer_id, c.first_name, c.last_name, p.policy_id, p.policy_number, p.coverage_limit, p.premium_amount, ip.product_name ORDER BY p.coverage_limit DESC, total_claims DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\nCREATE TABLE insurance.agents ( agent_id text, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.claim_documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n claim_id character varying(64) NOT NULL, -- identifier of the claim this document relates to (FK to claims)\n document_type character varying(50) NOT NULL, -- e.g., Police Report, Photo, Invoice, Medical Bill\n file_name character varying(255) NOT NULL, -- original name of the uploaded file\n file_path character varying(512) NOT NULL, -- storage path (e.g., S3 URL, network path)\n file_size_bytes integer, -- size of the file in bytes\n mime_type character varying(100), -- MIME type of the file (e.g., 'image/jpeg', 'application/pdf')\n uploaded_by character varying(64), -- identifier of the user/system who uploaded (FK to users/customers)\n uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- time of upload\n description text, -- optional description of the document\n PRIMARY KEY (document_id)\n)\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n"} {"conversations": [{"role": "user", "content": "Retrieve route_number, description, and distance_km for routes that have a distance greater than the average distance of all routes."}, {"role": "assistant", "content": "SELECT route_number, description, distance_km\nFROM transportation.routes\nWHERE distance_km > (\n SELECT AVG(distance_km)\n FROM transportation.routes\n);"}, {"role": "user", "content": "Actually, I only want those routes where estimated_duration_minutes is less than 120, and sort by distance_km in descending order."}, {"role": "assistant", "content": "SELECT route_number, description, distance_km\nFROM transportation.routes\nWHERE distance_km > (\n SELECT AVG(distance_km)\n FROM transportation.routes\n)\n AND estimated_duration_minutes < 120\nORDER BY distance_km DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "List all appointments and diagnoses associated with doctor 'doctor_123'. Show appointment_id, appointment_time, reason, diagnosis_id, diagnosis_code, description, and diagnosis_date."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time, a.reason, d.diagnosis_id, d.diagnosis_code, d.description, d.diagnosis_date FROM healthcare.appointments AS a LEFT JOIN healthcare.diagnoses AS d ON a.patient_id = d.patient_id AND a.doctor_id = d.doctor_id WHERE a.doctor_id = 'doctor_123' OR d.doctor_id = 'doctor_123';"}, {"role": "user", "content": "Refine this list to only include appointments scheduled after '2023-01-01' and diagnoses made after '2023-01-01'."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time, a.reason, d.diagnosis_id, d.diagnosis_code, d.description, d.diagnosis_date FROM healthcare.appointments AS a LEFT JOIN healthcare.diagnoses AS d ON a.patient_id = d.patient_id AND a.doctor_id = d.doctor_id WHERE (a.doctor_id = 'doctor_123' AND a.appointment_time >= '2023-01-01') OR (d.doctor_id = 'doctor_123' AND d.diagnosis_date >= '2023-01-01');"}, {"role": "user", "content": "Further filter to only include appointments with status 'Completed' and chronic diagnoses (is_chronic = TRUE)."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time, a.reason, d.diagnosis_id, d.diagnosis_code, d.description, d.diagnosis_date FROM healthcare.appointments AS a LEFT JOIN healthcare.diagnoses AS d ON a.patient_id = d.patient_id AND a.doctor_id = d.doctor_id WHERE (a.doctor_id = 'doctor_123' AND a.appointment_time >= '2023-01-01' AND a.status = 'Completed') OR (d.doctor_id = 'doctor_123' AND d.diagnosis_date >= '2023-01-01' AND d.is_chronic = TRUE);"}, {"role": "user", "content": "Can you also show the location_id for the appointments and the status for the diagnoses?"}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time, a.reason, a.location_id, d.diagnosis_id, d.diagnosis_code, d.description, d.diagnosis_date, d.status FROM healthcare.appointments AS a LEFT JOIN healthcare.diagnoses AS d ON a.patient_id = d.patient_id AND a.doctor_id = d.doctor_id WHERE (a.doctor_id = 'doctor_123' AND a.appointment_time >= '2023-01-01' AND a.status = 'Completed') OR (d.doctor_id = 'doctor_123' AND d.diagnosis_date >= '2023-01-01' AND d.is_chronic = TRUE);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n"} {"conversations": [{"role": "user", "content": "Show me all customers (customer_id, first_name, last_name) from California (state = 'CA') who have both a checking account (account_type = 'Checking') and a home loan (loan_type = 'Home'), along with their total account balance and loan principal amount."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, SUM(a.balance) AS total_balance, l.principal_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.loans l ON a.account_id = l.account_id\nWHERE c.state = 'CA' AND a.account_type = 'Checking' AND l.loan_type = 'Home'\nGROUP BY c.customer_id, c.first_name, c.last_name, l.principal_amount;"}, {"role": "user", "content": "Now modify the query to only include customers with a total balance greater than $50,000 and sort them by principal_amount in descending order."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, SUM(a.balance) AS total_balance, l.principal_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.loans l ON a.account_id = l.account_id\nWHERE c.state = 'CA' AND a.account_type = 'Checking' AND l.loan_type = 'Home'\nGROUP BY c.customer_id, c.first_name, c.last_name, l.principal_amount\nHAVING SUM(a.balance) > 50000\nORDER BY l.principal_amount DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE 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 )\nCREATE TABLE financial_services.trades ( trade_id text, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE 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 )\nCREATE TABLE financial_services.employees ( employee_id text, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\nCREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )\n"} {"conversations": [{"role": "user", "content": "How many unique user_ids are there in the wallets table?"}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT user_id) FROM blockchain.wallets;"}, {"role": "user", "content": "Now show me the count of wallet addresses for each user_id."}, {"role": "assistant", "content": "SELECT user_id, COUNT(address_id) as wallet_count FROM blockchain.wallets GROUP BY user_id;"}, {"role": "user", "content": "Filter this to only show users with more than 5 wallet addresses."}, {"role": "assistant", "content": "SELECT user_id, COUNT(address_id) as wallet_count FROM blockchain.wallets GROUP BY user_id HAVING COUNT(address_id) > 5;"}, {"role": "user", "content": "Now order the results by wallet_count in descending order."}, {"role": "assistant", "content": "SELECT user_id, COUNT(address_id) as wallet_count FROM blockchain.wallets GROUP BY user_id HAVING COUNT(address_id) > 5 ORDER BY wallet_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )\n"} {"conversations": [{"role": "user", "content": "Show all SUI coins with status 'exists', listing their object ID, owner address, coin type, and balance from the sui_coins table."}, {"role": "assistant", "content": "SELECT object_id, owner, coin_type, balance FROM sui_coins WHERE status = 'exists';"}, {"role": "user", "content": "Add the symbol and name for each coin by joining with the sui_coins_metadata table. Only include coins where the metadata status is also 'exists'."}, {"role": "assistant", "content": "SELECT sc.object_id, sc.owner, sc.coin_type, sc.balance, scm.symbol, scm.name FROM sui_coins sc JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type WHERE sc.status = 'exists' AND scm.status = 'exists';"}, {"role": "user", "content": "Filter the results to only include coins where the balance is greater than 1,000,000,000, and order by balance descending. Limit the output to the top 10 results."}, {"role": "assistant", "content": "SELECT sc.object_id, sc.owner, sc.coin_type, sc.balance, scm.symbol, scm.name FROM sui_coins sc JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type WHERE sc.status = 'exists' AND scm.status = 'exists' AND sc.balance > '1000000000' ORDER BY CAST(sc.balance AS REAL) DESC LIMIT 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE 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 )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_activities_bitcoin ( 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 )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE 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 )\n"} {"conversations": [{"role": "user", "content": "I need the average capacity of vehicles for each fuel_type."}, {"role": "assistant", "content": "SELECT fuel_type,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type;"}, {"role": "user", "content": "Only include fuel types where the vehicle count is at least 10."}, {"role": "assistant", "content": "SELECT fuel_type,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Also show the number of vehicles for each of these fuel types."}, {"role": "assistant", "content": "SELECT fuel_type,\n COUNT(*) AS vehicle_count,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Please round avg_capacity to one decimal place."}, {"role": "assistant", "content": "SELECT fuel_type,\n COUNT(*) AS vehicle_count,\n ROUND(AVG(capacity)::numeric, 1) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\n"}