{"conversations": [{"role": "user", "content": "How many employees work in each department? List the department name and the count."}, {"role": "assistant", "content": "SELECT department, COUNT(*) FROM government_services.employees GROUP BY department"}, {"role": "user", "content": "Only show departments with more than 5 employees."}, {"role": "assistant", "content": "SELECT department, COUNT(*) FROM government_services.employees GROUP BY department HAVING COUNT(*) > 5"}, {"role": "user", "content": "For these departments, also list the job titles present."}, {"role": "assistant", "content": "SELECT department, COUNT(*), STRING_AGG(DISTINCT job_title, ', ') FROM government_services.employees GROUP BY department HAVING COUNT(*) > 5"}, {"role": "user", "content": "Add the total number of employees hired in 2023 for each of these departments."}, {"role": "assistant", "content": "SELECT department, COUNT(*), STRING_AGG(DISTINCT job_title, ', '), SUM(CASE WHEN EXTRACT(YEAR FROM hire_date) = 2023 THEN 1 ELSE 0 END) AS employees_hired_in_2023 FROM government_services.employees GROUP BY department HAVING COUNT(*) > 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 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.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 (\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.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 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.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 )\n"} {"conversations": [{"role": "user", "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": "assistant", "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;"}], "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": "List the first and last name of each citizen along with the city and state of the service location for their agency."}, {"role": "assistant", "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;"}], "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": [{"role": "user", "content": "For each block number, show the highest transaction value and the status of the transaction with the highest value."}, {"role": "assistant", "content": "SELECT t.block_number, t.value AS max_value, t.status\nFROM web3.transactions t\nJOIN (\n SELECT block_number, MAX(value) AS max_value\n FROM web3.transactions\n GROUP BY block_number\n) mv\n ON t.block_number = mv.block_number AND t.value = mv.max_value;"}], "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": [{"role": "user", "content": "What is the average ROI for smart money addresses on the Ethereum chain with a realized ratio above 70%?"}, {"role": "assistant", "content": "SELECT AVG(roi) FROM smart_money_profit WHERE chain = 'Ethereum' AND realized_ratio > 70;"}], "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 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, -- 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) )\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) )\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) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n"} {"conversations": [{"role": "user", "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": "assistant", "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;"}], "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": [{"role": "user", "content": "For each chain, find the narrative category that has the highest total market_cap and display the chain, narrative, and that total market_cap."}, {"role": "assistant", "content": "SELECT chain,\n narrative,\n total_cap\nFROM (\n SELECT chain,\n narrative,\n SUM(market_cap) AS total_cap,\n RANK() OVER (PARTITION BY chain ORDER BY SUM(market_cap) DESC) AS rnk\n FROM token_basic_info\n GROUP BY chain, narrative\n) t\nWHERE rnk = 1;"}, {"role": "user", "content": "I received an error about window functions. Can you rewrite the query without using window functions?"}, {"role": "assistant", "content": "WITH agg AS (\n SELECT chain,\n narrative,\n SUM(market_cap) AS total_cap\n FROM token_basic_info\n GROUP BY chain, narrative\n),\nmax_cap AS (\n SELECT chain,\n MAX(total_cap) AS max_cap\n FROM agg\n GROUP BY chain\n)\nSELECT a.chain,\n a.narrative,\n a.total_cap\nFROM agg a\nJOIN max_cap m\n ON a.chain = m.chain\n AND a.total_cap = m.max_cap;"}], "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 )\n"} {"conversations": [{"role": "user", "content": "Get a list of all policies that have at least two beneficiaries with a percentage_share greater than 20%. Include policy_id, policy_number, and beneficiary_count."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, COUNT(pb.beneficiary_id) AS beneficiary_count\nFROM insurance.policies p\nJOIN insurance.policy_beneficiaries pb\n ON p.policy_id = pb.policy_id\nWHERE pb.percentage_share > 20\nGROUP BY p.policy_id, p.policy_number\nHAVING COUNT(pb.beneficiary_id) >= 2;"}, {"role": "user", "content": "Also include the names of those beneficiaries concatenated as a comma-separated string labeled beneficiaries."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number,\n COUNT(pb.beneficiary_id) AS beneficiary_count,\n STRING_AGG(pb.first_name || ' ' || pb.last_name, ', ') AS beneficiaries\nFROM insurance.policies p\nJOIN insurance.policy_beneficiaries pb\n ON p.policy_id = pb.policy_id\nWHERE pb.percentage_share > 20\nGROUP BY p.policy_id, p.policy_number\nHAVING COUNT(pb.beneficiary_id) >= 2;"}], "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.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 ( 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.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.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 ( payment_id text, 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.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n"} {"conversations": [{"role": "user", "content": "For each asset, show its name and symbol, and the total number of completed orders that have resulted in at least one trade."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COUNT(DISTINCT o.order_id) AS completed_order_count\nFROM trading_platform.assets a\nJOIN trading_platform.orders o ON o.asset_id = a.asset_id AND o.status = 'filled'\nJOIN trading_platform.trades t ON t.order_id = o.order_id\nGROUP BY a.asset_id, a.name, a.symbol;"}, {"role": "user", "content": "Only include assets where the total number of completed orders with trades is greater than 5, and sort the results by completed_order_count descending."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COUNT(DISTINCT o.order_id) AS completed_order_count\nFROM trading_platform.assets a\nJOIN trading_platform.orders o ON o.asset_id = a.asset_id AND o.status = 'filled'\nJOIN trading_platform.trades t ON t.order_id = o.order_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COUNT(DISTINCT o.order_id) > 5\nORDER BY completed_order_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 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 (\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, name text, symbol text, type text )\nCREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text )\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 ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "Show the first name, last name, and position of all staff members who are not currently active."}, {"role": "assistant", "content": "SELECT first_name , last_name , position FROM hospitality_technology.staff WHERE is_active = 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 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 (\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.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.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": "How many smart money addresses are recorded for each chain?"}, {"role": "assistant", "content": "SELECT chain, COUNT(address) FROM smart_money_profit GROUP BY chain;"}, {"role": "user", "content": "Now, only show chains that have more than 100 recorded addresses."}, {"role": "assistant", "content": "SELECT chain, COUNT(address) FROM smart_money_profit GROUP BY chain HAVING COUNT(address) > 100;"}, {"role": "user", "content": "Can you order the results by the number of addresses in descending order?"}, {"role": "assistant", "content": "SELECT chain, COUNT(address) FROM smart_money_profit GROUP BY chain HAVING COUNT(address) > 100 ORDER BY COUNT(address) DESC;"}, {"role": "user", "content": "Also, include the average ROI for addresses on these chains."}, {"role": "assistant", "content": "SELECT chain, COUNT(address), AVG(roi) FROM smart_money_profit GROUP BY chain HAVING COUNT(address) > 100 ORDER BY COUNT(address) DESC;"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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": "I want to see the total sum of transaction amounts and their average amount for each transaction_type along with the total number of transactions, grouped by currency."}, {"role": "assistant", "content": "SELECT transaction_type, currency, COUNT(*) AS total_transactions, SUM(amount) AS total_amount, AVG(amount) AS average_amount FROM financial_services.transactions GROUP BY transaction_type, currency;"}, {"role": "user", "content": "Can you filter out transactions where the status is not 'SUCCESSFUL' or 'PENDING'?"}, {"role": "assistant", "content": "SELECT transaction_type, currency, COUNT(*) AS total_transactions, SUM(amount) AS total_amount, AVG(amount) AS average_amount FROM financial_services.transactions WHERE status IN ('SUCCESSFUL', 'PENDING') GROUP BY transaction_type, currency;"}, {"role": "user", "content": "Also, show only the results where the total_amount is greater than 10000."}, {"role": "assistant", "content": "SELECT transaction_type, currency, COUNT(*) AS total_transactions, SUM(amount) AS total_amount, AVG(amount) AS average_amount FROM financial_services.transactions WHERE status IN ('SUCCESSFUL', 'PENDING') GROUP BY transaction_type, currency HAVING SUM(amount) > 10000;"}, {"role": "user", "content": "Sort the results by average_amount in ascending order."}, {"role": "assistant", "content": "SELECT transaction_type, currency, COUNT(*) AS total_transactions, SUM(amount) AS total_amount, AVG(amount) AS average_amount FROM financial_services.transactions WHERE status IN ('SUCCESSFUL', 'PENDING') GROUP BY transaction_type, currency HAVING SUM(amount) > 10000 ORDER BY average_amount 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 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 )\n"} {"conversations": [{"role": "user", "content": "List all documents that have multiple versions, including document_name, case_id, and the count of versions."}, {"role": "assistant", "content": "SELECT document_name,\n case_id,\n COUNT(*) AS version_count\nFROM legal_services.documents\nGROUP BY document_name, case_id\nHAVING COUNT(*) > 1;"}, {"role": "user", "content": "Actually, I only want to include those with at least three versions."}, {"role": "assistant", "content": "SELECT document_name,\n case_id,\n COUNT(*) AS version_count\nFROM legal_services.documents\nGROUP BY document_name, case_id\nHAVING COUNT(*) >= 3;"}, {"role": "user", "content": "Also include the lawyer ID who uploaded the latest version for each document."}, {"role": "assistant", "content": "SELECT d.document_name,\n d.case_id,\n m.version_count,\n d.uploaded_by_lawyer_id\nFROM legal_services.documents d\nJOIN (\n SELECT document_name,\n case_id,\n COUNT(*) AS version_count,\n MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY document_name, case_id\n HAVING COUNT(*) >= 3\n) m\n ON d.document_name = m.document_name\n AND d.case_id = m.case_id\n AND d.version = m.max_version;"}], "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": [{"role": "user", "content": "List the citizen IDs for individuals who have both uploaded documents and made payments."}, {"role": "assistant", "content": "SELECT DISTINCT T1.citizen_id FROM documents AS T1 JOIN payments AS T2 ON T1.citizen_id = T2.citizen_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.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": [{"role": "user", "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": "assistant", "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;"}], "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": [{"role": "user", "content": "List the total value and count of transactions for each status, ordered by total value descending."}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS transaction_count, SUM(value) AS total_value\nFROM web3.transactions\nGROUP BY status\nORDER BY total_value DESC;"}, {"role": "user", "content": "Actually, can you also include the average value per transaction for each status?"}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS transaction_count, SUM(value) AS total_value, AVG(value) AS avg_value\nFROM web3.transactions\nGROUP BY status\nORDER BY total_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\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": [{"role": "user", "content": "What is the total sum of all amounts for all UTXOs in the system, regardless of whether they are spent or unspent?"}, {"role": "assistant", "content": "SELECT SUM(amount) FROM trading_platform.utxos"}], "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.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.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.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": [{"role": "user", "content": "What is the average balance of all addresses in the database?"}, {"role": "assistant", "content": "SELECT AVG(balance) as average_balance FROM blockchain.addresses;"}, {"role": "user", "content": "Can you break this down by the first 3 characters of the address_id?"}, {"role": "assistant", "content": "SELECT SUBSTRING(address_id, 1, 3) as address_prefix, AVG(balance) as average_balance FROM blockchain.addresses GROUP BY SUBSTRING(address_id, 1, 3);"}, {"role": "user", "content": "Now show only address prefixes where the average balance is greater than 1000."}, {"role": "assistant", "content": "SELECT SUBSTRING(address_id, 1, 3) as address_prefix, AVG(balance) as average_balance FROM blockchain.addresses GROUP BY SUBSTRING(address_id, 1, 3) HAVING AVG(balance) > 1000;"}, {"role": "user", "content": "Can you order these results by the average balance in descending order?"}, {"role": "assistant", "content": "SELECT SUBSTRING(address_id, 1, 3) as address_prefix, AVG(balance) as average_balance FROM blockchain.addresses GROUP BY SUBSTRING(address_id, 1, 3) HAVING AVG(balance) > 1000 ORDER BY average_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 blockchain.addresses ( address_id.text, public_key.text, balance.numeric )\n"} {"conversations": [{"role": "user", "content": "Find pairs of citizens who share the same gender but registered in different years. Show each citizen's first and last name along with their registration year."}, {"role": "assistant", "content": "SELECT c1.first_name AS first_name_1,\n c1.last_name AS last_name_1,\n EXTRACT(YEAR FROM c1.registration_date) AS reg_year_1,\n c2.first_name AS first_name_2,\n c2.last_name AS last_name_2,\n EXTRACT(YEAR FROM c2.registration_date) AS reg_year_2\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON c1.gender = c2.gender\n AND EXTRACT(YEAR FROM c1.registration_date) <> EXTRACT(YEAR FROM c2.registration_date)\n AND c1.citizen_id < c2.citizen_id;"}, {"role": "user", "content": "Exclude any pairs where either citizen is not verified."}, {"role": "assistant", "content": "SELECT c1.first_name AS first_name_1,\n c1.last_name AS last_name_1,\n EXTRACT(YEAR FROM c1.registration_date) AS reg_year_1,\n c2.first_name AS first_name_2,\n c2.last_name AS last_name_2,\n EXTRACT(YEAR FROM c2.registration_date) AS reg_year_2\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON c1.gender = c2.gender\n AND EXTRACT(YEAR FROM c1.registration_date) <> EXTRACT(YEAR FROM c2.registration_date)\n AND c1.citizen_id < c2.citizen_id\nWHERE c1.is_verified = TRUE\n AND c2.is_verified = 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.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 )\n"} {"conversations": [{"role": "user", "content": "Find transactions where the from_address is the same as the to_address (self-transactions) with values greater than 1 ETH (1e18 wei), showing transaction_id and value."}, {"role": "assistant", "content": "SELECT transaction_id, value FROM web3.transactions WHERE from_address = to_address AND value > 1000000000000000000;"}], "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 me all bookings with a status of 'confirmed' that were made in the last 7 days, including passenger_id and fare."}, {"role": "assistant", "content": "SELECT b.booking_id, b.passenger_id, b.fare FROM transportation.bookings b WHERE b.status = 'confirmed' AND b.booking_time >= CURRENT_DATE - INTERVAL '7 days';"}, {"role": "user", "content": "Now include only bookings where the fare is greater than $50 and order them by booking_time in descending order."}, {"role": "assistant", "content": "SELECT b.booking_id, b.passenger_id, b.fare FROM transportation.bookings b WHERE b.status = 'confirmed' AND b.booking_time >= CURRENT_DATE - INTERVAL '7 days' AND b.fare > 50 ORDER BY b.booking_time DESC;"}, {"role": "user", "content": "Can you also include the trip_id and filter to only show bookings for trip_id 'TRIP789'?"}, {"role": "assistant", "content": "SELECT b.booking_id, b.passenger_id, b.fare, b.trip_id FROM transportation.bookings b WHERE b.status = 'confirmed' AND b.booking_time >= CURRENT_DATE - INTERVAL '7 days' AND b.fare > 50 AND b.trip_id = 'TRIP789' ORDER BY b.booking_time 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) )\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.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.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\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": "List all available services in the 'Housekeeping' department that cost less than 20."}, {"role": "assistant", "content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20;"}, {"role": "user", "content": "Sort the results by service_name in ascending order."}, {"role": "assistant", "content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20\nORDER BY service_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 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.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\n"} {"conversations": [{"role": "user", "content": "Show the name and symbol for all assets in the system."}, {"role": "assistant", "content": "SELECT name, symbol FROM assets;"}, {"role": "user", "content": "Now, include any associated metadata key and value for each asset. If an asset has no metadata, it should still be listed."}, {"role": "assistant", "content": "SELECT T1.name, T1.symbol, T2.key, T2.value FROM assets AS T1 LEFT JOIN metadata AS T2 ON T1.asset_id = T2.asset_id;"}, {"role": "user", "content": "Filter the results to only show entries where the metadata key contains the word 'description' and the asset type is 'cryptocurrency'."}, {"role": "assistant", "content": "SELECT T1.name, T1.symbol, T2.key, T2.value FROM assets AS T1 LEFT JOIN metadata AS T2 ON T1.asset_id = T2.asset_id WHERE T2.key LIKE '%description%' AND T1.type = 'cryptocurrency';"}, {"role": "user", "content": "Sort the final list by asset name alphabetically."}, {"role": "assistant", "content": "SELECT T1.name, T1.symbol, T2.key, T2.value FROM assets AS T1 LEFT JOIN metadata AS T2 ON T1.asset_id = T2.asset_id WHERE T2.key LIKE '%description%' AND T1.type = 'cryptocurrency' ORDER BY T1.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 trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\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.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": [{"role": "user", "content": "Get the number of documents for each case, showing case_id and document count, ordered by count descending."}, {"role": "assistant", "content": "SELECT case_id,\n COUNT(*) AS document_count\nFROM legal_services.documents\nGROUP BY case_id\nORDER BY document_count DESC;"}, {"role": "user", "content": "Actually, only count documents of type 'Evidence'."}, {"role": "assistant", "content": "SELECT case_id,\n COUNT(*) AS evidence_count\nFROM legal_services.documents\nWHERE document_type = 'Evidence'\nGROUP BY case_id\nORDER BY evidence_count DESC;"}, {"role": "user", "content": "Also, include the case_name from the cases table."}, {"role": "assistant", "content": "SELECT d.case_id,\n c.case_name,\n COUNT(*) AS evidence_count\nFROM legal_services.documents d\nJOIN legal_services.cases c ON d.case_id = c.case_id\nWHERE d.document_type = 'Evidence'\nGROUP BY d.case_id, c.case_name\nORDER BY evidence_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.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": [{"role": "user", "content": "List all accounts opened in the last 18 months, including the account number, account type, and the full name of the customer."}, {"role": "assistant", "content": "SELECT a.account_number, a.account_type, c.first_name, c.last_name, a.opened_date FROM financial_services.accounts a JOIN financial_services.customers c ON a.customer_id = c.customer_id WHERE a.opened_date >= CURRENT_DATE - INTERVAL '18 months' ORDER BY a.opened_date DESC;"}, {"role": "user", "content": "Additionally, filter this list to only include accounts with a status of 'Open'."}, {"role": "assistant", "content": "SELECT a.account_number, a.account_type, c.first_name, c.last_name, a.opened_date FROM financial_services.accounts a JOIN financial_services.customers c ON a.customer_id = c.customer_id WHERE a.opened_date >= CURRENT_DATE - INTERVAL '18 months' AND a.status = 'Open' ORDER BY a.opened_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 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": [{"role": "user", "content": "Find all medical records where the treatment plan includes 'physical therapy' and the patient has an active primary insurance plan, showing the patient ID, record date, and insurance provider details."}, {"role": "assistant", "content": "SELECT mr.patient_id, mr.record_date, ip.insurance_provider, ip.plan_name, pi.policy_number FROM healthcare.medical_records mr JOIN healthcare.patients p ON mr.patient_id = p.patient_id JOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id AND pi.is_primary = true JOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id WHERE mr.treatment_plan LIKE '%physical therapy%' AND (pi.expiration_date IS NULL OR pi.expiration_date > CURRENT_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 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 ( 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 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 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.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)\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": "Find all NFTs with a rarity rank less than 100 and show their name and the name of their collection."}, {"role": "assistant", "content": "SELECT nm.name AS nft_name, nc.name AS collection_name FROM nft_metadata nm JOIN nft_collections nc ON nm.contract_address = nc.contract_address WHERE nm.rarity_rank < 100;"}, {"role": "user", "content": "Filter that further to only include NFTs from collections named 'Bored Ape Yacht Club'."}, {"role": "assistant", "content": "SELECT nm.name AS nft_name, nc.name AS collection_name FROM nft_metadata nm JOIN nft_collections nc ON nm.contract_address = nc.contract_address WHERE nm.rarity_rank < 100 AND nc.name = 'Bored Ape Yacht Club';"}], "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 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 ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\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 ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner 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_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\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_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\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_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 ( 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": "Show me the content and creation time of comments made on posts authored by the user with ID 'user_X'."}, {"role": "assistant", "content": "SELECT T1.content, T1.created_at FROM social_media.comments AS T1 JOIN social_media.posts AS T2 ON T1.post_id = T2.post_id WHERE T2.user_id = 'user_X';"}, {"role": "user", "content": "Can you also include the username of the user who made each comment?"}, {"role": "assistant", "content": "SELECT T1.content, T1.created_at, T3.username FROM social_media.comments AS T1 JOIN social_media.posts AS T2 ON T1.post_id = T2.post_id JOIN social_media.users AS T3 ON T1.user_id = T3.user_id WHERE T2.user_id = 'user_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 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)\n"} {"conversations": [{"role": "user", "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": "assistant", "content": "SELECT project_name, AVG(investment_value) AS average_investment FROM project_fundraising_record GROUP BY project_name HAVING COUNT(*) > 1;"}, {"role": "user", "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": "assistant", "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;"}], "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": [{"role": "user", "content": "Calculate the total billable hours spent by each lawyer for entries in March 2024."}, {"role": "assistant", "content": "SELECT lawyer_id,\n SUM(hours_spent) AS total_hours\nFROM legal_services.time_entries\nWHERE is_billable = TRUE\n AND date_worked BETWEEN '2024-03-01' AND '2024-03-31'\nGROUP BY lawyer_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 (\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)\n"} {"conversations": [{"role": "user", "content": "List group conversation names and the number of messages sent in each conversation after January 1, 2023."}, {"role": "assistant", "content": "SELECT c.group_name, COUNT(m.message_id) FROM social_media.conversations c JOIN social_media.messages m ON c.conversation_id = m.conversation_id WHERE c.is_group_chat = true AND m.sent_at >= '2023-01-01' GROUP BY c.conversation_id, c.group_name;"}, {"role": "user", "content": "Only show conversations that have more than 100 messages sent after that date."}, {"role": "assistant", "content": "SELECT c.group_name, COUNT(m.message_id) FROM social_media.conversations c JOIN social_media.messages m ON c.conversation_id = m.conversation_id WHERE c.is_group_chat = true AND m.sent_at >= '2023-01-01' GROUP BY c.conversation_id, c.group_name HAVING COUNT(m.message_id) > 100;"}], "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.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.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.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )\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": [{"role": "user", "content": "List all premium payments made by Bank Transfer where the amount_paid is greater than 5000. Show payment_id, policy_id, customer_id, amount_paid, and payment_date, ordered by amount_paid descending."}, {"role": "assistant", "content": "SELECT payment_id,\n policy_id,\n customer_id,\n amount_paid,\n payment_date\nFROM insurance.premium_payments\nWHERE payment_method = 'Bank Transfer'\n AND amount_paid > 5000\nORDER BY amount_paid 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": "Show the tokens with a negative net flow this month on all chains."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now());"}, {"role": "user", "content": "Order them by net flow ascending and only show the bottom 5."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now()) ORDER BY net_flow ASC 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 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": [{"role": "user", "content": "Retrieve a list of beneficiaries who are assigned to more than one policy. Show customer_id, first_name, last_name, and the number of policies they are beneficiaries on."}, {"role": "assistant", "content": "SELECT pb.customer_id, pb.first_name, pb.last_name, COUNT(*) AS policy_count FROM insurance.policy_beneficiaries pb GROUP BY pb.customer_id, pb.first_name, pb.last_name HAVING COUNT(*) > 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 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.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) )\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": "Show me the hashtag IDs and their names."}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name FROM social_media.hashtags;"}, {"role": "user", "content": "I also want to see when each hashtag was created."}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name, created_at FROM social_media.hashtags;"}, {"role": "user", "content": "Filter the list to only show hashtags whose name starts with the letter 'S'."}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name, created_at FROM social_media.hashtags WHERE tag_name LIKE 'S%';"}], "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.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) )\n"} {"conversations": [{"role": "user", "content": "Find guests who have made at least one payment using a 'CreditCard'. List their full name (first and last name) and email address."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name, T1.last_name, T1.email FROM hospitality_technology.guests AS T1 JOIN hospitality_technology.payments AS T2 ON T1.guest_id = T2.guest_id WHERE T2.payment_method = 'CreditCard';"}, {"role": "user", "content": "For these guests, also show the total amount they have paid using a 'CreditCard'."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.email, SUM(T2.amount) AS total_credit_card_amount FROM hospitality_technology.guests AS T1 JOIN hospitality_technology.payments AS T2 ON T1.guest_id = T2.guest_id WHERE T2.payment_method = 'CreditCard' GROUP BY T1.guest_id, T1.first_name, T1.last_name, T1.email;"}, {"role": "user", "content": "Now, only include guests where the total credit card payment exceeds 5000."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.email, SUM(T2.amount) AS total_credit_card_amount FROM hospitality_technology.guests AS T1 JOIN hospitality_technology.payments AS T2 ON T1.guest_id = T2.guest_id WHERE T2.payment_method = 'CreditCard' GROUP BY T1.guest_id, T1.first_name, T1.last_name, T1.email HAVING SUM(T2.amount) > 5000;"}], "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 (\n guest_id character varying(64) NOT NULL, -- unique identifier for the guest profile\n first_name character varying(100) NOT NULL, -- guest's first name\n last_name character varying(100) NOT NULL, -- guest's last name\n email character varying(255) UNIQUE, -- guest's email address (unique identifier?)\n phone_number character varying(30), -- guest's phone number\n date_of_birth date, -- guest's date of birth\n address_line1 character varying(255), -- guest's home address\n city character varying(100),\n state_province character varying(100),\n postal_code character varying(20),\n country_code character varying(3),\n preferences text, -- notes on guest preferences (e.g., allergies, room location)\n loyalty_member_id character varying(64) UNIQUE, -- FK to loyalty_members table\n communication_consent boolean DEFAULT true, -- consent for marketing communications\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 (guest_id)\n)\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)\n"} {"conversations": [{"role": "user", "content": "I want a list of game_id and the count of hidden achievements for each game."}, {"role": "assistant", "content": "SELECT game_id, COUNT(*) AS hidden_achievement_count\nFROM gaming_technology.achievements\nWHERE hidden = TRUE\nGROUP BY game_id;"}, {"role": "user", "content": "Now only include games where the hidden_achievement_count is greater than 5."}, {"role": "assistant", "content": "SELECT game_id, COUNT(*) AS hidden_achievement_count\nFROM gaming_technology.achievements\nWHERE hidden = TRUE\nGROUP BY game_id\nHAVING COUNT(*) > 5;"}, {"role": "user", "content": "Also order the results by hidden_achievement_count in descending order."}, {"role": "assistant", "content": "SELECT game_id, COUNT(*) AS hidden_achievement_count\nFROM gaming_technology.achievements\nWHERE hidden = TRUE\nGROUP BY game_id\nHAVING COUNT(*) > 5\nORDER BY hidden_achievement_count DESC;"}, {"role": "user", "content": "Finally, include the average points of those hidden achievements as avg_hidden_points."}, {"role": "assistant", "content": "SELECT game_id,\n COUNT(*) AS hidden_achievement_count,\n AVG(points) AS avg_hidden_points\nFROM gaming_technology.achievements\nWHERE hidden = TRUE\nGROUP BY game_id\nHAVING COUNT(*) > 5\nORDER BY hidden_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.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.games ( game_id uuid PRIMARY KEY, 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.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 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, game_id.uuid, name.text, description.text, icon_url.text, points.integer, 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.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 )\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 SUI coins, showing object ID, owner address, and balance."}, {"role": "assistant", "content": "SELECT object_id, owner, balance FROM sui_coins;"}, {"role": "user", "content": "Include the coin symbol and name by joining with the metadata table. Also show the status from both tables."}, {"role": "assistant", "content": "SELECT sc.object_id, sc.owner, sc.balance, sc.coin_type, sm.symbol, sm.name, sc.status AS sui_coins_status, sm.status AS metadata_status FROM sui_coins sc JOIN sui_coins_metadata sm ON sc.coin_type = sm.coin_type;"}, {"role": "user", "content": "Only show coins where both statuses are 'exists' and the balance is greater than '100000000'."}, {"role": "assistant", "content": "SELECT sc.object_id, sc.owner, sc.balance, sc.coin_type, sm.symbol, sm.name, sc.status AS sui_coins_status, sm.status AS metadata_status FROM sui_coins sc JOIN sui_coins_metadata sm ON sc.coin_type = sm.coin_type WHERE sc.status = 'exists' AND sm.status = 'exists' AND CAST(sc.balance AS DECIMAL) > 100000000;"}, {"role": "user", "content": "Order the results by balance descending and limit to the top 10."}, {"role": "assistant", "content": "SELECT sc.object_id, sc.owner, sc.balance, sc.coin_type, sm.symbol, sm.name, sc.status AS sui_coins_status, sm.status AS metadata_status FROM sui_coins sc JOIN sui_coins_metadata sm ON sc.coin_type = sm.coin_type WHERE sc.status = 'exists' AND sm.status = 'exists' AND CAST(sc.balance AS DECIMAL) > 100000000 ORDER BY CAST(sc.balance AS DECIMAL) 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 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 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 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 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 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 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_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": [{"role": "user", "content": "How many unique patient records are there for each gender?"}, {"role": "assistant", "content": "SELECT gender, COUNT(DISTINCT patient_id) AS patient_count FROM healthcare.patients GROUP BY gender;"}], "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": "Show me all reservations with their guest IDs and room IDs where the total amount is greater than $500 and the status is 'Confirmed', ordered by check-in date."}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, room_id, check_in_date, total_amount FROM hospitality_technology.reservations WHERE total_amount > 500 AND status = 'Confirmed' ORDER BY check_in_date;"}, {"role": "user", "content": "Now, join this with the service_orders table to include the total price of all services ordered for each reservation."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount, SUM(so.total_price) AS total_service_price FROM hospitality_technology.reservations r LEFT JOIN hospitality_technology.service_orders so ON r.reservation_id = so.reservation_id WHERE r.total_amount > 500 AND r.status = 'Confirmed' GROUP BY r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount ORDER BY r.check_in_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 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 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.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 me all pairs of cases led by the same lawyer, including both case names and the lead lawyer ID."}, {"role": "assistant", "content": "SELECT c1.lead_lawyer_id,\n c1.case_name AS case_name_1,\n c2.case_name AS case_name_2\nFROM legal_services.cases c1\nJOIN legal_services.cases c2\n ON c1.lead_lawyer_id = c2.lead_lawyer_id\n AND c1.case_id < c2.case_id;"}, {"role": "user", "content": "Actually, only include pairs where the case types are also the same."}, {"role": "assistant", "content": "SELECT c1.lead_lawyer_id,\n c1.case_name AS case_name_1,\n c2.case_name AS case_name_2\nFROM legal_services.cases c1\nJOIN legal_services.cases c2\n ON c1.lead_lawyer_id = c2.lead_lawyer_id\n AND c1.case_type = c2.case_type\n AND c1.case_id < c2.case_id;"}, {"role": "user", "content": "Also, show me the earliest opening date between the two cases for each pair."}, {"role": "assistant", "content": "SELECT c1.lead_lawyer_id,\n c1.case_name AS case_name_1,\n c2.case_name AS case_name_2,\n LEAST(c1.date_opened, c2.date_opened) AS earliest_open_date\nFROM legal_services.cases c1\nJOIN legal_services.cases c2\n ON c1.lead_lawyer_id = c2.lead_lawyer_id\n AND c1.case_type = c2.case_type\n AND c1.case_id < c2.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.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": [{"role": "user", "content": "For each user, show the most recently created wallet address and the wallet creation timestamp."}, {"role": "assistant", "content": "SELECT w1.user_id, w1.address, w1.created_at\nFROM web3.wallets w1\nJOIN (\n SELECT user_id, MAX(created_at) AS max_created_at\n FROM web3.wallets\n GROUP BY user_id\n) w2 ON w1.user_id = w2.user_id AND w1.created_at = w2.max_created_at;"}, {"role": "user", "content": "Can you also include the wallet_id of the most recent wallet for each user in the result?"}, {"role": "assistant", "content": "SELECT w1.user_id, w1.wallet_id, w1.address, w1.created_at\nFROM web3.wallets w1\nJOIN (\n SELECT user_id, MAX(created_at) AS max_created_at\n FROM web3.wallets\n GROUP BY user_id\n) w2 ON w1.user_id = w2.user_id AND w1.created_at = w2.max_created_at;"}], "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": [{"role": "user", "content": "List all unique actions that have been logged in the system."}, {"role": "assistant", "content": "SELECT DISTINCT action FROM trading_platform.logs;"}], "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 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 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.kyc_audit ( kyc_audit_id.text, 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 )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n"} {"conversations": [{"role": "user", "content": "I need to find all bookings for a specific schedule with schedule_id 'sched_1122' and include the passenger and ticket details."}, {"role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGETALL ticket:tkt_*"}, {"role": "user", "content": "Can you filter the tickets to show only those that are not checked in?"}, {"role": "assistant", "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": "user", "content": "Can you also include the car details for each ticket?"}, {"role": "assistant", "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"}], "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": [{"role": "user", "content": "Provide a report of each user with their username and the count of all log entries from the last 30 days."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(l.log_id) AS log_count\nFROM trading_platform.users u\nLEFT JOIN trading_platform.logs l\n ON u.user_id = l.user_id\n AND l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Actually, show only logs where the action includes the word 'trade'."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(l.log_id) AS log_count\nFROM trading_platform.users u\nJOIN trading_platform.logs l\n ON u.user_id = l.user_id\nWHERE l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\n AND l.action ILIKE '%trade%'\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Also include the earliest log date for each user in that period."}, {"role": "assistant", "content": "SELECT u.user_id,\n u.username,\n COUNT(l.log_id) AS log_count,\n MIN(l.logged_at) AS first_log_date\nFROM trading_platform.users u\nJOIN trading_platform.logs l\n ON u.user_id = l.user_id\nWHERE l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\n AND l.action ILIKE '%trade%'\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Finally, sort the results by log_count descending and limit to the top 5 users."}, {"role": "assistant", "content": "SELECT u.user_id,\n u.username,\n COUNT(l.log_id) AS log_count,\n MIN(l.logged_at) AS first_log_date\nFROM trading_platform.users u\nJOIN trading_platform.logs l\n ON u.user_id = l.user_id\nWHERE l.logged_at >= CURRENT_DATE - INTERVAL '30 days'\n AND l.action ILIKE '%trade%'\nGROUP BY u.user_id, u.username\nORDER BY log_count 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 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.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.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": [{"role": "user", "content": "List usernames and the length of their 'bio' field for users whose 'is_verified' status is true."}, {"role": "assistant", "content": "SELECT username, LENGTH(bio) AS bio_length FROM social_media.users WHERE is_verified IS 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 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": [{"role": "user", "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": "assistant", "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;"}], "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": [{"role": "user", "content": "Show me the notification ID, recipient user ID, and notification type for notifications received by users that user 'user123' is following."}, {"role": "assistant", "content": "SELECT n.notification_id, n.recipient_user_id, n.notification_type FROM social_media.notifications AS n JOIN social_media.follows AS f ON n.recipient_user_id = f.following_user_id WHERE f.follower_user_id = 'user123';"}, {"role": "user", "content": "Filter this list to only include notifications created after '2024-06-01' and also show the notification creation time."}, {"role": "assistant", "content": "SELECT n.notification_id, n.recipient_user_id, n.notification_type, n.created_at FROM social_media.notifications AS n JOIN social_media.follows AS f ON n.recipient_user_id = f.following_user_id WHERE f.follower_user_id = 'user123' AND n.created_at >= '2024-06-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 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.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, 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": [{"role": "user", "content": "Find all in-game items that have a 'mana_cost' attribute in their attributes JSON. Show the item ID, item name, and the value of the 'mana_cost'."}, {"role": "assistant", "content": "SELECT item_id, item_name, attributes ->> 'mana_cost' AS mana_cost FROM gaming_technology.in_game_items WHERE attributes ? 'mana_cost'"}, {"role": "user", "content": "Now, only include items where the 'mana_cost' is greater than 50."}, {"role": "assistant", "content": "SELECT item_id, item_name, attributes ->> 'mana_cost' AS mana_cost FROM gaming_technology.in_game_items WHERE attributes ? 'mana_cost' AND (attributes ->> 'mana_cost')::int > 50"}, {"role": "user", "content": "Add the item's rarity and the title of the game it belongs to in the output."}, {"role": "assistant", "content": "SELECT t1.item_id, t1.item_name, t1.rarity, t2.title, t1.attributes ->> 'mana_cost' AS mana_cost FROM gaming_technology.in_game_items AS t1 JOIN gaming_technology.games AS t2 ON t1.game_id = t2.game_id WHERE t1.attributes ? 'mana_cost' AND (t1.attributes ->> 'mana_cost')::int > 50"}, {"role": "user", "content": "Filter the results to only include items from games in the 'Fantasy' genre."}, {"role": "assistant", "content": "SELECT t1.item_id, t1.item_name, t1.rarity, t2.title, t1.attributes ->> 'mana_cost' AS mana_cost FROM gaming_technology.in_game_items AS t1 JOIN gaming_technology.games AS t2 ON t1.game_id = t2.game_id WHERE t1.attributes ? 'mana_cost' AND (t1.attributes ->> 'mana_cost')::int > 50 AND t2.genre = 'Fantasy'"}], "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 PRIMARY KEY, 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.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\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.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 )\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": "Show me all reservations with their guest IDs and room IDs where the total amount is greater than $500 and the status is 'Confirmed', ordered by check-in date."}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, room_id, check_in_date, total_amount FROM hospitality_technology.reservations WHERE total_amount > 500 AND status = 'Confirmed' ORDER BY check_in_date;"}, {"role": "user", "content": "Now, join this with the service_orders table to include the total price of all services ordered for each reservation."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount, SUM(so.total_price) AS total_service_price FROM hospitality_technology.reservations r LEFT JOIN hospitality_technology.service_orders so ON r.reservation_id = so.reservation_id WHERE r.total_amount > 500 AND r.status = 'Confirmed' GROUP BY r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount ORDER BY r.check_in_date;"}, {"role": "user", "content": "The query should also show the difference between the total amount and the base rate for each reservation."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount, SUM(so.total_price) AS total_service_price, (r.total_amount - rt.base_rate) AS rate_difference FROM hospitality_technology.reservations r LEFT JOIN hospitality_technology.service_orders so ON r.reservation_id = so.reservation_id LEFT JOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id WHERE r.total_amount > 500 AND r.status = 'Confirmed' GROUP BY r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount, rt.base_rate ORDER BY r.check_in_date;"}, {"role": "user", "content": "Actually, I only need reservations where the total amount is at least 50% higher than the base rate, and order them by check-in date."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount, SUM(so.total_price) AS total_service_price, (r.total_amount - rt.base_rate) AS rate_difference FROM hospitality_technology.reservations r LEFT JOIN hospitality_technology.service_orders so ON r.reservation_id = so.reservation_id LEFT JOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id WHERE r.total_amount > 500 AND r.status = 'Confirmed' AND r.total_amount >= rt.base_rate * 1.5 GROUP BY r.reservation_id, r.guest_id, r.room_id, r.check_in_date, r.total_amount, rt.base_rate ORDER BY r.check_in_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 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 (\n reservation_id character varying(64) NOT NULL, -- unique identifier for the booking\n property_id character varying(64) NOT NULL, -- FK to properties table\n guest_id character varying(64) NOT NULL, -- FK to guests table (primary guest)\n room_id character varying(64), -- FK to rooms table (assigned room, might be null initially)\n room_type_id character varying(64) NOT NULL, -- FK to room_types table (booked room type)\n check_in_date date NOT NULL, -- scheduled check-in date\n check_out_date date NOT NULL, -- scheduled check-out date\n actual_check_in_ts timestamp with time zone, -- actual check-in time\n actual_check_out_ts timestamp with time zone, -- actual check-out time\n num_adults integer NOT NULL, -- number of adults\n num_children integer DEFAULT 0, -- number of children\n status character varying(50) NOT NULL, -- e.g., Pending, Confirmed, CheckedIn, CheckedOut, Cancelled, NoShow\n booking_source character varying(100), -- e.g., Website, OTA (Expedia, Booking.com), Phone, WalkIn\n rate_plan_id character varying(64), -- FK to rate_plans table (optional)\n total_amount numeric(12, 2), -- estimated or final total cost\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n special_requests text, -- specific guest requests for this booking\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 (reservation_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\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)\nCREATE TABLE hospitality_technology.payments ( payment_id text PRIMARY KEY, 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 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": "List the claim_id and the total number of documents uploaded for each claim, but only include claims with between 3 and 7 documents."}, {"role": "assistant", "content": "SELECT claim_id, COUNT(*) AS document_count FROM insurance.claim_documents GROUP BY claim_id HAVING COUNT(*) BETWEEN 3 AND 7;"}, {"role": "user", "content": "Can you also show the upload time of the most recent document for each claim in this list?"}, {"role": "assistant", "content": "SELECT cd.claim_id, COUNT(*) AS document_count, MAX(cd.uploaded_at) AS latest_uploaded_at FROM insurance.claim_documents cd GROUP BY cd.claim_id HAVING COUNT(*) BETWEEN 3 AND 7;"}], "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.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": [{"role": "user", "content": "Show me the username and email of all users who own at least one wallet."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username, T1.email FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_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 blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )\nCREATE TABLE blockchain.users ( user_id.text, username.text, email.text, password_hash.text )\n"} {"conversations": [{"role": "user", "content": "Can you provide a breakdown of total and average account balance by account_type and currency for each account status?"}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance\nFROM financial_services.accounts\nGROUP BY account_type, currency, status;"}, {"role": "user", "content": "Could you include the minimum and maximum interest rate for each group as well?"}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance, MIN(interest_rate) AS min_interest_rate, MAX(interest_rate) AS max_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, currency, status;"}, {"role": "user", "content": "Only show groups where the total_accounts is greater than 20."}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance, MIN(interest_rate) AS min_interest_rate, MAX(interest_rate) AS max_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, currency, status\nHAVING COUNT(*) > 20;"}, {"role": "user", "content": "Please sort the results by average_balance in descending order."}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance, MIN(interest_rate) AS min_interest_rate, MAX(interest_rate) AS max_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, currency, status\nHAVING COUNT(*) > 20\nORDER BY average_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 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": [{"role": "user", "content": "List all fuel refueling events with the refueled vehicle's make and model, the fuel type used, and the fueling location ID."}, {"role": "assistant", "content": "SELECT fl.fuel_log_id, fl.log_timestamp, v.make, v.model, fl.fuel_type, fl.quantity, fl.unit, fl.total_cost, fl.location_id\nFROM transportation.fuel_logs fl\nJOIN transportation.vehicles v ON fl.vehicle_id = v.vehicle_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 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, 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.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 ( 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": "Find all chronic diagnoses made by Cardiology doctors in the last year, including patient ID, diagnosis description, and doctor's full name."}, {"role": "assistant", "content": "SELECT di.patient_id, di.description, d.first_name || ' ' || d.last_name AS doctor_name, di.diagnosis_date FROM healthcare.diagnoses di JOIN healthcare.doctors d ON di.doctor_id = d.doctor_id WHERE di.is_chronic = true AND d.specialty = 'Cardiology' AND di.diagnosis_date >= CURRENT_DATE - INTERVAL '1 year' ORDER BY di.diagnosis_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 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 ( 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.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\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) )\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 users who have created the most wallets, along with their email addresses and the creation date of their first wallet."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, MIN(w.created_at) AS first_wallet_date, COUNT(w.wallet_id) AS wallet_count FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id GROUP BY u.user_id, u.email ORDER BY wallet_count DESC LIMIT 5;"}, {"role": "user", "content": "Now modify the query to only include wallets created in the last 6 months."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, MIN(w.created_at) AS first_wallet_date, COUNT(w.wallet_id) AS wallet_count FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id WHERE w.created_at >= NOW() - INTERVAL '6 months' GROUP BY u.user_id, u.email ORDER BY wallet_count DESC LIMIT 5;"}, {"role": "user", "content": "Actually, I want to see the total balance across all wallets for each of these users, calculated from unspent UTXOs."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, MIN(w.created_at) AS first_wallet_date, COUNT(w.wallet_id) AS wallet_count, COALESCE(SUM(ut.amount), 0) AS total_balance FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id LEFT JOIN trading_platform.utxos ut ON w.address = ut.address AND ut.spent = false WHERE w.created_at >= NOW() - INTERVAL '6 months' GROUP BY u.user_id, u.email ORDER BY wallet_count 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 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.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.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 (\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)\n"} {"conversations": [{"role": "user", "content": "I want a list of all claims where at least one document is larger than 2 megabytes. Include the claim ID, incident date, and the file name of such documents."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152;"}, {"role": "user", "content": "Actually, please also show the document type and only include documents uploaded after June 1, 2024."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01';"}, {"role": "user", "content": "Add the file size in kilobytes and order the results by file size descending."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type, (d.file_size_bytes/1024) AS file_size_kb\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01'\nORDER BY d.file_size_bytes DESC;"}, {"role": "user", "content": "Sorry, I'm getting some records where file_size_bytes is NULL. Please exclude those from the results."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type, (d.file_size_bytes/1024) AS file_size_kb\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01'\n AND d.file_size_bytes IS NOT NULL\nORDER BY d.file_size_bytes 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.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.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 )\n"} {"conversations": [{"role": "user", "content": "How many customers are there for each status?"}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM financial_services.customers GROUP BY status"}, {"role": "user", "content": "Only show statuses where the count is greater than 50."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM financial_services.customers GROUP BY status HAVING COUNT(*) > 50"}, {"role": "user", "content": "Sort the results by the count in descending order."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM financial_services.customers GROUP BY status HAVING COUNT(*) > 50 ORDER BY 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.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 )\n"} {"conversations": [{"role": "user", "content": "Show me all hashtag IDs and their tag names that were created after June 10, 2024 and whose tag names contain the word 'dev'."}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name FROM social_media.hashtags WHERE created_at > '2024-06-10' AND tag_name ILIKE '%dev%';"}, {"role": "user", "content": "Can you also include the creation timestamp and order the results by created_at ascending?"}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name, created_at FROM social_media.hashtags WHERE created_at > '2024-06-10' AND tag_name ILIKE '%dev%' ORDER BY created_at ASC;"}, {"role": "user", "content": "Actually, only show hashtags where the tag name starts with the letter 'D'."}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name, created_at FROM social_media.hashtags WHERE created_at > '2024-06-10' AND tag_name ILIKE 'D%' ORDER BY created_at ASC;"}, {"role": "user", "content": "Limit the results to the top 8 hashtags."}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name, created_at FROM social_media.hashtags WHERE created_at > '2024-06-10' AND tag_name ILIKE 'D%' ORDER BY created_at ASC LIMIT 8;"}], "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.hashtags ( hashtag_id text, tag_name text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List all users who have deployed contracts, along with their email addresses and the count of contracts they've deployed."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(c.contract_id) AS contract_count FROM web3.users u JOIN web3.contracts c ON u.user_id = c.deployer_address GROUP BY u.user_id, u.email;"}, {"role": "user", "content": "Actually, I only want to see users who have deployed more than 3 contracts."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(c.contract_id) AS contract_count FROM web3.users u JOIN web3.contracts c ON u.user_id = c.deployer_address GROUP BY u.user_id, u.email HAVING COUNT(c.contract_id) > 3;"}, {"role": "user", "content": "There's an error in your SQL, it should be 'deployer_address' not 'user_id' in the JOIN condition."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(c.contract_id) AS contract_count FROM web3.users u JOIN web3.contracts c ON u.user_id = c.deployer_address GROUP BY u.user_id, u.email HAVING COUNT(c.contract_id) > 3;"}, {"role": "user", "content": "Now sort the results by contract_count in descending order."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(c.contract_id) AS contract_count FROM web3.users u JOIN web3.contracts c ON u.user_id = c.deployer_address GROUP BY u.user_id, u.email HAVING COUNT(c.contract_id) > 3 ORDER BY contract_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 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.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 )\nCREATE TABLE web3.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) )\n"} {"conversations": [{"role": "user", "content": "What is the average ROI for smart money addresses on the Ethereum chain with a realized profit ratio above 50%?"}, {"role": "assistant", "content": "SELECT AVG(roi) as average_roi\nFROM smart_money_token_performance\nWHERE chain = 'Ethereum'\nAND realized_ratio > 0.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.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )\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 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": [{"role": "user", "content": "List all agents who have been terminated, showing their full name, agency name, and termination date."}, {"role": "assistant", "content": "SELECT first_name, last_name, agency_name, termination_date\nFROM insurance.agents\nWHERE status <> 'Active';"}], "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 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": [{"role": "user", "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": "assistant", "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": "user", "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": "assistant", "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": "user", "content": "Add the last recorded price for each token, and sort by total_usd_value in descending order."}, {"role": "assistant", "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": "user", "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": "assistant", "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;"}], "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": [{"role": "user", "content": "What is the average ROI and average realized_ratio for each chain?"}, {"role": "assistant", "content": "SELECT chain,\n AVG(roi) AS avg_roi,\n AVG(realized_ratio) AS avg_realized_ratio\nFROM smart_money_token_performance\nGROUP BY chain;"}, {"role": "user", "content": "Now filter to only include chains where average ROI is above 0.5."}, {"role": "assistant", "content": "WITH stats AS (\n SELECT chain,\n AVG(roi) AS avg_roi,\n AVG(realized_ratio) AS avg_realized_ratio\n FROM smart_money_token_performance\n GROUP BY chain\n)\nSELECT chain, avg_roi, avg_realized_ratio\nFROM stats\nWHERE avg_roi > 0.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 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 )\n"} {"conversations": [{"role": "user", "content": "Can you help me retrieve the details of all bookings for a specific route with route_id 'RT789', including the passenger names and the scheduled departure times?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nWHERE s.route_id = 'RT789';"}, {"role": "user", "content": "Can you modify the query to include only bookings with a status of 'Pending'?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending';"}, {"role": "user", "content": "Can you also add the route name and origin station ID to the results?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price, r.route_name, r.origin_station_id\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nJOIN train_station_management.routes r ON s.route_id = r.route_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending';"}, {"role": "user", "content": "Can you sort the results by departure datetime in descending order?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price, r.route_name, r.origin_station_id\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nJOIN train_station_management.routes r ON s.route_id = r.route_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending'\nORDER BY s.departure_datetime DESC;"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars (\n car_id character varying(64) NOT NULL, -- Unique identifier for the train car\n train_id character varying(64) NOT NULL, -- Foreign key referencing trains\n car_number character varying(10) NOT NULL, -- Identifier of the car within the train set\n car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage\n class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars)\n capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars)\n features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom')\n PRIMARY KEY (car_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id)\n)\nCREATE TABLE train_station_management.routes (\n route_id character varying(64) NOT NULL, -- Unique identifier for the route\n route_name character varying(128) NOT NULL, -- Name of the route (e.g., 'Northeast Corridor')\n description text, -- Description of the route\n origin_station_id character varying(64) NOT NULL, -- Starting station\n destination_station_id character varying(64) NOT NULL, -- Final station\n is_active boolean NOT NULL DEFAULT true, -- Is the route currently operational?\n PRIMARY KEY (route_id),\n FOREIGN KEY (origin_station_id) REFERENCES train_station_management.stations(station_id),\n FOREIGN KEY (destination_station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.route_stations (\n route_station_id character varying(64) NOT NULL, -- Unique ID for this route-station link\n route_id character varying(64) NOT NULL, -- Foreign key referencing routes\n station_id character varying(64) NOT NULL, -- Foreign key referencing stations\n sequence_order integer NOT NULL, -- Order of the station in the route (1 for origin, 2, 3...)\n distance_from_previous_km numeric(10, 2), -- Distance from the previous station in the sequence\n typical_stop_duration_minutes integer, -- Typical dwell time at this station\n PRIMARY KEY (route_station_id),\n UNIQUE (route_id, station_id),\n UNIQUE (route_id, sequence_order),\n FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id),\n FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.schedules (\n schedule_id character varying(64) NOT NULL, -- Unique identifier for a specific scheduled trip\n train_id character varying(64) NOT NULL, -- Foreign key referencing the train used\n route_id character varying(64) NOT NULL, -- Foreign key referencing the route taken\n departure_datetime timestamp with time zone NOT NULL, -- Scheduled departure time from origin station\n arrival_datetime timestamp with time zone NOT NULL, -- Scheduled arrival time at destination station\n status character varying(32) NOT NULL DEFAULT 'Scheduled', -- e.g., Scheduled, On Time, Delayed, Cancelled, Arrived\n notes text, -- Any notes regarding this specific trip (e.g., reason for delay)\n PRIMARY KEY (schedule_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id),\n FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id)\n)\nCREATE TABLE train_station_management.passengers (\n passenger_id character varying(64) NOT NULL, -- Unique identifier for the passenger\n first_name character varying(100) NOT NULL, -- Passenger's first name\n last_name character varying(100) NOT NULL, -- Passenger's last name\n email character varying(128) UNIQUE, -- Passenger's email address\n phone_number character varying(32) UNIQUE, -- Passenger's phone number\n date_of_birth date, -- Passenger's date of birth\n loyalty_program_id character varying(64), -- ID for loyalty program, if applicable\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE train_station_management.bookings (\n booking_id character varying(64) NOT NULL, -- Unique identifier for the booking\n passenger_id character varying(64) NOT NULL, -- Foreign key referencing the passenger\n schedule_id character varying(64) NOT NULL, -- Foreign key referencing the scheduled trip\n booking_datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the booking was made\n status character varying(32) NOT NULL DEFAULT 'Confirmed', -- e.g., Confirmed, Cancelled, Pending\n total_price numeric(12, 2) NOT NULL, -- Total price for all tickets in this booking\n currency_code character varying(3) NOT NULL DEFAULT 'USD', -- Currency of the price\n special_requests text, -- Any special requests (e.g., wheelchair assistance)\n PRIMARY KEY (booking_id),\n FOREIGN KEY (passenger_id) REFERENCES train_station_management.passengers(passenger_id),\n FOREIGN KEY (schedule_id) REFERENCES train_station_management.schedules(schedule_id)\n)\nCREATE TABLE train_station_management.staff (\n staff_id character varying(64) NOT NULL, -- Unique identifier for the staff member\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n role character varying(64) NOT NULL, -- e.g., Station Master, Ticket Agent, Conductor, Engineer, Maintenance Crew\n primary_station_id character varying(64), -- Base station for the staff member (nullable for mobile staff)\n employee_number character varying(32) UNIQUE NOT NULL, -- Unique employee identifier\n hire_date date NOT NULL,\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n is_active boolean NOT NULL DEFAULT true, -- Is the staff member currently employed?\n PRIMARY KEY (staff_id),\n FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id)\n)\n"} {"conversations": [{"role": "user", "content": "What is the schedule of trains arriving at platform 1A at station XYZ on December 25th, 2023?"}, {"role": "assistant", "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."}], "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": [{"role": "user", "content": "Show me the top 5 narratives by market cap, along with their 24-hour trading volume and 7-day price change percentage."}, {"role": "assistant", "content": "SELECT narrative.text, volume_24h.numeric, price_change_percentage_7d.numeric FROM narrative_info ORDER BY market_cap.numeric DESC LIMIT 5;"}, {"role": "user", "content": "Can you also include the top 3 coins for each of these narratives?"}, {"role": "assistant", "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;"}], "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": [{"role": "user", "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": "assistant", "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);"}], "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": [{"role": "user", "content": "List pairs of citizens who share the same email domain."}, {"role": "assistant", "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;"}], "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": [{"role": "user", "content": "What is the history of incidents or accidents that occurred on platform 5 at station GHI?"}, {"role": "assistant", "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."}], "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": [{"role": "user", "content": "List all achievements with points greater than 100, showing achievement_id, name, and points."}, {"role": "assistant", "content": "SELECT achievement_id, name, points\nFROM gaming_technology.achievements\nWHERE points > 100;"}, {"role": "user", "content": "Filter further to only include visible achievements and also return the description."}, {"role": "assistant", "content": "SELECT achievement_id, name, description, points\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = FALSE;"}, {"role": "user", "content": "Now group by game_id to find how many such high-point visible achievements each game has."}, {"role": "assistant", "content": "SELECT game_id,\n COUNT(*) AS high_point_visible_count\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = FALSE\nGROUP BY game_id;"}, {"role": "user", "content": "Only include games with at least 2 of these achievements and order by that count descending."}, {"role": "assistant", "content": "SELECT game_id,\n COUNT(*) AS high_point_visible_count\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = FALSE\nGROUP BY game_id\nHAVING COUNT(*) >= 2\nORDER BY high_point_visible_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.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\n"} {"conversations": [{"role": "user", "content": "List all premium payments for policy 'POL123'. Show payment ID, payment date, amount paid, and status."}, {"role": "assistant", "content": "SELECT payment_id, payment_date, amount_paid, status FROM insurance.premium_payments WHERE policy_id = 'POL123';"}, {"role": "user", "content": "Only show payments made on or after January 1, 2024."}, {"role": "assistant", "content": "SELECT payment_id, payment_date, amount_paid, status FROM insurance.premium_payments WHERE policy_id = 'POL123' AND payment_date >= '2024-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 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)\n"} {"conversations": [{"role": "user", "content": "What is the ticket price for a journey on train number T4321?"}, {"role": "assistant", "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."}], "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": [{"role": "user", "content": "Show me the top 5 buyers by total trade volume (quantity * price) in the last 30 days, along with their trade count."}, {"role": "assistant", "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": "user", "content": "Now modify the query to also include the average trade price for each buyer."}, {"role": "assistant", "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": "user", "content": "Actually, I want to see the results for sellers instead of buyers, and include the distinct asset count they traded."}, {"role": "assistant", "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"}], "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": [{"role": "user", "content": "Show me the number of service orders placed for each service category."}, {"role": "assistant", "content": "SELECT s.category, COUNT(so.order_id) AS order_count\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.services s ON so.service_id = s.service_id\nGROUP BY s.category;"}, {"role": "user", "content": "Only include categories with more than 10 orders and order by order_count descending."}, {"role": "assistant", "content": "SELECT s.category, COUNT(so.order_id) AS order_count\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.services s ON so.service_id = s.service_id\nGROUP BY s.category\nHAVING COUNT(so.order_id) > 10\nORDER BY order_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.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 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.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\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.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": "How many messages in total have been sent that do not contain any media attachment?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS non_media_message_count\nFROM social_media.messages\nWHERE media_url IS NULL OR media_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 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 )\n"} {"conversations": [{"role": "user", "content": "How many medications does each manufacturer have?"}, {"role": "assistant", "content": "SELECT manufacturer, COUNT(*) AS med_count\nFROM healthcare.medications\nGROUP BY manufacturer;"}, {"role": "user", "content": "Only include manufacturers with more than 10 medications."}, {"role": "assistant", "content": "SELECT manufacturer, COUNT(*) AS med_count\nFROM healthcare.medications\nGROUP BY manufacturer\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 healthcare.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\n"} {"conversations": [{"role": "user", "content": "List all employees and their managers, showing the full name for both the employee and their manager."}, {"role": "assistant", "content": "SELECT e.first_name || ' ' || e.last_name AS employee_name, m.first_name || ' ' || m.last_name AS manager_name FROM financial_services.employees e LEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id;"}, {"role": "user", "content": "Filter this list to only include employees whose job title is 'Analyst'."}, {"role": "assistant", "content": "SELECT e.first_name || ' ' || e.last_name AS employee_name, m.first_name || ' ' || m.last_name AS manager_name FROM financial_services.employees e LEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id WHERE e.job_title = 'Analyst';"}], "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 character varying(64) NOT NULL, account_id character varying(64) NOT NULL, related_account_id character varying(64), transaction_type character varying(50) NOT NULL, amount numeric(19, 4) NOT NULL, currency character varying(3) NOT NULL, transaction_date timestamp NOT NULL, effective_date date NOT NULL, description text, status character varying(32) NOT NULL, reference_number character varying(128), PRIMARY KEY (transaction_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id) )\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.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )\n"} {"conversations": [{"role": "user", "content": "Get each user's ID, the count of wallets they own, and the total amount of their unspent UTXOs across all wallets."}, {"role": "assistant", "content": "SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.utxos u\n ON w.address = u.address\n AND u.spent = false\nGROUP BY w.user_id;"}, {"role": "user", "content": "Only include users who have more than one wallet."}, {"role": "assistant", "content": "SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.utxos u\n ON w.address = u.address\n AND u.spent = false\nGROUP BY w.user_id\nHAVING COUNT(DISTINCT w.wallet_id) > 1;"}, {"role": "user", "content": "Also include the date of the earliest wallet created by each user."}, {"role": "assistant", "content": "SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent,\n MIN(w.created_at) AS first_wallet_date\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.utxos u\n ON w.address = u.address\n AND u.spent = false\nGROUP BY w.user_id\nHAVING COUNT(DISTINCT w.wallet_id) > 1;"}, {"role": "user", "content": "Sort the results by total_unspent descending and limit to the top 10."}, {"role": "assistant", "content": "SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent,\n MIN(w.created_at) AS first_wallet_date\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.utxos u\n ON w.address = u.address\n AND u.spent = false\nGROUP BY w.user_id\nHAVING COUNT(DISTINCT w.wallet_id) > 1\nORDER BY total_unspent 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 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": [{"role": "user", "content": "Show the agent_id, first name, and last name for all agents who were hired before January 1, 2020."}, {"role": "assistant", "content": "SELECT agent_id, first_name, last_name FROM insurance.agents WHERE hire_date < '2020-01-01';"}, {"role": "user", "content": "Additionally, only include agents who have a commission rate greater than 0.05."}, {"role": "assistant", "content": "SELECT agent_id, first_name, last_name FROM insurance.agents WHERE hire_date < '2020-01-01' AND commission_rate > 0.05;"}], "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, 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": [{"role": "user", "content": "Show me the total fuel quantity and cost for each route, grouped by route number, only for trips that have associated fuel logs."}, {"role": "assistant", "content": "SELECT r.route_number, SUM(f.quantity) AS total_quantity, SUM(f.total_cost) AS total_cost\nFROM transportation.fuel_logs f\nJOIN transportation.routes r ON f.trip_id IS NOT NULL AND f.trip_id IN (\n SELECT DISTINCT trip_id FROM transportation.fuel_logs\n)\nJOIN transportation.bookings b ON f.trip_id = b.trip_id\nWHERE r.route_id = b.trip_id\nGROUP BY r.route_number;"}], "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 )\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.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n"} {"conversations": [{"role": "user", "content": "Find pairs of insurance plans that are offered by the same insurance provider. Show the provider name, and the names of the two plans."}, {"role": "assistant", "content": "SELECT p1.insurance_provider, p1.plan_name, p2.plan_name FROM healthcare.insurance_plans p1 JOIN healthcare.insurance_plans p2 ON p1.insurance_provider = p2.insurance_provider AND p1.plan_id < p2.plan_id ORDER BY p1.insurance_provider, p1.plan_name;"}, {"role": "user", "content": "Only show pairs where the provider name starts with 'B'."}, {"role": "assistant", "content": "SELECT p1.insurance_provider, p1.plan_name, p2.plan_name FROM healthcare.insurance_plans p1 JOIN healthcare.insurance_plans p2 ON p1.insurance_provider = p2.insurance_provider AND p1.plan_id < p2.plan_id WHERE p1.insurance_provider LIKE 'B%' ORDER BY p1.insurance_provider, p1.plan_name;"}, {"role": "user", "content": "Further filter to include only pairs where both plans have a website listed."}, {"role": "assistant", "content": "SELECT p1.insurance_provider, p1.plan_name, p2.plan_name FROM healthcare.insurance_plans p1 JOIN healthcare.insurance_plans p2 ON p1.insurance_provider = p2.insurance_provider AND p1.plan_id < p2.plan_id WHERE p1.insurance_provider LIKE 'B%' AND p1.website IS NOT NULL AND p2.website IS NOT NULL ORDER BY p1.insurance_provider, p1.plan_name;"}, {"role": "user", "content": "Also, include the plan type for both plans in the result."}, {"role": "assistant", "content": "SELECT p1.insurance_provider, p1.plan_name, p1.plan_type, p2.plan_name, p2.plan_type FROM healthcare.insurance_plans p1 JOIN healthcare.insurance_plans p2 ON p1.insurance_provider = p2.insurance_provider AND p1.plan_id < p2.plan_id WHERE p1.insurance_provider LIKE 'B%' AND p1.website IS NOT NULL AND p2.website IS NOT NULL ORDER BY p1.insurance_provider, p1.plan_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.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\n"} {"conversations": [{"role": "user", "content": "List all pairs of beneficiaries on the same policy, showing policy_id, beneficiary1_id, beneficiary1 first_name, beneficiary1 last_name, beneficiary2_id, beneficiary2 first_name, and beneficiary2 last_name."}, {"role": "assistant", "content": "SELECT b1.policy_id,\n b1.beneficiary_id AS beneficiary1_id,\n b1.first_name AS beneficiary1_first,\n b1.last_name AS beneficiary1_last,\n b2.beneficiary_id AS beneficiary2_id,\n b2.first_name AS beneficiary2_first,\n b2.last_name AS beneficiary2_last\nFROM insurance.policy_beneficiaries b1\nJOIN insurance.policy_beneficiaries b2\n ON b1.policy_id = b2.policy_id\n AND b1.beneficiary_id < b2.beneficiary_id;"}, {"role": "user", "content": "Actually, only include pairs where the first beneficiary’s relationship is 'Spouse'."}, {"role": "assistant", "content": "SELECT b1.policy_id,\n b1.beneficiary_id AS beneficiary1_id,\n b1.first_name AS beneficiary1_first,\n b1.last_name AS beneficiary1_last,\n b2.beneficiary_id AS beneficiary2_id,\n b2.first_name AS beneficiary2_first,\n b2.last_name AS beneficiary2_last\nFROM insurance.policy_beneficiaries b1\nJOIN insurance.policy_beneficiaries b2\n ON b1.policy_id = b2.policy_id\n AND b1.beneficiary_id < b2.beneficiary_id\nWHERE b1.relationship = 'Spouse';"}, {"role": "user", "content": "And also filter to only include cases where the spouse's percentage_share is above 25%."}, {"role": "assistant", "content": "SELECT b1.policy_id,\n b1.beneficiary_id AS beneficiary1_id,\n b1.first_name AS beneficiary1_first,\n b1.last_name AS beneficiary1_last,\n b2.beneficiary_id AS beneficiary2_id,\n b2.first_name AS beneficiary2_first,\n b2.last_name AS beneficiary2_last\nFROM insurance.policy_beneficiaries b1\nJOIN insurance.policy_beneficiaries b2\n ON b1.policy_id = b2.policy_id\n AND b1.beneficiary_id < b2.beneficiary_id\nWHERE b1.relationship = 'Spouse'\n AND b1.percentage_share > 25;"}], "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.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me all documents uploaded by lawyers from law firms located in 'New York'. Include the document name, upload timestamp, the first and last name of the uploading lawyer, and the firm name."}, {"role": "assistant", "content": "SELECT d.document_name, d.upload_timestamp, l.first_name AS lawyer_first_name, l.last_name AS lawyer_last_name, lf.firm_name FROM documents AS d JOIN lawyers AS l ON d.uploaded_by_lawyer_id = l.lawyer_id JOIN law_firms AS lf ON l.firm_id = lf.firm_id WHERE lf.address LIKE '%New York%';"}, {"role": "user", "content": "Okay, but only show documents where the document type is 'Contract'."}, {"role": "assistant", "content": "SELECT d.document_name, d.upload_timestamp, l.first_name AS lawyer_first_name, l.last_name AS lawyer_last_name, lf.firm_name FROM documents AS d JOIN lawyers AS l ON d.uploaded_by_lawyer_id = l.lawyer_id JOIN law_firms AS lf ON l.firm_id = lf.firm_id WHERE lf.address LIKE '%New York%' AND d.document_type = 'Contract';"}, {"role": "user", "content": "Also, sort the results by upload timestamp descending and include the document version."}, {"role": "assistant", "content": "SELECT d.document_name, d.upload_timestamp, d.version, l.first_name AS lawyer_first_name, l.last_name AS lawyer_last_name, lf.firm_name FROM documents AS d JOIN lawyers AS l ON d.uploaded_by_lawyer_id = l.lawyer_id JOIN law_firms AS lf ON l.firm_id = lf.firm_id WHERE lf.address LIKE '%New York%' AND d.document_type = 'Contract' ORDER BY d.upload_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 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": [{"role": "user", "content": "Show me all patients who have a primary insurance plan from 'Blue Cross', along with their insurance policy numbers and the plan types."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, pi.policy_number, ip.plan_type FROM healthcare.patients p JOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id JOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id WHERE ip.insurance_provider = 'Blue Cross' AND pi.is_primary = 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.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 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 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.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)\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": "What is the total amount of all payments recorded?"}, {"role": "assistant", "content": "SELECT SUM(amount) FROM government_services.payments;"}, {"role": "user", "content": "Now only include payments with status 'Completed'."}, {"role": "assistant", "content": "SELECT SUM(amount) FROM government_services.payments WHERE status = 'Completed';"}, {"role": "user", "content": "Also, only consider payments made in the year 2024."}, {"role": "assistant", "content": "SELECT SUM(amount) FROM government_services.payments WHERE status = 'Completed' AND EXTRACT(YEAR FROM payment_timestamp) = 2024;"}, {"role": "user", "content": "Group the results by payment method and show the total amount for each method for these completed 2024 payments."}, {"role": "assistant", "content": "SELECT payment_method, SUM(amount) FROM government_services.payments WHERE status = 'Completed' AND EXTRACT(YEAR FROM payment_timestamp) = 2024 GROUP BY payment_method;"}], "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.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.payments ( payment_id text PRIMARY KEY, 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.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 )\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 )\n"} {"conversations": [{"role": "user", "content": "List pairs of invoice numbers for the same case, including their issue dates."}, {"role": "assistant", "content": "SELECT T1.invoice_number AS invoice1_number, T2.invoice_number AS invoice2_number, T1.case_id, T1.issue_date AS invoice1_issue_date, T2.issue_date AS invoice2_issue_date FROM legal_services.invoices AS T1 JOIN legal_services.invoices AS T2 ON T1.case_id = T2.case_id AND T1.invoice_id <> T2.invoice_id WHERE T1.case_id IS NOT NULL ORDER BY T1.case_id, invoice1_issue_date, invoice2_issue_date"}, {"role": "user", "content": "Only show pairs where one invoice was issued before the other, and calculate the difference in days between their issue dates."}, {"role": "assistant", "content": "SELECT T1.invoice_number AS earlier_invoice_number, T2.invoice_number AS later_invoice_number, T1.case_id, T1.issue_date AS earlier_issue_date, T2.issue_date AS later_issue_date, DATE_PART('day', T2.issue_date - T1.issue_date) AS days_difference FROM legal_services.invoices AS T1 JOIN legal_services.invoices AS T2 ON T1.case_id = T2.case_id AND T1.invoice_id <> T2.invoice_id WHERE T1.issue_date < T2.issue_date AND T1.case_id IS NOT NULL ORDER BY T1.case_id, earlier_issue_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 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": [{"role": "user", "content": "I need to compare consecutive daily close_prices for each security to find when the close_price increased compared to the previous day."}, {"role": "assistant", "content": "SELECT a.security_id, b.data_timestamp AS prev_date, b.close_price AS prev_close, a.data_timestamp AS curr_date, a.close_price AS curr_close\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nWHERE a.close_price > b.close_price;"}, {"role": "user", "content": "Now, restrict this to only securities whose average volume over the past 30 days exceeds 1,000,000."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id, b.data_timestamp AS prev_date, b.close_price AS prev_close, a.data_timestamp AS curr_date, a.close_price AS curr_close\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE a.close_price > b.close_price;"}, {"role": "user", "content": "Also, only include those increases where the percentage change between days is greater than 2%."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id,\n b.data_timestamp AS prev_date,\n b.close_price AS prev_close,\n a.data_timestamp AS curr_date,\n a.close_price AS curr_close,\n ROUND((a.close_price - b.close_price) / b.close_price * 100, 2) AS pct_change\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE (a.close_price - b.close_price) / b.close_price * 100 > 2;"}, {"role": "user", "content": "Finally, add the adjusted_close_price for both current and previous days to the result."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id,\n b.data_timestamp AS prev_date,\n b.close_price AS prev_close,\n b.adjusted_close_price AS prev_adj_close,\n a.data_timestamp AS curr_date,\n a.close_price AS curr_close,\n a.adjusted_close_price AS curr_adj_close,\n ROUND((a.close_price - b.close_price) / b.close_price * 100, 2) AS pct_change\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE (a.close_price - b.close_price) / b.close_price * 100 > 2;"}], "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 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 )\n"} {"conversations": [{"role": "user", "content": "List each property along with the count of available rooms grouped by bed type."}, {"role": "assistant", "content": "SELECT rt.property_id, p.property_name, rt.bed_type, COUNT(r.room_id) AS available_count\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nJOIN hospitality_technology.properties p ON rt.property_id = p.property_id\nWHERE r.status = 'Available'\nGROUP BY rt.property_id, p.property_name, rt.bed_type;"}], "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 PRIMARY KEY, 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 PRIMARY KEY, property_id text, room_number text, room_type_id text, floor int, 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.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\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 text PRIMARY KEY, 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 )\n"} {"conversations": [{"role": "user", "content": "List the first and last names of employees and the full name of the citizens for whom they have scheduled appointments."}, {"role": "assistant", "content": "SELECT T1.first_name , T1.last_name , T3.first_name , T3.last_name FROM government_services.employees AS T1 JOIN government_services.appointments AS T2 ON T1.employee_id = T2.employee_id JOIN government_services.citizens AS T3 ON T2.citizen_id = T3.citizen_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.payments ( payment_id text PRIMARY KEY, 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 PRIMARY KEY, 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 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": "Show the latest version number of each document_name for every case."}, {"role": "assistant", "content": "SELECT case_id,\n document_name,\n MAX(version) AS latest_version\nFROM legal_services.documents\nGROUP BY case_id, document_name;"}, {"role": "user", "content": "Actually, I also need the upload_timestamp of that latest version."}, {"role": "assistant", "content": "SELECT d.case_id,\n d.document_name,\n d.version AS latest_version,\n d.upload_timestamp\nFROM legal_services.documents d\nJOIN (\n SELECT case_id,\n document_name,\n MAX(version) AS latest_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) sub\n ON d.case_id = sub.case_id\n AND d.document_name = sub.document_name\n AND d.version = sub.latest_version;"}, {"role": "user", "content": "Also include the uploaded_by_lawyer_id for each latest version."}, {"role": "assistant", "content": "SELECT d.case_id,\n d.document_name,\n d.version AS latest_version,\n d.upload_timestamp,\n d.uploaded_by_lawyer_id\nFROM legal_services.documents d\nJOIN (\n SELECT case_id,\n document_name,\n MAX(version) AS latest_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) sub\n ON d.case_id = sub.case_id\n AND d.document_name = sub.document_name\n AND d.version = sub.latest_version;"}], "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": [{"role": "user", "content": "For each chain, which token had the highest number of smart money addresses buying it this week? Show the token symbol and narrative too."}, {"role": "assistant", "content": "SELECT chain, token_symbol, narrative, MAX(address_amount) AS max_buyers FROM smart_money_token_inflow WHERE type = 1 AND DATE_TRUNC('week', CURRENT_DATE) = DATE_TRUNC('week', CURRENT_DATE) GROUP BY chain, token_symbol, narrative;"}, {"role": "user", "content": "I got an error, I think the filter for the week may be wrong. Please revise the query so that it only counts buys from the current week."}, {"role": "assistant", "content": "SELECT chain, token_symbol, narrative, address_amount AS buyers FROM smart_money_token_inflow WHERE type = 1 AND EXTRACT(week FROM CURRENT_DATE) = EXTRACT(week FROM CURRENT_DATE) AND EXTRACT(year FROM CURRENT_DATE) = EXTRACT(year FROM CURRENT_DATE) ORDER BY chain, buyers 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 smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n"} {"conversations": [{"role": "user", "content": "Can you show me each user's address and the date their wallet was created?"}, {"role": "assistant", "content": "SELECT user_id, address, created_at FROM trading_platform.wallets;"}, {"role": "user", "content": "Now, can you show only wallets created after '2024-01-01' and include the user_id and address?"}, {"role": "assistant", "content": "SELECT user_id, address, created_at FROM trading_platform.wallets WHERE created_at > '2024-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 trading_platform.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "How many unique tokens are recorded for each chain in the latest snapshot in cex_token_balance?"}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n)\nSELECT \n chain, \n COUNT(DISTINCT token_symbol) AS unique_token_count\nFROM cex_token_balance c\nJOIN latest_snapshot l ON c.snapshot_time = l.max_time\nGROUP BY chain\nORDER BY unique_token_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 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"} {"conversations": [{"role": "user", "content": "List all pairs of diagnoses that belong to the same medical record. Show record_id, diagnosis_id from the first entry as diag1_id, and diagnosis_id from the second entry as diag2_id."}, {"role": "assistant", "content": "SELECT d1.record_id,\n d1.diagnosis_id AS diag1_id,\n d2.diagnosis_id AS diag2_id\nFROM healthcare.diagnoses d1\nJOIN healthcare.diagnoses d2\n ON d1.record_id = d2.record_id\n AND d1.diagnosis_id < d2.diagnosis_id;"}, {"role": "user", "content": "Only include pairs where both diagnoses are chronic."}, {"role": "assistant", "content": "SELECT d1.record_id,\n d1.diagnosis_id AS diag1_id,\n d2.diagnosis_id AS diag2_id\nFROM healthcare.diagnoses d1\nJOIN healthcare.diagnoses d2\n ON d1.record_id = d2.record_id\n AND d1.diagnosis_id < d2.diagnosis_id\nWHERE d1.is_chronic = TRUE\n AND d2.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.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)\n"} {"conversations": [{"role": "user", "content": "Could you list all pairs of developers that are based in the same country and share the same website domain?"}, {"role": "assistant", "content": "SELECT\n d1.name AS developer1_name,\n d2.name AS developer2_name,\n d1.country,\n d1.website\nFROM\n gaming_technology.developers AS d1\nJOIN\n gaming_technology.developers AS d2 ON d1.country = d2.country\n AND d1.website = d2.website\n AND d1.developer_id < d2.developer_id\nWHERE\n d1.country IS NOT NULL\n AND d1.website IS NOT NULL AND d1.website != '';"}], "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 (\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)\n"} {"conversations": [{"role": "user", "content": "List all SUI NFT objects with the status 'exists', showing the object_id, name, and owner."}, {"role": "assistant", "content": "SELECT object_id, name, owner\nFROM sui_nfts\nWHERE status = 'exists';"}, {"role": "user", "content": "Can you also add the collection_type and package_id for each NFT?"}, {"role": "assistant", "content": "SELECT object_id, name, owner, collection_type, package_id\nFROM sui_nfts\nWHERE status = 'exists';"}, {"role": "user", "content": "Only include NFTs where the collection_type contains the word 'Genesis'."}, {"role": "assistant", "content": "SELECT object_id, name, owner, collection_type, package_id\nFROM sui_nfts\nWHERE status = 'exists' AND collection_type LIKE '%Genesis%';"}, {"role": "user", "content": "Also show the display metadata for these NFTs and sort the result by name ascending."}, {"role": "assistant", "content": "SELECT object_id, name, owner, collection_type, package_id, display\nFROM sui_nfts\nWHERE status = 'exists' AND collection_type LIKE '%Genesis%'\nORDER BY 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 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 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 sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\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 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_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)\n"} {"conversations": [{"role": "user", "content": "I need to find all components associated with a specific supplier. Can you help with that?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE"}, {"role": "user", "content": "Can you also show me the material ID for each of these components?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id"}, {"role": "user", "content": "What if I want to exclude components with a specific material ID?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id\nIF HGET component: material_id != 'mat:TI64' THEN INCLUDE"}, {"role": "user", "content": "Can you add the component name to the result as well?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id\nIF HGET component: material_id != 'mat:TI64' THEN INCLUDE\nHGET component: component_name"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": [{"role": "user", "content": "Could you list each game title along with its developer's name and the total number of servers hosting it?"}, {"role": "assistant", "content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nLEFT JOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nLEFT JOIN gaming_technology.servers s ON g.game_id = s.game_id\nGROUP BY g.title, d.name;"}, {"role": "user", "content": "Actually, please include only servers with status = 'online' and exclude games with zero online servers."}, {"role": "assistant", "content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nJOIN gaming_technology.servers s ON g.game_id = s.game_id\nWHERE s.status = 'online'\nGROUP BY g.title, d.name;"}, {"role": "user", "content": "I want to see only developers based in 'USA'."}, {"role": "assistant", "content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nJOIN gaming_technology.servers s ON g.game_id = s.game_id AND s.status = 'online'\nWHERE d.country = 'USA'\nGROUP BY g.title, d.name;"}, {"role": "user", "content": "Finally, sort the results by server_count in descending order."}, {"role": "assistant", "content": "SELECT g.title, d.name AS developer_name, COUNT(s.server_id) AS server_count\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nJOIN gaming_technology.servers s ON g.game_id = s.game_id AND s.status = 'online'\nWHERE d.country = 'USA'\nGROUP BY g.title, d.name\nORDER BY server_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 ( 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.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\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 timestamp with time zone )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid, player_id uuid, item_id uuid, quantity integer, acquired_at timestamp with time zone, instance_data jsonb )\n"} {"conversations": [{"role": "user", "content": "For each patient, find the next appointment after each one. Return patient_id, appointment_id, next_appointment_id, and the waiting time in minutes between them."}, {"role": "assistant", "content": "SELECT A.patient_id,\n A.appointment_id AS current_id,\n B.appointment_id AS next_id,\n EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 AS wait_minutes\nFROM healthcare.appointments A\nJOIN healthcare.appointments B\n ON A.patient_id = B.patient_id\n AND B.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = A.patient_id\n AND appointment_time > A.appointment_time\n );"}, {"role": "user", "content": "Now include only the pairs where the waiting time is less than 30 minutes."}, {"role": "assistant", "content": "SELECT A.patient_id,\n A.appointment_id AS current_id,\n B.appointment_id AS next_id,\n EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 AS wait_minutes\nFROM healthcare.appointments A\nJOIN healthcare.appointments B\n ON A.patient_id = B.patient_id\n AND B.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = A.patient_id\n AND appointment_time > A.appointment_time\n )\nWHERE EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 < 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.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": "Show me the top 3 tokens by USD value inflow where smart money was buying (type = 1), along with their token symbol and narrative."}, {"role": "assistant", "content": "SELECT token_symbol, narrative, usd_value FROM smart_money_token_inflow WHERE type = 1 ORDER BY usd_value DESC LIMIT 3;"}, {"role": "user", "content": "Actually, I want to see tokens with a USD value over $100,000."}, {"role": "assistant", "content": "SELECT token_symbol, narrative, usd_value FROM smart_money_token_inflow WHERE type = 1 AND usd_value > 100000 ORDER BY usd_value DESC LIMIT 3;"}, {"role": "user", "content": "Can you filter these results to only include tokens from the Ethereum chain?"}, {"role": "assistant", "content": "SELECT token_symbol, narrative, usd_value FROM smart_money_token_inflow WHERE type = 1 AND usd_value > 100000 AND chain = 'Ethereum' ORDER BY usd_value DESC LIMIT 3;"}, {"role": "user", "content": "Now include the 24-hour trading volume for these tokens from the token_dexpool_info table."}, {"role": "assistant", "content": "SELECT smti.token_symbol, smti.narrative, smti.usd_value, tdi.volume_24h FROM smart_money_token_inflow smti LEFT JOIN token_dexpool_info tdi ON smti.token_symbol = tdi.token_symbol AND smti.chain = tdi.chain WHERE smti.type = 1 AND smti.usd_value > 100000 AND smti.chain = 'Ethereum' ORDER BY smti.usd_value 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\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 token_dexpool_info (\",\n \"pair_address character varying(512) NOT NULL, -- the id of dexpool\",\n \"token_name character varying(100) NOT NULL, -- the name of the token in the dexpool\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"chain text, -- the chain that the dexpool 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_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours\",\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 \"makers_24h double precision, -- the makers of the dex pool in 24 hours\",\n \"volume_24h double precision, -- the trade volume of the dex pool in 24 hours\",\n \"liquidity double precision, -- the liquidity of the dex pool\",\n \"market_cap double precision, -- the market cap of the token\",\n \"trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (pair_address, chain);\"\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": "For each guest, calculate their total spending on delivered service orders and the total number of those orders."}, {"role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.total_price) AS total_spent,\n COUNT(*) AS total_orders\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.status = 'delivered'\nGROUP BY g.guest_id, full_name;"}, {"role": "user", "content": "I need the breakdown by month for the current year. Show guest ID, month, total spent, and total orders."}, {"role": "assistant", "content": "SELECT so.guest_id,\n DATE_TRUNC('month', so.delivery_timestamp) AS month,\n SUM(so.total_price) AS total_spent,\n COUNT(*) AS total_orders\nFROM hospitality_technology.service_orders so\nWHERE so.status = 'delivered'\n AND so.delivery_timestamp >= '2024-01-01'\n AND so.delivery_timestamp < '2025-01-01'\nGROUP BY so.guest_id, month\nORDER BY month;"}, {"role": "user", "content": "Also include the guest’s email and only show months where total spent is greater than 500."}, {"role": "assistant", "content": "SELECT sub.guest_id,\n g.email,\n sub.month,\n sub.total_spent,\n sub.total_orders\nFROM (\n SELECT so.guest_id,\n DATE_TRUNC('month', so.delivery_timestamp) AS month,\n SUM(so.total_price) AS total_spent,\n COUNT(*) AS total_orders\n FROM hospitality_technology.service_orders so\n WHERE so.status = 'delivered'\n AND so.delivery_timestamp >= '2024-01-01'\n AND so.delivery_timestamp < '2025-01-01'\n GROUP BY so.guest_id, month\n) sub\nJOIN hospitality_technology.guests g\n ON sub.guest_id = g.guest_id\nWHERE sub.total_spent > 500\nORDER BY sub.month;"}], "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": [{"role": "user", "content": "List payment records in USD including guest names and processing staff names."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.amount,\n p.currency_code,\n g.guest_name,\n s.staff_name\nFROM hospitality_technology.payments p\nJOIN hospitality_technology.guests g ON p.guest_id = g.guest_id\nJOIN hospitality_technology.staff s ON p.staff_id_processed = s.staff_id\nWHERE p.currency_code = 'USD';"}, {"role": "user", "content": "Only include payments with status 'Succeeded' made within the last 30 days."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.amount,\n p.currency_code,\n g.guest_name,\n s.staff_name\nFROM hospitality_technology.payments p\nJOIN hospitality_technology.guests g ON p.guest_id = g.guest_id\nJOIN hospitality_technology.staff s ON p.staff_id_processed = s.staff_id\nWHERE p.currency_code = 'USD'\n AND p.status = 'Succeeded'\n AND p.payment_timestamp >= NOW() - INTERVAL '30 days';"}, {"role": "user", "content": "Sort by payment timestamp descending and limit to 50 records."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.amount,\n p.currency_code,\n g.guest_name,\n s.staff_name\nFROM hospitality_technology.payments p\nJOIN hospitality_technology.guests g ON p.guest_id = g.guest_id\nJOIN hospitality_technology.staff s ON p.staff_id_processed = s.staff_id\nWHERE p.currency_code = 'USD'\n AND p.status = 'Succeeded'\n AND p.payment_timestamp >= NOW() - INTERVAL '30 days'\nORDER BY p.payment_timestamp DESC\nLIMIT 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 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)\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)\n"} {"conversations": [{"role": "user", "content": "Count the number of unique locations specified in the users table."}, {"role": "assistant", "content": "SELECT count(DISTINCT location) FROM social_media.users WHERE location IS NOT 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 ( 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.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 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.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 )\n"} {"conversations": [{"role": "user", "content": "For each user with 'approved' KYC status, show their user ID and the total amount in their unspent UTXOs."}, {"role": "assistant", "content": "SELECT T1.user_id, SUM(T2.amount) FROM trading_platform.kyc_audit AS T1 JOIN trading_platform.utxos AS T2 ON T1.user_id = T2.user_id WHERE T1.status = 'approved' AND T2.spent = false GROUP BY T1.user_id;"}, {"role": "user", "content": "Only include users where the total unspent amount is greater than 100."}, {"role": "assistant", "content": "SELECT T1.user_id, SUM(T2.amount) FROM trading_platform.kyc_audit AS T1 JOIN trading_platform.utxos AS T2 ON T1.user_id = T2.user_id WHERE T1.status = 'approved' AND T2.spent = false GROUP BY T1.user_id HAVING SUM(T2.amount) > 100;"}], "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 ( 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 )\n"} {"conversations": [{"role": "user", "content": "List all NFT collections where the floor price is greater than 0.5 ETH, including their names and contract addresses."}, {"role": "assistant", "content": "SELECT name, contract_address FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH';"}, {"role": "user", "content": "Can you also include the banner image URL and filter to only show ERC721 collections?"}, {"role": "assistant", "content": "SELECT name, contract_address, banner_image_url FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721';"}, {"role": "user", "content": "Now sort these results by floor price in descending order and limit to the top 10."}, {"role": "assistant", "content": "SELECT name, contract_address, banner_image_url, floor_price FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721' ORDER BY CAST(floor_price AS decimal) 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 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 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 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.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 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.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 (\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 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_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\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 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, 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 the total number of sessions and the total duration in seconds for each server, including the server name and the game title."}, {"role": "assistant", "content": "SELECT\n s.server_name,\n g.game_title,\n COUNT(gs.session_id) AS total_sessions,\n SUM(gs.duration_seconds) AS total_duration_seconds\nFROM gaming_technology.game_sessions AS gs\nJOIN gaming_technology.servers AS s\n ON gs.server_id = s.server_id\nJOIN gaming_technology.games AS g\n ON gs.game_id = g.game_id\nGROUP BY\n s.server_id,\n s.server_name,\n g.game_title;"}, {"role": "user", "content": "Actually, I got an error that the table 'games' does not exist. Can you provide the same information but without using the 'games' table? Just show the server name and its game_id."}, {"role": "assistant", "content": "SELECT\n s.server_name,\n s.game_id,\n COUNT(gs.session_id) AS total_sessions,\n SUM(gs.duration_seconds) AS total_duration_seconds\nFROM gaming_technology.game_sessions AS gs\nJOIN gaming_technology.servers AS s\n ON gs.server_id = s.server_id\nGROUP BY\n s.server_id,\n s.server_name,\n s.game_id;"}, {"role": "user", "content": "Only include servers where the total session duration is greater than 1 day (86400 seconds)."}, {"role": "assistant", "content": "SELECT\n s.server_name,\n s.game_id,\n COUNT(gs.session_id) AS total_sessions,\n SUM(gs.duration_seconds) AS total_duration_seconds\nFROM gaming_technology.game_sessions AS gs\nJOIN gaming_technology.servers AS s\n ON gs.server_id = s.server_id\nGROUP BY\n s.server_id,\n s.server_name,\n s.game_id\nHAVING\n SUM(gs.duration_seconds) > 86400;"}, {"role": "user", "content": "Order the results by total session duration in descending order."}, {"role": "assistant", "content": "SELECT\n s.server_name,\n s.game_id,\n COUNT(gs.session_id) AS total_sessions,\n SUM(gs.duration_seconds) AS total_duration_seconds\nFROM gaming_technology.game_sessions AS gs\nJOIN gaming_technology.servers AS s\n ON gs.server_id = s.server_id\nGROUP BY\n s.server_id,\n s.server_name,\n s.game_id\nHAVING\n SUM(gs.duration_seconds) > 86400\nORDER BY\n total_duration_seconds 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.game_sessions ( session_id.uuid, player_id.uuid, game_id.uuid, server_id.uuid, start_time.timestamptz, end_time.timestamptz, duration_seconds.integer, score.integer, session_data.jsonb )\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 )\n"} {"conversations": [{"role": "user", "content": "Show me each loyalty program ID along with the full names of all passengers enrolled in that program."}, {"role": "assistant", "content": "SELECT loyalty_program_id, first_name, last_name FROM transportation.passengers WHERE loyalty_program_id IS NOT NULL ORDER BY loyalty_program_id, last_name, first_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 transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\n"} {"conversations": [{"role": "user", "content": "What are the fuel consumption rates per hour for the Boeing 747-8 model?"}, {"role": "assistant", "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."}], "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": [{"role": "user", "content": "Show me all patients who have both primary and non-primary insurance plans, along with their policy numbers and expiration dates."}, {"role": "assistant", "content": "SELECT p1.patient_id, p1.policy_number AS primary_policy, p1.expiration_date AS primary_expiry, p2.policy_number AS non_primary_policy, p2.expiration_date AS non_primary_expiry FROM healthcare.patient_insurance p1 JOIN healthcare.patient_insurance p2 ON p1.patient_id = p2.patient_id WHERE p1.is_primary = true AND p2.is_primary = 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 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": "What is the total market cap for all tokens listed on the 'Polygon' chain?"}, {"role": "assistant", "content": "SELECT SUM(market_cap) FROM token_dexpool_info WHERE chain = 'Polygon';"}, {"role": "user", "content": "Only sum the market cap for tokens on 'Polygon' that have a 24-hour volume greater than 500000."}, {"role": "assistant", "content": "SELECT SUM(market_cap) FROM token_dexpool_info WHERE chain = 'Polygon' AND volume_24h > 500000;"}, {"role": "user", "content": "Also show the number of unique tokens that meet these criteria."}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT token_symbol), SUM(market_cap) FROM token_dexpool_info WHERE chain = 'Polygon' AND volume_24h > 500000;"}, {"role": "user", "content": "Can you show the total market cap and token count for *each* chain that meets these volume criteria, ordered by total market cap descending?"}, {"role": "assistant", "content": "SELECT chain, COUNT(DISTINCT token_symbol) AS token_count, SUM(market_cap) AS total_market_cap FROM token_dexpool_info WHERE volume_24h > 500000 GROUP BY chain ORDER BY total_market_cap 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_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": [{"role": "user", "content": "Calculate the average length of stay in days for completed reservations for each property."}, {"role": "assistant", "content": "SELECT p.property_id,\n p.property_name,\n AVG(res.check_out_date - res.check_in_date) AS avg_stay_days\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.properties p ON res.property_id = p.property_id\nWHERE res.status = 'Completed'\nGROUP BY p.property_id, p.property_name;"}, {"role": "user", "content": "Limit the results to properties where the average stay is more than 3 days."}, {"role": "assistant", "content": "SELECT p.property_id,\n p.property_name,\n AVG(res.check_out_date - res.check_in_date) AS avg_stay_days\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.properties p ON res.property_id = p.property_id\nWHERE res.status = 'Completed'\nGROUP BY p.property_id, p.property_name\nHAVING AVG(res.check_out_date - res.check_in_date) > 3;"}, {"role": "user", "content": "Also include the total number of completed reservations per property alongside the average length of stay."}, {"role": "assistant", "content": "SELECT p.property_id,\n p.property_name,\n COUNT(res.reservation_id) AS total_reservations,\n AVG(res.check_out_date - res.check_in_date) AS avg_stay_days\nFROM hospitality_technology.reservations res\nJOIN hospitality_technology.properties p ON res.property_id = p.property_id\nWHERE res.status = 'Completed'\nGROUP BY p.property_id, p.property_name\nHAVING AVG(res.check_out_date - res.check_in_date) > 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 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 (\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 ( 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 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 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.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\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 )\n"} {"conversations": [{"role": "user", "content": "Get the usernames of users who have created any public posts, and count how many public posts each user has made. Order the results by the post count in descending order."}, {"role": "assistant", "content": "SELECT u.username, COUNT(p.post_id) AS public_post_count FROM social_media.users u JOIN posts p ON u.user_id = p.user_id WHERE p.visibility = 'public' GROUP BY u.username ORDER BY public_post_count DESC;"}, {"role": "user", "content": "Actually, only include users who have posted more than 5 public posts."}, {"role": "assistant", "content": "SELECT u.username, COUNT(p.post_id) AS public_post_count FROM social_media.users u JOIN posts p ON u.user_id = p.user_id WHERE p.visibility = 'public' GROUP BY u.username HAVING COUNT(p.post_id) > 5 ORDER BY public_post_count DESC;"}, {"role": "user", "content": "Limit the result to the top 10 users by public post count."}, {"role": "assistant", "content": "SELECT u.username, COUNT(p.post_id) AS public_post_count FROM social_media.users u JOIN posts p ON u.user_id = p.user_id WHERE p.visibility = 'public' GROUP BY u.username HAVING COUNT(p.post_id) > 5 ORDER BY public_post_count DESC LIMIT 10;"}, {"role": "user", "content": "Can you also include their email address?"}, {"role": "assistant", "content": "SELECT u.username, u.email, COUNT(p.post_id) AS public_post_count FROM social_media.users u JOIN posts p ON u.user_id = p.user_id WHERE p.visibility = 'public' GROUP BY u.username, u.email HAVING COUNT(p.post_id) > 5 ORDER BY public_post_count 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 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)\n"} {"conversations": [{"role": "user", "content": "For each country code, what is the earliest registration date of a player?"}, {"role": "assistant", "content": "SELECT country_code, MIN(registration_date) AS earliest_reg_date FROM gaming_technology.players GROUP BY country_code;"}, {"role": "user", "content": "Only list countries where the earliest registration occurred before January 1st, 2020."}, {"role": "assistant", "content": "SELECT country_code, MIN(registration_date) AS earliest_reg_date FROM gaming_technology.players GROUP BY country_code HAVING MIN(registration_date) < '2020-01-01';"}, {"role": "user", "content": "Also include the total count of players for each of these countries."}, {"role": "assistant", "content": "SELECT country_code, MIN(registration_date) AS earliest_reg_date, COUNT(player_id) AS total_players FROM gaming_technology.players GROUP BY country_code HAVING MIN(registration_date) < '2020-01-01';"}, {"role": "user", "content": "Sort the results by the earliest registration date in ascending order."}, {"role": "assistant", "content": "SELECT country_code, MIN(registration_date) AS earliest_reg_date, COUNT(player_id) AS total_players FROM gaming_technology.players GROUP BY country_code HAVING MIN(registration_date) < '2020-01-01' ORDER BY earliest_reg_date 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 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 )\n"} {"conversations": [{"role": "user", "content": "Show me the total traded volume and the average price per security for trades executed last month."}, {"role": "assistant", "content": "SELECT s.ticker_symbol,\n SUM(t.quantity) AS total_volume,\n AVG(t.price_per_unit) AS avg_price\nFROM financial_services.trades t\nJOIN financial_services.securities s ON t.security_id = s.security_id\nWHERE t.trade_timestamp >= date_trunc('month', CURRENT_DATE - INTERVAL '1 month')\n AND t.trade_timestamp < date_trunc('month', CURRENT_DATE)\nGROUP BY s.ticker_symbol;"}, {"role": "user", "content": "Filter to only include those trades with status 'SETTLED' and execution_venue 'NYSE'."}, {"role": "assistant", "content": "SELECT s.ticker_symbol,\n SUM(t.quantity) AS total_volume,\n AVG(t.price_per_unit) AS avg_price\nFROM financial_services.trades t\nJOIN financial_services.securities s ON t.security_id = s.security_id\nWHERE t.trade_timestamp >= date_trunc('month', CURRENT_DATE - INTERVAL '1 month')\n AND t.trade_timestamp < date_trunc('month', CURRENT_DATE)\n AND t.status = 'SETTLED'\n AND t.execution_venue = 'NYSE'\nGROUP BY s.ticker_symbol;"}, {"role": "user", "content": "Now exclude any securities where the summed quantity is less than 1000."}, {"role": "assistant", "content": "SELECT s.ticker_symbol,\n SUM(t.quantity) AS total_volume,\n AVG(t.price_per_unit) AS avg_price\nFROM financial_services.trades t\nJOIN financial_services.securities s ON t.security_id = s.security_id\nWHERE t.trade_timestamp >= date_trunc('month', CURRENT_DATE - INTERVAL '1 month')\n AND t.trade_timestamp < date_trunc('month', CURRENT_DATE)\n AND t.status = 'SETTLED'\n AND t.execution_venue = 'NYSE'\nGROUP BY s.ticker_symbol\nHAVING SUM(t.quantity) >= 1000;"}], "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 PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\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 (\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)\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 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": [{"role": "user", "content": "Show me the wallet addresses holding the ERC20 token with contract address '0xabcdeffedcba9876543210abcdefedcba9876'. Include the amount they hold."}, {"role": "assistant", "content": "SELECT wallet_address, amount FROM erc20_balances WHERE contract_address = '0xabcdeffedcba9876543210abcdefedcba9876';"}, {"role": "user", "content": "Instead of contract address, can you do this for a token symbol like 'USDC'?"}, {"role": "assistant", "content": "SELECT eb.wallet_address, eb.amount FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address WHERE tm.symbol = 'USDC' AND tm.is_erc20 = 1;"}, {"role": "user", "content": "Filter the results to only show wallets holding more than 1000 of this token."}, {"role": "assistant", "content": "SELECT eb.wallet_address, eb.amount FROM erc20_balances eb JOIN token_metas tm ON eb.contract_address = tm.contract_address WHERE tm.symbol = 'USDC' AND tm.is_erc20 = 1 AND CAST(eb.amount AS DECIMAL) > 1000;"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 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_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\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_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_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 all beneficiaries with a percentage_share greater than 30%, showing beneficiary_id, first_name, last_name, relationship, percentage_share, and policy_id."}, {"role": "assistant", "content": "SELECT beneficiary_id,\n first_name,\n last_name,\n relationship,\n percentage_share,\n policy_id\nFROM insurance.policy_beneficiaries\nWHERE percentage_share > 30;"}, {"role": "user", "content": "Only include beneficiaries of policies that are currently active and add the policy status to the results."}, {"role": "assistant", "content": "SELECT pb.beneficiary_id,\n pb.first_name,\n pb.last_name,\n pb.relationship,\n pb.percentage_share,\n pb.policy_id,\n p.status AS policy_status\nFROM insurance.policy_beneficiaries pb\nJOIN insurance.policies p ON pb.policy_id = p.policy_id\nWHERE pb.percentage_share > 30\n AND p.status = 'Active';"}, {"role": "user", "content": "Also include the policy_number and order the results by percentage_share descending."}, {"role": "assistant", "content": "SELECT pb.beneficiary_id,\n pb.first_name,\n pb.last_name,\n pb.relationship,\n pb.percentage_share,\n pb.policy_id,\n p.status AS policy_status,\n p.policy_number\nFROM insurance.policy_beneficiaries pb\nJOIN insurance.policies p ON pb.policy_id = p.policy_id\nWHERE pb.percentage_share > 30\n AND p.status = 'Active'\nORDER BY pb.percentage_share DESC;"}, {"role": "user", "content": "Limit the output to the top 10 beneficiaries."}, {"role": "assistant", "content": "SELECT pb.beneficiary_id,\n pb.first_name,\n pb.last_name,\n pb.relationship,\n pb.percentage_share,\n pb.policy_id,\n p.status AS policy_status,\n p.policy_number\nFROM insurance.policy_beneficiaries pb\nJOIN insurance.policies p ON pb.policy_id = p.policy_id\nWHERE pb.percentage_share > 30\n AND p.status = 'Active'\nORDER BY pb.percentage_share 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.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.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.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show the total transaction amount for each customer, including their full name and risk profile. Join customers to accounts and then to transactions."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile;"}, {"role": "user", "content": "Filter this report to only include transactions from the last 90 days."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile;"}, {"role": "user", "content": "Also, only include customers whose total transaction amount in this period exceeds 1000."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile\nHAVING\n SUM(T1.amount) > 1000;"}, {"role": "user", "content": "Sort the results by total transaction amount in descending order and limit to the top 10 customers."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile\nHAVING\n SUM(T1.amount) > 1000\nORDER BY\n total_transaction_amount 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 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.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.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 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)\n"} {"conversations": [{"role": "user", "content": "What is the average trade price for each asset for trades executed between '2024-05-01' and '2024-05-31'?"}, {"role": "assistant", "content": "SELECT\n asset_id,\n AVG(price) AS avg_price\nFROM trading_platform.trades\nWHERE traded_at >= '2024-05-01' AND traded_at < '2024-06-01'\nGROUP BY asset_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 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)\n"} {"conversations": [{"role": "user", "content": "For each player, list the total number of 'Legendary' rarity items they have in their inventory, along with the titles of the respective games those items belong to."}, {"role": "assistant", "content": "SELECT pi.player_id, g.game_id, g.title, COUNT(*) AS legendary_item_count\nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE i.rarity = 'Legendary'\nGROUP BY pi.player_id, g.game_id, g.title;"}, {"role": "user", "content": "Please modify the query to only include players who have more than 2 'Legendary' items per game."}, {"role": "assistant", "content": "SELECT pi.player_id, g.game_id, g.title, COUNT(*) AS legendary_item_count\nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE i.rarity = 'Legendary'\nGROUP BY pi.player_id, g.game_id, g.title\nHAVING COUNT(*) > 2;"}], "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.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\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.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 ( item_id uuid, 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": "For each event recorded, list its ID, name, and the status and value of the transaction in which it occurred."}, {"role": "assistant", "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;"}], "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": [{"role": "user", "content": "List all reservations where the number of adults is greater than 2, showing reservation_id, guest_id, and the total_amount."}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, total_amount\nFROM hospitality_technology.reservations\nWHERE num_adults > 2;"}, {"role": "user", "content": "Can you also include the room_type_id and the status for each reservation?"}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, room_type_id, status, total_amount\nFROM hospitality_technology.reservations\nWHERE num_adults > 2;"}], "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.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": "List all pairs of achievements in the same game where the difference in their points is greater than 50."}, {"role": "assistant", "content": "SELECT a1.game_id,\n a1.name AS achv1,\n a2.name AS achv2,\n ABS(a1.points - a2.points) AS point_diff\nFROM gaming_technology.achievements a1\nJOIN gaming_technology.achievements a2\n ON a1.game_id = a2.game_id\n WHERE ABS(a1.points - a2.points) > 50;"}, {"role": "user", "content": "Can you ensure each pair appears only once with achv1 having fewer points than achv2?"}, {"role": "assistant", "content": "SELECT a1.game_id,\n a1.name AS achv1,\n a2.name AS achv2,\n (a2.points - a1.points) AS point_diff\nFROM gaming_technology.achievements a1\nJOIN gaming_technology.achievements a2\n ON a1.game_id = a2.game_id\n AND a1.points < a2.points\nWHERE (a2.points - a1.points) > 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 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.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.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": "Show me all log entries for user ID 'user123'."}, {"role": "assistant", "content": "SELECT log_id, user_id, action, details, logged_at FROM trading_platform.logs WHERE user_id = 'user123' ORDER BY logged_at DESC;"}, {"role": "user", "content": "Show only the logs for that user where the action contains 'trade' and the log entry was created after '2024-07-01'."}, {"role": "assistant", "content": "SELECT log_id, user_id, action, details, logged_at FROM trading_platform.logs WHERE user_id = 'user123' AND action LIKE '%trade%' AND logged_at > '2024-07-01' ORDER BY logged_at DESC;"}, {"role": "user", "content": "Instead of listing the logs, just count how many logs for user 'user123' meet the criteria (action contains 'trade' and logged after '2024-07-01')."}, {"role": "assistant", "content": "SELECT COUNT(*) FROM trading_platform.logs WHERE user_id = 'user123' AND action LIKE '%trade%' AND logged_at > '2024-07-01';"}, {"role": "user", "content": "Now, for that user ('user123') and timeframe (after '2024-07-01'), count how many unique action types containing 'trade' they performed."}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT action) FROM trading_platform.logs WHERE user_id = 'user123' AND action LIKE '%trade%' AND logged_at > '2024-07-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 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) )\n"} {"conversations": [{"role": "user", "content": "List all customers who reside in New York and were created in the system before 2023."}, {"role": "assistant", "content": "SELECT customer_id, first_name, last_name, created_at FROM insurance.customers WHERE state = 'NY' AND created_at < '2023-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 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 )\n"} {"conversations": [{"role": "user", "content": "Provide a count of notifications, separated by whether they have been read or not."}, {"role": "assistant", "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"}], "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": [{"role": "user", "content": "I want to see pairs of items from the same game that share the same rarity but are of different types. Show each pair's names and types."}, {"role": "assistant", "content": "SELECT a.game_id,\n a.item_name AS item1_name,\n a.item_type AS item1_type,\n b.item_name AS item2_name,\n b.item_type AS item2_type\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\n AND a.rarity = b.rarity\n AND a.item_type <> b.item_type\n AND a.item_id < b.item_id;"}, {"role": "user", "content": "Also include cost_currency and cost_amount for each item in the output."}, {"role": "assistant", "content": "SELECT a.game_id,\n a.item_name AS item1_name,\n a.item_type AS item1_type,\n a.cost_currency AS item1_currency,\n a.cost_amount AS item1_cost,\n b.item_name AS item2_name,\n b.item_type AS item2_type,\n b.cost_currency AS item2_currency,\n b.cost_amount AS item2_cost\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\n AND a.rarity = b.rarity\n AND a.item_type <> b.item_type\n AND a.item_id < b.item_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 gaming_technology.in_game_items ( item_id.uuid, game_id.uuid, item_name.text, item_type.text, description.text, rarity.text, cost_currency.text, cost_amount.numeric, attributes.jsonb )\n"} {"conversations": [{"role": "user", "content": "I need a list of claim_ids that have at least one document of type 'Photo' and at least one of type 'Invoice'."}, {"role": "assistant", "content": "SELECT DISTINCT cd.claim_id\nFROM insurance.claim_documents cd\nWHERE cd.document_type IN ('Photo', 'Invoice');"}, {"role": "user", "content": "It returns claim_ids that have either a Photo or an Invoice but not necessarily both. I need only those with both types."}, {"role": "assistant", "content": "SELECT cd.claim_id\nFROM insurance.claim_documents cd\nWHERE cd.document_type IN ('Photo', 'Invoice')\nGROUP BY cd.claim_id\nHAVING COUNT(DISTINCT cd.document_type) = 2;"}, {"role": "user", "content": "Actually, I only want those documents uploaded in 2024."}, {"role": "assistant", "content": "SELECT cd.claim_id\nFROM insurance.claim_documents cd\nWHERE cd.document_type IN ('Photo', 'Invoice')\n AND cd.uploaded_at >= '2024-01-01'\nGROUP BY cd.claim_id\nHAVING COUNT(DISTINCT cd.document_type) = 2;"}, {"role": "user", "content": "Also, I'd like to see the policy_number and incident_date for these claims."}, {"role": "assistant", "content": "SELECT c.claim_id, p.policy_number, c.incident_date\nFROM (\n SELECT cd.claim_id\n FROM insurance.claim_documents cd\n WHERE cd.document_type IN ('Photo', 'Invoice')\n AND cd.uploaded_at >= '2024-01-01'\n GROUP BY cd.claim_id\n HAVING COUNT(DISTINCT cd.document_type) = 2\n) AS filtered\nJOIN insurance.claims c ON filtered.claim_id = c.claim_id\nJOIN insurance.policies p ON c.policy_id = p.policy_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 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 (\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.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 events and any token transfers that occurred in the same transaction, showing event_id, event_name, transfer_id, and token_symbol."}, {"role": "assistant", "content": "SELECT\n e.event_id,\n e.event_name,\n tt.transfer_id,\n tk.token_symbol\nFROM web3.events e\nLEFT JOIN web3.token_transfers tt\n ON e.transaction_id = tt.transaction_id\nLEFT JOIN web3.tokens tk\n ON tt.token_id = tk.token_id\nORDER BY e.transaction_id, e.log_index;"}], "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) )\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.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 ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Find pairs of insurance policies where the plan_id is the same, but they belong to different patients. Show the plan_id, and the patient_id and policy_number for both policies in the pair."}, {"role": "assistant", "content": "SELECT T1.plan_id, T1.patient_id AS patient_id_1, T1.policy_number AS policy_number_1, T2.patient_id AS patient_id_2, T2.policy_number AS policy_number_2 FROM healthcare.patient_insurance AS T1 JOIN healthcare.patient_insurance AS T2 ON T1.plan_id = T2.plan_id WHERE T1.patient_id <> T2.patient_id AND T1.patient_insurance_id < T2.patient_insurance_id;"}, {"role": "user", "content": "Refine this to only include policies that are currently active (expiration_date IS NULL or > CURRENT_DATE) for both policies in the pair."}, {"role": "assistant", "content": "SELECT T1.plan_id, T1.patient_id AS patient_id_1, T1.policy_number AS policy_number_1, T2.patient_id AS patient_id_2, T2.policy_number AS policy_number_2 FROM healthcare.patient_insurance AS T1 JOIN healthcare.patient_insurance AS T2 ON T1.plan_id = T2.plan_id WHERE T1.patient_id <> T2.patient_id AND T1.patient_insurance_id < T2.patient_insurance_id AND (T1.expiration_date IS NULL OR T1.expiration_date > CURRENT_DATE) AND (T2.expiration_date IS NULL OR T2.expiration_date > CURRENT_DATE);"}, {"role": "user", "content": "Also, only show pairs where one policy is primary and the other is not primary (is_primary = TRUE for one, is_primary = FALSE for the other)."}, {"role": "assistant", "content": "SELECT T1.plan_id, T1.patient_id AS patient_id_1, T1.policy_number AS policy_number_1, T2.patient_id AS patient_id_2, T2.policy_number AS policy_number_2 FROM healthcare.patient_insurance AS T1 JOIN healthcare.patient_insurance AS T2 ON T1.plan_id = T2.plan_id WHERE T1.patient_id <> T2.patient_id AND T1.patient_insurance_id < T2.patient_insurance_id AND (T1.expiration_date IS NULL OR T1.expiration_date > CURRENT_DATE) AND (T2.expiration_date IS NULL OR T2.expiration_date > CURRENT_DATE) AND ((T1.is_primary = TRUE AND T2.is_primary = FALSE) OR (T1.is_primary = FALSE AND T2.is_primary = TRUE));"}, {"role": "user", "content": "Filter further to only show pairs where the shared plan_id starts with 'HMO'."}, {"role": "assistant", "content": "SELECT T1.plan_id, T1.patient_id AS patient_id_1, T1.policy_number AS policy_number_1, T2.patient_id AS patient_id_2, T2.policy_number AS policy_number_2 FROM healthcare.patient_insurance AS T1 JOIN healthcare.patient_insurance AS T2 ON T1.plan_id = T2.plan_id WHERE T1.patient_id <> T2.patient_id AND T1.patient_insurance_id < T2.patient_insurance_id AND (T1.expiration_date IS NULL OR T1.expiration_date > CURRENT_DATE) AND (T2.expiration_date IS NULL OR T2.expiration_date > CURRENT_DATE) AND ((T1.is_primary = TRUE AND T2.is_primary = FALSE) OR (T1.is_primary = FALSE AND T2.is_primary = TRUE)) AND T1.plan_id LIKE 'HMO%';"}], "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 token, show its token_id, decimals, and the average total_supply of all tokens with the same decimals."}, {"role": "assistant", "content": "SELECT t.token_id,\n t.decimals,\n avg_data.avg_total_supply\nFROM web3.tokens t\nJOIN (\n SELECT decimals,\n AVG(total_supply) AS avg_total_supply\n FROM web3.tokens\n GROUP BY decimals\n) AS avg_data\n ON t.decimals = avg_data.decimals;"}], "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": [{"role": "user", "content": "Find all pairs of transactions where both transactions have the same nonce and from_address, but different transaction_id. Show both transaction IDs, the shared from_address, shared nonce, and their block numbers."}, {"role": "assistant", "content": "SELECT t1.transaction_id AS transaction_id_1, t2.transaction_id AS transaction_id_2, t1.from_address, t1.nonce, t1.block_number AS block_number_1, t2.block_number AS block_number_2\nFROM web3.transactions t1\nJOIN web3.transactions t2\n ON t1.from_address = t2.from_address\n AND t1.nonce = t2.nonce\n AND t1.transaction_id < t2.transaction_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.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128), -- address of the receiver (can be null for contract deployment)\n value numeric(38,14) NOT NULL, -- value transferred\n gas_used integer NOT NULL, -- amount of gas used by the transaction\n gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction\n block_number integer NOT NULL, -- block number containing the transaction\n timestamp timestamp NOT NULL, -- time when the transaction was mined\n input_data text, -- input data of the transaction (can be null)\n status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)\n nonce integer NOT NULL, -- nonce of the sender at the time of the transaction\n PRIMARY KEY (transaction_id)\n)\n"} {"conversations": [{"role": "user", "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": "assistant", "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": "user", "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": "assistant", "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;"}], "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": [{"role": "user", "content": "List all guests who have not provided their date of birth, along with their email if available."}, {"role": "assistant", "content": "SELECT guest_id, first_name, last_name, email FROM hospitality_technology.guests WHERE date_of_birth IS NULL;"}, {"role": "user", "content": "Now, filter these results to only include guests from the USA."}, {"role": "assistant", "content": "SELECT guest_id, first_name, last_name, email FROM hospitality_technology.guests WHERE date_of_birth IS NULL AND country_code = 'USA';"}, {"role": "user", "content": "The query is missing their city information. Can you include that as well?"}, {"role": "assistant", "content": "SELECT guest_id, first_name, last_name, email, city FROM hospitality_technology.guests WHERE date_of_birth IS NULL AND country_code = 'USA';"}, {"role": "user", "content": "Actually, I need to see the results ordered by created_at in descending order."}, {"role": "assistant", "content": "SELECT guest_id, first_name, last_name, email, city, created_at FROM hospitality_technology.guests WHERE date_of_birth IS NULL AND country_code = 'USA' 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 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": [{"role": "user", "content": "Show me the number of unique achievements unlocked by each player."}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT achievement_id) AS unique_achievements_unlocked\nFROM gaming_technology.player_achievements\nGROUP BY player_id;"}, {"role": "user", "content": "Can you include only players who unlocked more than 3 unique achievements?"}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT achievement_id) AS unique_achievements_unlocked\nFROM gaming_technology.player_achievements\nGROUP BY player_id\nHAVING COUNT(DISTINCT achievement_id) > 3;"}, {"role": "user", "content": "Add another column to show the date when each player unlocked their first achievement."}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT achievement_id) AS unique_achievements_unlocked,\n MIN(unlocked_at) AS first_achievement_unlocked_at\nFROM gaming_technology.player_achievements\nGROUP BY player_id\nHAVING COUNT(DISTINCT achievement_id) > 3;"}, {"role": "user", "content": "Now order the results by unique_achievements_unlocked descending, then by first_achievement_unlocked_at ascending."}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT achievement_id) AS unique_achievements_unlocked,\n MIN(unlocked_at) AS first_achievement_unlocked_at\nFROM gaming_technology.player_achievements\nGROUP BY player_id\nHAVING COUNT(DISTINCT achievement_id) > 3\nORDER BY unique_achievements_unlocked DESC, first_achievement_unlocked_at 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 gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\n"} {"conversations": [{"role": "user", "content": "能否帮我查询特定路线(route_id 为 'RT001')的所有行程信息,并关联到乘客的联系方式?"}, {"role": "assistant", "content": "SELECT s.schedule_id, s.train_id, s.route_id, s.departure_datetime, s.arrival_datetime, s.status, p.passenger_id, p.first_name, p.last_name, p.phone_number, p.email\nFROM schedules s\nLEFT JOIN passengers p ON s.schedule_id = (SELECT schedule_id FROM bookings WHERE passenger_id = p.passenger_id)\nWHERE s.route_id = 'RT001';"}, {"role": "user", "content": "能否只显示状态为‘On Time’的行程,并按出发时间升序排列?"}, {"role": "assistant", "content": "SELECT s.schedule_id, s.train_id, s.route_id, s.departure_datetime, s.arrival_datetime, s.status, p.passenger_id, p.first_name, p.last_name, p.phone_number, p.email\nFROM schedules s\nLEFT JOIN passengers p ON s.schedule_id = (SELECT schedule_id FROM bookings WHERE passenger_id = p.passenger_id)\nWHERE s.route_id = 'RT001' AND s.status = 'On Time'\nORDER BY s.departure_datetime ASC;"}, {"role": "user", "content": "如果乘客信息为空,能否仍然显示行程信息,并限制结果前10条?"}, {"role": "assistant", "content": "SELECT s.schedule_id, s.train_id, s.route_id, s.departure_datetime, s.arrival_datetime, s.status, p.passenger_id, p.first_name, p.last_name, p.phone_number, p.email\nFROM schedules s\nLEFT JOIN passengers p ON s.schedule_id = (SELECT schedule_id FROM bookings WHERE passenger_id = p.passenger_id)\nWHERE s.route_id = 'RT001' AND s.status = 'On Time'\nORDER BY s.departure_datetime ASC\nLIMIT 10;"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n// PUT /schedules\n{\n \"mappings\": {\n \"properties\": {\n \"schedule_id\": { \"type\": \"keyword\" },\n \"train_id\": { \"type\": \"keyword\" }, // References trains index\n \"route_id\": { \"type\": \"keyword\" }, // References routes index\n \"departure_datetime\": { \"type\": \"date\" }, // ISO 8601 format recommended\n \"arrival_datetime\": { \"type\": \"date\" },\n \"status\": { \"type\": \"keyword\" },\n \"notes\": { \"type\": \"text\" }\n }\n }\n}\n// PUT /passengers\n{\n \"mappings\": {\n \"properties\": {\n \"passenger_id\": { \"type\": \"keyword\" },\n \"first_name\": { \n \"type\": \"text\", \n \"fields\": { \"keyword\": { \"type\": \"keyword\", \"ignore_above\": 100 } }\n },\n \"last_name\": { \n \"type\": \"text\", \n \"fields\": { \"keyword\": { \"type\": \"keyword\", \"ignore_above\": 100 } }\n },\n \"email\": { \"type\": \"keyword\" }, // Often used for exact matches\n \"phone_number\": { \"type\": \"keyword\" },\n \"date_of_birth\": { \"type\": \"date\", \"format\": \"yyyy-MM-dd\" },\n \"loyalty_program_id\": { \"type\": \"keyword\" },\n \"created_at\": { \"type\": \"date\" }\n }\n }\n}\n"} {"conversations": [{"role": "user", "content": "List the first name and last name of citizens along with the amount of payments they have made."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.amount FROM government_services.citizens AS T1 JOIN government_services.payments AS T2 ON T1.citizen_id = T2.citizen_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.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.payments ( payment_id text PRIMARY KEY, 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.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 )\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 )\n"} {"conversations": [{"role": "user", "content": "Show me all diesel fuel logs from the last month with their vehicle details, including make, model and license plate."}, {"role": "assistant", "content": "SELECT f.fuel_log_id, f.log_timestamp, f.quantity, f.total_cost, v.make, v.model, v.license_plate FROM transportation.fuel_logs f JOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id WHERE f.fuel_type = 'diesel' AND f.log_timestamp >= CURRENT_DATE - INTERVAL '1 month'"}, {"role": "user", "content": "Can you also include the trip ID and location name where the fueling occurred, and order by the most expensive fuel logs first?"}, {"role": "assistant", "content": "SELECT f.fuel_log_id, f.trip_id, f.log_timestamp, f.quantity, f.total_cost, v.make, v.model, v.license_plate, l.name AS location_name FROM transportation.fuel_logs f JOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id JOIN transportation.locations l ON f.location_id = l.location_id WHERE f.fuel_type = 'diesel' AND f.log_timestamp >= CURRENT_DATE - INTERVAL '1 month' ORDER BY f.total_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.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) )\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 ( 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 (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me all room types with a base rate over $200 and max occupancy of at least 4, along with their property IDs and amenities."}, {"role": "assistant", "content": "SELECT room_type_id, property_id, type_name, base_rate, max_occupancy, amenities FROM hospitality_technology.room_types WHERE base_rate > 200 AND max_occupancy >= 4;"}, {"role": "user", "content": "Now, join this with the guests table to show only room types from properties where the guest's country code is 'USA'."}, {"role": "assistant", "content": "SELECT rt.room_type_id, rt.property_id, rt.type_name, rt.base_rate, rt.max_occupancy, rt.amenities FROM hospitality_technology.room_types rt JOIN hospitality_technology.guests g ON rt.property_id = g.property_id WHERE rt.base_rate > 200 AND rt.max_occupancy >= 4 AND g.country_code = 'USA';"}], "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": [{"role": "user", "content": "Which is the token with the largest difference between its highest and lowest price in the last 24h on each chain, and what is the token's symbol and current price?"}, {"role": "assistant", "content": "SELECT chain, token_symbol, price, (highest_price_24h - lowest_price_24h) AS price_diff_24h\nFROM token_basic_info\nWHERE (chain, highest_price_24h - lowest_price_24h) IN (\n SELECT chain, MAX(highest_price_24h - lowest_price_24h) AS diff\n FROM token_basic_info\n GROUP BY chain\n)\nORDER BY price_diff_24h DESC;"}, {"role": "user", "content": "Could you also include the percentage change over 24 hours for each token in the result?"}, {"role": "assistant", "content": "SELECT chain, token_symbol, price, price_change_percentage_24h, (highest_price_24h - lowest_price_24h) AS price_diff_24h\nFROM token_basic_info\nWHERE (chain, highest_price_24h - lowest_price_24h) IN (\n SELECT chain, MAX(highest_price_24h - lowest_price_24h) AS diff\n FROM token_basic_info\n GROUP BY chain\n)\nORDER BY price_diff_24h DESC;"}, {"role": "user", "content": "I'm only interested in tokens where this price difference exceeds $5. Can you filter for that?"}, {"role": "assistant", "content": "SELECT chain, token_symbol, price, price_change_percentage_24h, (highest_price_24h - lowest_price_24h) AS price_diff_24h\nFROM token_basic_info\nWHERE (chain, highest_price_24h - lowest_price_24h) IN (\n SELECT chain, MAX(highest_price_24h - lowest_price_24h) AS diff\n FROM token_basic_info\n GROUP BY chain\n)\nAND (highest_price_24h - lowest_price_24h) > 5\nORDER BY price_diff_24h 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 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"} {"conversations": [{"role": "user", "content": "List all medical records created in the last 7 days, including patient_id, doctor_id, and record_date."}, {"role": "assistant", "content": "SELECT patient_id, doctor_id, record_date FROM healthcare.medical_records WHERE created_at >= CURRENT_DATE - INTERVAL '7 days';"}, {"role": "user", "content": "Actually, I only need records where the treatment_plan is not empty."}, {"role": "assistant", "content": "SELECT patient_id, doctor_id, record_date FROM healthcare.medical_records WHERE created_at >= CURRENT_DATE - INTERVAL '7 days' AND treatment_plan IS NOT NULL AND treatment_plan != '';"}, {"role": "user", "content": "Can you also sort them by record_date in descending order?"}, {"role": "assistant", "content": "SELECT patient_id, doctor_id, record_date FROM healthcare.medical_records WHERE created_at >= CURRENT_DATE - INTERVAL '7 days' AND treatment_plan IS NOT NULL AND treatment_plan != '' ORDER BY record_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 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 )\n"} {"conversations": [{"role": "user", "content": "List all patients who do not have an email address on file, showing their patient_id, first_name, last_name, and phone_number."}, {"role": "assistant", "content": "SELECT patient_id,\n first_name,\n last_name,\n phone_number\nFROM healthcare.patients\nWHERE email 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 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": "Find all medical records where the vitals field indicates a heart rate over 100 bpm, along with the associated appointment details and diagnosis description if available."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.patient_id, a.appointment_time, a.doctor_id, a.reason, d.description FROM healthcare.medical_records mr LEFT JOIN healthcare.appointments a ON mr.appointment_id = a.appointment_id LEFT JOIN healthcare.diagnoses d ON mr.record_id = d.record_id WHERE mr.vitals::json->>'heart_rate' > '100';"}], "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.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 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 )\n"} {"conversations": [{"role": "user", "content": "List the full name and bar number of all lawyers who were hired before 2015."}, {"role": "assistant", "content": "SELECT first_name || ' ' || last_name AS lawyer_full_name, bar_number\nFROM legal_services.lawyers\nWHERE hire_date < '2015-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.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.lawyers ( lawyer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, bar_number character varying(64) UNIQUE NOT NULL, firm_id character varying(64), email character varying(128) UNIQUE NOT NULL, phone character varying(32), specialization text, hire_date timestamp NOT NULL, is_partner boolean DEFAULT false, PRIMARY KEY (lawyer_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.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) )\n"} {"conversations": [{"role": "user", "content": "Can you write a query that retrieves each server's name, its region, and the highest current player count observed in that region?"}, {"role": "assistant", "content": "SELECT s.server_name, s.region, m.max_current_players\nFROM gaming_technology.servers s\nJOIN (\n SELECT region, MAX(current_players) AS max_current_players\n FROM gaming_technology.servers\n GROUP BY region\n) m ON s.region = m.region;"}, {"role": "user", "content": "Actually, only include regions where that maximum current player count exceeds 50."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, m.max_current_players\nFROM gaming_technology.servers s\nJOIN (\n SELECT region, MAX(current_players) AS max_current_players\n FROM gaming_technology.servers\n GROUP BY region\n HAVING MAX(current_players) > 50\n) m ON s.region = m.region;"}, {"role": "user", "content": "Also, exclude any servers that are already full (where current_players equals max_players)."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, m.max_current_players\nFROM gaming_technology.servers s\nJOIN (\n SELECT region, MAX(current_players) AS max_current_players\n FROM gaming_technology.servers\n GROUP BY region\n HAVING MAX(current_players) > 50\n) m ON s.region = m.region\nWHERE s.current_players < s.max_players;"}, {"role": "user", "content": "Finally, sort the results by region ascending and then by the maximum current players in descending order."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, m.max_current_players\nFROM gaming_technology.servers s\nJOIN (\n SELECT region, MAX(current_players) AS max_current_players\n FROM gaming_technology.servers\n GROUP BY region\n HAVING MAX(current_players) > 50\n) m ON s.region = m.region\nWHERE s.current_players < s.max_players\nORDER BY s.region ASC, m.max_current_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.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) )\n"} {"conversations": [{"role": "user", "content": "What is the average, minimum, and maximum interest_rate for each loan_type among active loans?"}, {"role": "assistant", "content": "SELECT loan_type,\n AVG(interest_rate) AS avg_interest_rate,\n MIN(interest_rate) AS min_interest_rate,\n MAX(interest_rate) AS max_interest_rate\nFROM financial_services.loans\nWHERE status = 'Active'\nGROUP BY loan_type;"}, {"role": "user", "content": "Exclude loan types with fewer than 5 active loans."}, {"role": "assistant", "content": "SELECT loan_type,\n AVG(interest_rate) AS avg_interest_rate,\n MIN(interest_rate) AS min_interest_rate,\n MAX(interest_rate) AS max_interest_rate\nFROM financial_services.loans\nWHERE status = 'Active'\nGROUP BY loan_type\nHAVING COUNT(*) >= 5;"}, {"role": "user", "content": "Sort the result by average_interest_rate descending and only return the top 5 loan types."}, {"role": "assistant", "content": "SELECT loan_type,\n AVG(interest_rate) AS avg_interest_rate,\n MIN(interest_rate) AS min_interest_rate,\n MAX(interest_rate) AS max_interest_rate\nFROM financial_services.loans\nWHERE status = 'Active'\nGROUP BY loan_type\nHAVING COUNT(*) >= 5\nORDER BY avg_interest_rate 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 financial_services.loans (\n loan_id character varying(64) NOT NULL, -- unique identifier for the loan, could be same as account_id\n account_id character varying(64) NOT NULL UNIQUE, -- link to the general account record\n loan_type character varying(50) NOT NULL, -- e.g., Mortgage, Personal, Auto, Student\n principal_amount numeric(19, 4) NOT NULL, -- original loan amount\n current_principal_balance numeric(19, 4) NOT NULL, -- remaining principal\n interest_rate numeric(6, 4) NOT NULL, -- annual interest rate\n term_months integer NOT NULL, -- loan term in months\n origination_date date NOT NULL, -- date the loan was disbursed\n maturity_date date NOT NULL, -- date the loan is due to be fully repaid\n monthly_payment numeric(12, 4), -- scheduled monthly payment amount\n collateral_description text, -- description of collateral, if secured loan\n status character varying(32) NOT NULL, -- e.g., Active, Paid Off, Defaulted\n PRIMARY KEY (loan_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id)\n)\n"} {"conversations": [{"role": "user", "content": "Retrieve all pairs of distinct contract IDs that were created by the same creator within an hour of each other. Include the creator address and the timestamps of both contracts."}, {"role": "assistant", "content": "SELECT sc1.creator_address, sc1.contract_id AS contract_id_1, sc1.timestamp AS timestamp_1, sc2.contract_id AS contract_id_2, sc2.timestamp AS timestamp_2 FROM blockchain.smart_contracts sc1 JOIN blockchain.smart_contracts sc2 ON sc1.creator_address = sc2.creator_address AND sc1.contract_id <> sc2.contract_id WHERE ABS(UNIX_TIMESTAMP(sc1.timestamp) - UNIX_TIMESTAMP(sc2.timestamp)) <= 3600 AND sc1.timestamp < sc2.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 blockchain.smart_contracts ( contract_id.text, creator_address.text, code.text, timestamp.timestamp )\n"} {"conversations": [{"role": "user", "content": "List the full names and dates of birth for all patients who do not have a phone number on record."}, {"role": "assistant", "content": "SELECT first_name, last_name, date_of_birth FROM healthcare.patients WHERE phone_number IS NULL OR TRIM(phone_number) = '';"}], "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": [{"role": "user", "content": "List the first and last names of employees and the number of services offered by their agency."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS service_count\nFROM government_services.employees e\nLEFT JOIN government_services.services s ON e.agency_id = s.agency_id\nGROUP BY e.employee_id, e.first_name, e.last_name;"}, {"role": "user", "content": "Include only employees whose agency offers more than 3 services."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS service_count\nFROM government_services.employees e\nLEFT JOIN government_services.services s ON e.agency_id = s.agency_id\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(s.service_id) > 3;"}, {"role": "user", "content": "Add the agency name to the result."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, ag.agency_name, COUNT(s.service_id) AS service_count\nFROM government_services.employees e\nJOIN government_services.agencies ag ON e.agency_id = ag.agency_id\nLEFT JOIN government_services.services s ON e.agency_id = s.agency_id\nGROUP BY e.employee_id, e.first_name, e.last_name, ag.agency_name\nHAVING COUNT(s.service_id) > 3;"}, {"role": "user", "content": "Now, only show services that are currently active in the count."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, ag.agency_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.agencies ag ON e.agency_id = ag.agency_id\nLEFT JOIN 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, ag.agency_name\nHAVING COUNT(s.service_id) > 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 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 (\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.applications (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\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.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\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) )\n"} {"conversations": [{"role": "user", "content": "List the names of services for which documents are set to expire in the next 90 days."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name FROM government_services.services AS T1 JOIN applications AS T2 ON T1.service_id = T2.service_id JOIN government_services.documents AS T3 ON T2.application_id = T3.application_id WHERE T3.expiry_date IS NOT NULL AND T3.expiry_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '90 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 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.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 )\n"} {"conversations": [{"role": "user", "content": "Find all users who registered with a Yahoo email address, along with their registration dates."}, {"role": "assistant", "content": "SELECT user_id, username, email, password_hash FROM blockchain.users WHERE email LIKE '%@yahoo.com';"}, {"role": "user", "content": "This query doesn't show registration dates. Can you modify it to include the registration date?"}, {"role": "assistant", "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": "user", "content": "Then just show me the count of Yahoo email users instead."}, {"role": "assistant", "content": "SELECT COUNT(*) as yahoo_user_count FROM blockchain.users WHERE email LIKE '%@yahoo.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 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": [{"role": "user", "content": "Show me all active electric vehicles along with their make, model, and license plate, ordered by acquisition date with the newest first."}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, license_plate, acquisition_date FROM transportation.vehicles WHERE status = 'active' AND fuel_type = 'electric' ORDER BY acquisition_date DESC;"}, {"role": "user", "content": "Now include the depot_id for these vehicles and filter to only show vehicles acquired in the last 2 years."}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, license_plate, acquisition_date, depot_id FROM transportation.vehicles WHERE status = 'active' AND fuel_type = 'electric' AND acquisition_date >= CURRENT_DATE - INTERVAL '2 years' ORDER BY acquisition_date DESC;"}, {"role": "user", "content": "Can you also include the vehicle's capacity and order the results by capacity in descending order?"}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, license_plate, acquisition_date, depot_id, capacity FROM transportation.vehicles WHERE status = 'active' AND fuel_type = 'electric' AND acquisition_date >= CURRENT_DATE - INTERVAL '2 years' ORDER BY capacity 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": "Which exchanges hold the largest total USD value of tokens on the BSC chain in the most recent snapshot, and what is the top token (by usd_value) held by each exchange?"}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"}, {"role": "user", "content": "Can you add the number of distinct tokens each exchange holds on BSC in the latest snapshot to the result?"}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value,\n COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n e.token_count,\n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"}, {"role": "user", "content": "I'd like the results filtered so only exchanges holding more than $2,000,000 in total on BSC are included."}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value,\n COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n HAVING SUM(c.usd_value) > 2000000\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n e.token_count,\n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.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\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"} {"conversations": [{"role": "user", "content": "List the latest version of each document (identified by case_id and document_name), showing the version number and its upload_timestamp."}, {"role": "assistant", "content": "SELECT d.case_id,\n d.document_name,\n d.version AS latest_version,\n d.upload_timestamp\nFROM legal_services.documents d\nJOIN (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m ON d.case_id = m.case_id\n AND d.document_name = m.document_name\n AND d.version = m.max_version;"}, {"role": "user", "content": "Actually, I also want to see the upload_timestamp of the previous version for each document."}, {"role": "assistant", "content": "SELECT m.case_id,\n m.document_name,\n m.max_version AS latest_version,\n d_latest.upload_timestamp AS latest_timestamp,\n d_prev.upload_timestamp AS previous_timestamp\nFROM (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m\nJOIN legal_services.documents d_latest\n ON d_latest.case_id = m.case_id\n AND d_latest.document_name = m.document_name\n AND d_latest.version = m.max_version\nLEFT JOIN legal_services.documents d_prev\n ON d_prev.case_id = m.case_id\n AND d_prev.document_name = m.document_name\n AND d_prev.version = m.max_version - 1;"}, {"role": "user", "content": "Also, only include documents whose first version (version = 1) was uploaded in 2024."}, {"role": "assistant", "content": "SELECT m.case_id,\n m.document_name,\n m.max_version AS latest_version,\n d_latest.upload_timestamp AS latest_timestamp,\n d_prev.upload_timestamp AS previous_timestamp\nFROM (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m\nJOIN legal_services.documents d_first\n ON d_first.case_id = m.case_id\n AND d_first.document_name = m.document_name\n AND d_first.version = 1\n AND d_first.upload_timestamp >= '2024-01-01'\n AND d_first.upload_timestamp < '2025-01-01'\nJOIN legal_services.documents d_latest\n ON d_latest.case_id = m.case_id\n AND d_latest.document_name = m.document_name\n AND d_latest.version = m.max_version\nLEFT JOIN legal_services.documents d_prev\n ON d_prev.case_id = m.case_id\n AND d_prev.document_name = m.document_name\n AND d_prev.version = m.max_version - 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 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": [{"role": "user", "content": "Find transactions that triggered events and whose to_address matches the contract_id of the emitted event. List the transaction ID, the to_address, and the count of such events for that transaction."}, {"role": "assistant", "content": "SELECT t.transaction_id, t.to_address, COUNT(e.event_id) AS matching_event_count FROM web3.transactions t JOIN web3.events e ON t.transaction_id = e.transaction_id WHERE t.to_address IS NOT NULL AND t.to_address = e.contract_id GROUP BY t.transaction_id, t.to_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 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.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )\n"} {"conversations": [{"role": "user", "content": "For each claim, show the claim ID, incident date, and the number of documents attached to it. Only include claims that have at least 2 documents."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, COUNT(d.document_id) AS document_count\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nGROUP BY c.claim_id, c.incident_date\nHAVING COUNT(d.document_id) >= 2;"}], "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, 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.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 )\n"} {"conversations": [{"role": "user", "content": "Which projects raised funds in January 2022?"}, {"role": "assistant", "content": "SELECT project_name, rounds_name, investment_value, investment_date FROM project_fundraising_record WHERE investment_date >= '2022-01-01' AND investment_date < '2022-02-01';"}, {"role": "user", "content": "Please also show their introductions."}, {"role": "assistant", "content": "SELECT project_name, rounds_name, investment_value, investment_date, introduction FROM project_fundraising_record WHERE investment_date >= '2022-01-01' AND investment_date < '2022-02-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 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": "For each narrative in smart money token inflow, calculate the total usd_value and list the token symbol that has the highest liquidity from the DEX pool."}, {"role": "assistant", "content": "SELECT i.narrative, SUM(i.usd_value) AS total_usd_inflow,\n (SELECT d.token_symbol\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity_token,\n (SELECT d.liquidity\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity\nFROM smart_money_token_inflow i\nGROUP BY i.narrative;"}, {"role": "user", "content": "Also include the average price_change_percentage_24h of that top liquidity token."}, {"role": "assistant", "content": "SELECT i.narrative, SUM(i.usd_value) AS total_usd_inflow,\n (SELECT d.token_symbol\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity_token,\n (SELECT d.liquidity\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity,\n (SELECT d.price_change_percentage_24h\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS price_change_24h\nFROM smart_money_token_inflow i\nGROUP BY i.narrative;"}, {"role": "user", "content": "Filter to include only narratives that have more than 2 distinct tokens in the inflow records."}, {"role": "assistant", "content": "SELECT i.narrative, SUM(i.usd_value) AS total_usd_inflow,\n (SELECT d.token_symbol\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity_token,\n (SELECT d.liquidity\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity,\n (SELECT d.price_change_percentage_24h\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS price_change_24h\nFROM smart_money_token_inflow i\nGROUP BY i.narrative\nHAVING COUNT(DISTINCT i.token_symbol) > 2;"}, {"role": "user", "content": "Finally, only show narratives where the total usd_value exceeds 20000."}, {"role": "assistant", "content": "SELECT i.narrative, SUM(i.usd_value) AS total_usd_inflow,\n (SELECT d.token_symbol\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity_token,\n (SELECT d.liquidity\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS top_liquidity,\n (SELECT d.price_change_percentage_24h\n FROM smart_money_token_inflow inf2\n JOIN token_dexpool_info d ON inf2.token_symbol = d.token_symbol AND inf2.chain = d.chain\n WHERE inf2.narrative = i.narrative\n ORDER BY d.liquidity DESC\n LIMIT 1) AS price_change_24h\nFROM smart_money_token_inflow i\nGROUP BY i.narrative\nHAVING COUNT(DISTINCT i.token_symbol) > 2\n AND SUM(i.usd_value) > 20000;"}], "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) )\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 )\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": "Show me the top 5 NFT collections with the highest floor price on Ethereum, along with their names and contract addresses, but only include collections with more than 5000 tokens."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.floor_price FROM nft_collections nc WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Can you join this with the nft_metadata table to include the average rarity score for these collections?"}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.floor_price, AVG(nm.rarity_score) as avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 GROUP BY nc.name, nc.contract_address, nc.floor_price ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Now filter these results to only show collections with an average rarity score above 75."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.floor_price, AVG(nm.rarity_score) as avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 GROUP BY nc.name, nc.contract_address, nc.floor_price HAVING AVG(nm.rarity_score) > 75 ORDER BY CAST(nc.floor_price AS decimal) 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 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 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 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 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_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 )\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": [{"role": "user", "content": "Find all contracts where the deployer address is the same as the contract address, indicating self-deployed contracts."}, {"role": "assistant", "content": "SELECT address, deployer_address FROM web3.contracts WHERE address = deployer_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 web3.contracts ( contract_id text, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\n"} {"conversations": [{"role": "user", "content": "List all reviews for properties with a star rating of at least 4.5. Include the property_name, review_id, rating_overall, and review_date."}, {"role": "assistant", "content": "SELECT p.property_name, r.review_id, r.rating_overall, r.review_date\nFROM hospitality_technology.reviews r\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE p.star_rating >= 4.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 hospitality_technology.properties ( property_id text PRIMARY KEY, 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.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 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.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 (\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 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": "List all insurance plans along with their provider, plan type, and the contact phone number. Also, for each plan, show how many doctors have their hospital affiliation ID matching the plan ID."}, {"role": "assistant", "content": "SELECT ip.plan_id, ip.plan_name, ip.insurance_provider, ip.plan_type, ip.contact_phone, COUNT(d.doctor_id) FROM healthcare.insurance_plans ip LEFT JOIN healthcare.doctors d ON ip.plan_id = d.hospital_affiliation_id GROUP BY ip.plan_id, ip.plan_name, ip.insurance_provider, ip.plan_type, ip.contact_phone"}], "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 ( 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 ( 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 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 text, created_at 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": [{"role": "user", "content": "List vehicle_id, make, model, and capacity for all vehicles acquired in 2023."}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, capacity\nFROM transportation.vehicles\nWHERE acquisition_date >= '2023-01-01'\n AND acquisition_date <= '2023-12-31';"}, {"role": "user", "content": "Now include only vehicles with capacity greater than or equal to 50 and order by capacity descending."}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, capacity\nFROM transportation.vehicles\nWHERE acquisition_date >= '2023-01-01'\n AND acquisition_date <= '2023-12-31'\n AND capacity >= 50\nORDER BY capacity 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 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.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 )\nCREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n"} {"conversations": [{"role": "user", "content": "Please list the full name and status of clients who have not provided a company name."}, {"role": "assistant", "content": "SELECT first_name, last_name, status\nFROM legal_services.clients\nWHERE company_name 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 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 )\n"} {"conversations": [{"role": "user", "content": "Find all blocks with difficulty above 5000 and include their timestamp."}, {"role": "assistant", "content": "SELECT block_id, timestamp FROM blockchain.blocks WHERE difficulty > 5000;"}, {"role": "user", "content": "Now show me the count of such blocks grouped by month in 2023."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', timestamp) AS month, COUNT(*) AS block_count FROM blockchain.blocks WHERE difficulty > 5000 AND timestamp BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY month ORDER BY month;"}, {"role": "user", "content": "Actually, I want to see the average difficulty for each of these months as well."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', timestamp) AS month, COUNT(*) AS block_count, AVG(difficulty) AS avg_difficulty FROM blockchain.blocks WHERE difficulty > 5000 AND timestamp BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY month ORDER BY month;"}, {"role": "user", "content": "Can you modify this to also include the block_id with the highest difficulty for each month?"}, {"role": "assistant", "content": "WITH monthly_stats AS (SELECT DATE_TRUNC('month', timestamp) AS month, COUNT(*) AS block_count, AVG(difficulty) AS avg_difficulty FROM blockchain.blocks WHERE difficulty > 5000 AND timestamp BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY month) SELECT ms.month, ms.block_count, ms.avg_difficulty, (SELECT b.block_id FROM blockchain.blocks b WHERE DATE_TRUNC('month', b.timestamp) = ms.month AND b.difficulty > 5000 ORDER BY b.difficulty DESC LIMIT 1) AS highest_diff_block_id FROM monthly_stats ms ORDER BY ms.month;"}], "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 PRIMARY KEY, previous_block_id text, timestamp timestamp, nonce int, merkle_root text, difficulty int )\nCREATE TABLE blockchain.addresses ( address_id text PRIMARY KEY, public_key text, balance numeric )\nCREATE TABLE blockchain.smart_contracts ( contract_id text PRIMARY KEY, creator_address text, code text, timestamp timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me the historical balance entries for wallet address '0xabc...' and contract address '0xdef...', including the block number and amount."}, {"role": "assistant", "content": "SELECT block_number, amount FROM erc20_balances_historical WHERE wallet_address = '0xabc...' AND contract_address = '0xdef...'"}, {"role": "user", "content": "For these entries, please also include the token symbol and name by joining with the `token_metas` table."}, {"role": "assistant", "content": "SELECT T1.block_number, T1.amount, T2.symbol, T2.name FROM erc20_balances_historical AS T1 JOIN token_metas AS T2 ON T1.contract_address = T2.contract_address WHERE T1.wallet_address = '0xabc...' AND T1.contract_address = '0xdef...'"}, {"role": "user", "content": "Now, add the latest USD price for this token by joining the `token_prices_latest` table."}, {"role": "assistant", "content": "SELECT T1.block_number, T1.amount, T2.symbol, T2.name, T3.price FROM erc20_balances_historical AS T1 JOIN token_metas AS T2 ON T1.contract_address = T2.contract_address JOIN token_prices_latest AS T3 ON T2.contract_address = T3.address WHERE T1.wallet_address = '0xabc...' AND T1.contract_address = '0xdef...'"}, {"role": "user", "content": "Finally, filter the results to only show historical entries where the latest USD price is greater than 100."}, {"role": "assistant", "content": "SELECT T1.block_number, T1.amount, T2.symbol, T2.name, T3.price FROM erc20_balances_historical AS T1 JOIN token_metas AS T2 ON T1.contract_address = T2.contract_address JOIN token_prices_latest AS T3 ON T2.contract_address = T3.address WHERE T1.wallet_address = '0xabc...' AND T1.contract_address = '0xdef...' AND T3.price > 100"}], "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, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address 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_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 ( 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_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_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 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": "List the case number, case name, and the full name of the client for cases that have uploaded documents."}, {"role": "assistant", "content": "SELECT T1.case_number , T1.case_name , T2.full_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id WHERE EXISTS ( SELECT 1 FROM legal_services.documents AS T3 WHERE T3.case_id = T1.case_id )"}, {"role": "user", "content": "Also include the full name of the lead lawyer for these cases."}, {"role": "assistant", "content": "SELECT T1.case_number , T1.case_name , T2.full_name AS client_name , T4.full_name AS lawyer_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id JOIN legal_services.lawyers AS T4 ON T1.lead_lawyer_id = T4.lawyer_id WHERE EXISTS ( SELECT 1 FROM legal_services.documents AS T3 WHERE T3.case_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.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": [{"role": "user", "content": "Show me the names of law firms founded after 2010, along with the full name of their managing partner."}, {"role": "assistant", "content": "SELECT f.firm_name, l.first_name, l.last_name FROM legal_services.law_firms AS f JOIN legal_services.lawyers AS l ON f.managing_partner_id = l.lawyer_id WHERE f.founded_date > '2010-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 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": "Show me the number of guests for each city they reside in."}, {"role": "assistant", "content": "SELECT city, count(*) AS guest_count FROM hospitality_technology.guests WHERE city IS NOT NULL GROUP BY city;"}, {"role": "user", "content": "Now, only show cities with more than 10 guests and order the results by the guest count in descending order."}, {"role": "assistant", "content": "SELECT city, count(*) AS guest_count FROM hospitality_technology.guests WHERE city IS NOT NULL GROUP BY city HAVING count(*) > 10 ORDER BY guest_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.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 )\n"} {"conversations": [{"role": "user", "content": "For each user, show their user_id, KYC status, and the total count of completed orders they've placed."}, {"role": "assistant", "content": "SELECT k.user_id, k.status, COUNT(o.order_id) AS completed_order_count\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nGROUP BY k.user_id, k.status;"}, {"role": "user", "content": "Only include users whose KYC status is 'approved'."}, {"role": "assistant", "content": "SELECT k.user_id, k.status, COUNT(o.order_id) AS completed_order_count\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nWHERE k.status = 'approved'\nGROUP BY k.user_id, k.status;"}, {"role": "user", "content": "Also calculate the total value of these completed orders as total_value."}, {"role": "assistant", "content": "SELECT k.user_id,\n k.status,\n COUNT(o.order_id) AS completed_order_count,\n SUM(o.quantity * o.price) AS total_value\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nWHERE k.status = 'approved'\nGROUP BY k.user_id, k.status;"}, {"role": "user", "content": "Finally, order the results by total_value descending and limit to 5."}, {"role": "assistant", "content": "SELECT k.user_id,\n k.status,\n COUNT(o.order_id) AS completed_order_count,\n SUM(o.quantity * o.price) AS total_value\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nWHERE k.status = 'approved'\nGROUP BY k.user_id, k.status\nORDER BY total_value 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 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.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\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.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.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "List all pairs of properties located in the same city, showing each pair's property IDs and names along with the city."}, {"role": "assistant", "content": "SELECT p1.property_id AS property_id_1,\n p1.property_name AS property_name_1,\n p2.property_id AS property_id_2,\n p2.property_name AS property_name_2,\n p1.city\nFROM hospitality_technology.properties p1\nJOIN hospitality_technology.properties p2\n ON p1.city = p2.city\n AND p1.property_id < p2.property_id;"}, {"role": "user", "content": "Only include pairs in cities that have more than two properties."}, {"role": "assistant", "content": "SELECT p1.property_id AS property_id_1,\n p1.property_name AS property_name_1,\n p2.property_id AS property_id_2,\n p2.property_name AS property_name_2,\n p1.city\nFROM hospitality_technology.properties p1\nJOIN hospitality_technology.properties p2\n ON p1.city = p2.city\n AND p1.property_id < p2.property_id\nWHERE p1.city IN (\n SELECT city\n FROM hospitality_technology.properties\n GROUP BY city\n HAVING COUNT(*) > 2\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 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) )\n"} {"conversations": [{"role": "user", "content": "List the medication_name and manufacturer for all medications where the description is null or an empty string."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NULL OR description = '';"}, {"role": "user", "content": "Now, refine the query to only include medications whose ndc_code starts with '5'."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer FROM healthcare.medications WHERE (description IS NULL OR description = '') AND ndc_code LIKE '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 (\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 (\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)\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.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)\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": "Show the first and last names, email, and phone number for all patients who were added to the system in the last 90 days along with their emergency contact name."}, {"role": "assistant", "content": "SELECT first_name, last_name, email, phone_number, emergency_contact_name FROM healthcare.patients WHERE created_at >= NOW() - INTERVAL '90 days';"}, {"role": "user", "content": "Actually, can you also include the emergency contact phone number in the results?"}, {"role": "assistant", "content": "SELECT first_name, last_name, email, phone_number, emergency_contact_name, emergency_contact_phone FROM healthcare.patients WHERE created_at >= NOW() - INTERVAL '90 days';"}, {"role": "user", "content": "Now filter to only patients whose emergency_contact_phone is not null."}, {"role": "assistant", "content": "SELECT first_name, last_name, email, phone_number, emergency_contact_name, emergency_contact_phone FROM healthcare.patients WHERE created_at >= NOW() - INTERVAL '90 days' AND emergency_contact_phone IS NOT NULL;"}, {"role": "user", "content": "Sorry, I only want patients whose phone_number field is empty. Can you update the query?"}, {"role": "assistant", "content": "SELECT first_name, last_name, email, phone_number, emergency_contact_name, emergency_contact_phone FROM healthcare.patients WHERE created_at >= NOW() - INTERVAL '90 days' AND emergency_contact_phone IS NOT NULL AND (phone_number IS NULL OR phone_number = '');"}], "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": "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": "assistant", "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;"}], "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": [{"role": "user", "content": "List all DApps along with the number of metadata entries linked to each, even if the DApp has no linked metadata."}, {"role": "assistant", "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;"}], "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": [{"role": "user", "content": "Find the contract ID, address, and deployer address for all contracts that have not emitted any events."}, {"role": "assistant", "content": "SELECT c.contract_id, c.address, c.deployer_address FROM web3.contracts AS c LEFT JOIN web3.events AS e ON c.contract_id = e.contract_id WHERE e.event_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 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 (\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.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": [{"role": "user", "content": "Provide a list of all vehicles and the total quantity of fuel refueled for each vehicle."}, {"role": "assistant", "content": "SELECT T1.license_plate, sum(T2.quantity) FROM transportation.vehicles AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.license_plate"}], "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": [{"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": "List all guests who have a loyalty member ID, showing their full name (first and last name), email, and loyalty ID."}, {"role": "assistant", "content": "SELECT first_name, last_name, email, loyalty_member_id FROM hospitality_technology.guests WHERE loyalty_member_id IS NOT NULL;"}, {"role": "user", "content": "Can you also include the date they registered as a guest?"}, {"role": "assistant", "content": "SELECT first_name, last_name, email, loyalty_member_id, created_at FROM hospitality_technology.guests WHERE loyalty_member_id IS NOT 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 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 ( 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 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.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 ( 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.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)\n"} {"conversations": [{"role": "user", "content": "List the token symbol, token name, and contract address for all tokens that have no recorded transfers in the token_transfers table."}, {"role": "assistant", "content": "SELECT T.token_symbol, T.token_name, T.contract_address FROM web3.tokens AS T LEFT JOIN token_transfers AS TT ON T.token_id = TT.token_id WHERE TT.transfer_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 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": [{"role": "user", "content": "Can you help me get the total number of operational platforms across all stations?"}, {"role": "assistant", "content": "db.platforms.countDocuments({ status: 'Operational' });"}], "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": [{"role": "user", "content": "Show prescriptions with their corresponding chief complaint from the medical record. Return prescription_id, record_id, and chief_complaint."}, {"role": "assistant", "content": "SELECT p.prescription_id, p.record_id, mr.chief_complaint\nFROM healthcare.prescriptions p\nLEFT JOIN healthcare.medical_records mr ON p.record_id = mr.record_id;"}, {"role": "user", "content": "Only include prescriptions where chief_complaint contains 'fever' and the route is 'Oral'."}, {"role": "assistant", "content": "SELECT p.prescription_id, p.record_id, mr.chief_complaint\nFROM healthcare.prescriptions p\nLEFT JOIN healthcare.medical_records mr ON p.record_id = mr.record_id\nWHERE mr.chief_complaint ILIKE '%fever%'\n AND p.route = 'Oral';"}, {"role": "user", "content": "Also include the medication_name by joining the medications table and sort the results by prescription_date ascending."}, {"role": "assistant", "content": "SELECT p.prescription_id,\n p.record_id,\n mr.chief_complaint,\n m.medication_name\nFROM healthcare.prescriptions p\nLEFT JOIN healthcare.medical_records mr ON p.record_id = mr.record_id\nLEFT JOIN healthcare.medications m ON p.medication_id = m.medication_id\nWHERE mr.chief_complaint ILIKE '%fever%'\n AND p.route = 'Oral'\nORDER BY p.prescription_date 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 ( 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 ( 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 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 text, created_at timestamp )\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 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": "List lawyers who have any unbilled time entries. Show their first name, last name, and the count of their unbilled entries."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, COUNT(T2.entry_id) FROM lawyers AS T1 JOIN time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id WHERE T2.is_billed = false GROUP BY T1.lawyer_id, T1.first_name, T1.last_name;"}, {"role": "user", "content": "Modify that query to only include entries marked as billable, and instead show the total hours spent rather than the count."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, SUM(T2.hours_spent) FROM lawyers AS T1 JOIN time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id WHERE T2.is_billed = false AND T2.is_billable = true GROUP BY T1.lawyer_id, T1.first_name, T1.last_name;"}, {"role": "user", "content": "Now, only show lawyers with more than 10 unbilled billable hours in total, and sort the results by the total hours descending."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, SUM(T2.hours_spent) FROM lawyers AS T1 JOIN time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id WHERE T2.is_billed = false AND T2.is_billable = true GROUP BY T1.lawyer_id, T1.first_name, T1.last_name HAVING SUM(T2.hours_spent) > 10 ORDER BY SUM(T2.hours_spent) 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.lawyers ( lawyer_id text PRIMARY KEY, first_name text, last_name text, bar_number text UNIQUE, firm_id text, email text UNIQUE, phone text, specialization text, hire_date timestamp, is_partner bool )\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 )\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 )\nCREATE TABLE legal_services.appointments ( appointment_id text PRIMARY KEY, 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": "Show the number of achievements unlocked by each player per month. Display player_id, month (as YYYY-MM), and achievement_count."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM');"}, {"role": "user", "content": "Filter to months where players unlocked at least 5 achievements."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5;"}, {"role": "user", "content": "Sort the results by year_month ascending and then by achievement_count descending."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5\nORDER BY year_month ASC, achievement_count DESC;"}, {"role": "user", "content": "Limit the results to 10 rows."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5\nORDER BY year_month ASC, achievement_count 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 gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\n"} {"conversations": [{"role": "user", "content": "For each Avalanche token tick, calculate the total transfer volume and transaction count over the past 7 days using token_activities_avalanche. Include the token tick, total_volume, and tx_count."}, {"role": "assistant", "content": "SELECT\n tick,\n SUM(amt) AS total_volume,\n COUNT(*) AS tx_count\nFROM token_activities_avalanche\nWHERE block_timestamp >= CURRENT_DATE - INTERVAL '7 days'\nGROUP BY tick;"}, {"role": "user", "content": "Also include the creator address from token_info for each tick, and filter where total_volume > 1000 and creator starts with '0x1'."}, {"role": "assistant", "content": "SELECT\n a.tick,\n SUM(a.amt) AS total_volume,\n COUNT(*) AS tx_count,\n i.creator\nFROM token_activities_avalanche a\nJOIN token_info i\n ON a.tick = i.tick\nWHERE a.block_timestamp >= CURRENT_DATE - INTERVAL '7 days'\nGROUP BY a.tick, i.creator\nHAVING SUM(a.amt) > 1000\n AND i.creator LIKE '0x1%';"}, {"role": "user", "content": "Sort the results by total_volume descending and limit to the top 5 tokens."}, {"role": "assistant", "content": "SELECT\n a.tick,\n SUM(a.amt) AS total_volume,\n COUNT(*) AS tx_count,\n i.creator\nFROM token_activities_avalanche a\nJOIN token_info i\n ON a.tick = i.tick\nWHERE a.block_timestamp >= CURRENT_DATE - INTERVAL '7 days'\nGROUP BY a.tick, i.creator\nHAVING SUM(a.amt) > 1000\n AND i.creator LIKE '0x1%'\nORDER BY total_volume 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.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_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_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 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_prices_latest ( 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_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, 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 (\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(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\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 varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\n"} {"conversations": [{"role": "user", "content": "Show me the usernames and email addresses of users who commented on any post tagged with the hashtag 'H777'."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.email\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nJOIN social_media.post_hashtags ph ON c.post_id = ph.post_id\nWHERE ph.hashtag_id = 'H777';"}, {"role": "user", "content": "Please also include the comment content and when each comment was created."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.email, c.content, c.created_at\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nJOIN social_media.post_hashtags ph ON c.post_id = ph.post_id\nWHERE ph.hashtag_id = 'H777';"}, {"role": "user", "content": "Now, only include comments created after April 1, 2024."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.email, c.content, c.created_at\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nJOIN social_media.post_hashtags ph ON c.post_id = ph.post_id\nWHERE ph.hashtag_id = 'H777'\n AND c.created_at > '2024-04-01';"}, {"role": "user", "content": "Instead of email, show the user's full name, and sort by comment creation time descending."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.full_name, c.content, c.created_at\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nJOIN social_media.post_hashtags ph ON c.post_id = ph.post_id\nWHERE ph.hashtag_id = 'H777'\n AND c.created_at > '2024-04-01'\nORDER BY c.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 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, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text, tag_name text, created_at timestamp )\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 ( 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": [{"role": "user", "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": "assistant", "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)"}], "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": [{"role": "user", "content": "List the vehicle_id, make, model, and total maintenance cost for each vehicle that has undergone maintenance, ordering by total maintenance cost descending."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, SUM(m.cost) AS total_maintenance_cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nGROUP BY m.vehicle_id, v.make, v.model\nORDER BY total_maintenance_cost DESC;"}, {"role": "user", "content": "Now further include the count of maintenance entries per vehicle and only include vehicles with more than 3 maintenance logs."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, COUNT(*) AS maintenance_count, SUM(m.cost) AS total_maintenance_cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nGROUP BY m.vehicle_id, v.make, v.model\nHAVING COUNT(*) > 3\nORDER BY total_maintenance_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.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, 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.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 PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n"} {"conversations": [{"role": "user", "content": "Retrieve each agency’s name along with the count of accessible service locations it has in California."}, {"role": "assistant", "content": "SELECT\n a.agency_name,\n COUNT(l.location_id) AS accessible_location_count\nFROM government_services.agencies a\nJOIN government_services.service_locations l\n ON a.agency_id = l.agency_id\nWHERE l.is_accessible = TRUE\n AND l.state = 'California'\nGROUP BY a.agency_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 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.employees ( employee_id text PRIMARY KEY, 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 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 )\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": "能否帮我统计特定车站(station_id 为 'station_xyz')的所有工作人员数量?"}, {"role": "assistant", "content": "MATCH (s:Station {station_id: 'station_xyz'})<-[:BASED_AT]-(staff:Staff)\nRETURN COUNT(staff) AS total_staff"}], "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// Node Label: :Station\n// Properties:\n// station_id: String (Constraint: UNIQUE)\n// station_name: String\n// city: String (Index recommended)\n// state_province: String\n// country_code: String\n// address: String\n// timezone: String\n// number_of_platforms: Integer\n// created_at: DateTime\n// last_updated_at: DateTime\n// Example Cypher CREATE:\n// CREATE (:Station {station_id: 'station_xyz', station_name: 'Grand Central Terminal', city: 'New York', ...})\n// Node Label: :Platform\n// Properties:\n// platform_id: String (Constraint: UNIQUE)\n// platform_number: String\n// track_number: String\n// status: String\n// length_meters: Float\n// accessible: Boolean\n// Relationship: (:Platform)-[:LOCATED_AT]->(:Station)\n// Example Cypher CREATE:\n// MATCH (s:Station {station_id: 'station_xyz'})\n// CREATE (p:Platform {platform_id: 'plat_123', ...})-[:LOCATED_AT]->(s)\n// Node Label: :Train\n// Properties:\n// train_id: String (Constraint: UNIQUE)\n// train_number: String (Constraint: UNIQUE)\n// model: String\n// manufacturer: String\n// year_manufactured: Integer\n// capacity: Integer\n// status: String\n// last_maintenance_date: Date\n// next_maintenance_date: Date\n// Example Cypher CREATE:\n// CREATE (:Train {train_id: 'train_789', train_number: 'Acela 2151', ...})\n// Node Label: :TrainCar\n// Properties:\n// car_id: String (Constraint: UNIQUE)\n// car_number: String\n// car_type: String\n// class: String\n// capacity: Integer\n// features: String (Or List if driver supports)\n// Relationship: (:TrainCar)-[:PART_OF_TRAIN]->(:Train)\n// Example Cypher CREATE:\n// MATCH (t:Train {train_id: 'train_789'})\n// CREATE (c:TrainCar {car_id: 'car_abc', ...})-[:PART_OF_TRAIN]->(t)\n// Node Label: :Route\n// Properties:\n// route_id: String (Constraint: UNIQUE)\n// route_name: String\n// description: String\n// is_active: Boolean\n// Relationships:\n// (:Route)-[:STARTS_AT]->(:Station)\n// (:Route)-[:ENDS_AT]->(:Station)\n// Example Cypher CREATE:\n// MATCH (origin:Station {station_id: 'station_bos'}), (dest:Station {station_id: 'station_was'})\n// CREATE (r:Route {route_id: 'route_ne_corr', ...})-[:STARTS_AT]->(origin), (r)-[:ENDS_AT]->(dest)\n// Relationship: (:Route)-[rel:HAS_STOP]->(:Station)\n// Relationship Properties on :HAS_STOP:\n// sequence_order: Integer\n// distance_from_previous_km: Float\n// typical_stop_duration_minutes: Integer\n// Example Cypher CREATE:\n// MATCH (r:Route {route_id: 'route_ne_corr'}), (s:Station {station_id: 'station_pvd'})\n// CREATE (r)-[:HAS_STOP {sequence_order: 2, distance_from_previous_km: 70.5, ...}]->(s)\n// Node Label: :ScheduledTrip (or just :Trip)\n// Properties:\n// schedule_id: String (Constraint: UNIQUE)\n// departure_datetime: DateTime\n// arrival_datetime: DateTime\n// status: String\n// notes: String\n// Relationships:\n// (:ScheduledTrip)-[:USES_TRAIN]->(:Train)\n// (:ScheduledTrip)-[:FOLLOWS_ROUTE]->(:Route)\n// Example Cypher CREATE:\n// MATCH (t:Train {train_id: 'train_789'}), (r:Route {route_id: 'route_ne_corr'})\n// CREATE (sched:ScheduledTrip {schedule_id: 'sched_1122', ...})-[:USES_TRAIN]->(t), (sched)-[:FOLLOWS_ROUTE]->(r)\n// Relationship: (:ScheduledTrip)-[rel:SCHEDULED_STOP]->(:Station)\n// Relationship Properties on :SCHEDULED_STOP:\n// sequence_order: Integer\n// platform_id: String (references Platform node if modeled, or just store ID)\n// scheduled_arrival_time: DateTime\n// scheduled_departure_time: DateTime\n// actual_arrival_time: DateTime\n// actual_departure_time: DateTime\n// status: String\n// Example Cypher CREATE:\n// MATCH (sched:ScheduledTrip {schedule_id: 'sched_1122'}), (s:Station {station_id: 'station_pvd'})\n// CREATE (sched)-[:SCHEDULED_STOP {sequence_order: 2, platform_id: 'plat_pvd_1', ...}]->(s)\n// Node Label: :Passenger\n// Properties:\n// passenger_id: String (Constraint: UNIQUE)\n// first_name: String\n// last_name: String\n// email: String (Constraint: UNIQUE, if not null)\n// phone_number: String (Constraint: UNIQUE, if not null)\n// date_of_birth: Date\n// loyalty_program_id: String\n// created_at: DateTime\n// Example Cypher CREATE:\n// CREATE (:Passenger {passenger_id: 'pass_pqr', first_name: 'Alice', ...})\n// Node Label: :Booking\n// Properties:\n// booking_id: String (Constraint: UNIQUE)\n// booking_datetime: DateTime\n// status: String\n// total_price: Float\n// currency_code: String\n// special_requests: String\n// Relationships:\n// (:Passenger)-[:MADE_BOOKING]->(:Booking)\n// (:Booking)-[:FOR_TRIP]->(:ScheduledTrip)\n// Example Cypher CREATE:\n// MATCH (p:Passenger {passenger_id: 'pass_pqr'}), (sched:ScheduledTrip {schedule_id: 'sched_1122'})\n// CREATE (p)-[:MADE_BOOKING]->(b:Booking {booking_id: 'book_zyx', ...})-[:FOR_TRIP]->(sched)\n// Node Label: :Ticket\n// Properties:\n// ticket_id: String (Constraint: UNIQUE)\n// seat_number: String\n// ticket_type: String\n// price: Float\n// is_checked_in: Boolean\n// qr_code_data: String\n// Relationships:\n// (:Ticket)-[:PART_OF_BOOKING]->(:Booking)\n// (:Ticket)-[:ASSIGNED_TO_CAR]->(:TrainCar)\n// Example Cypher CREATE:\n// MATCH (b:Booking {booking_id: 'book_zyx'}), (c:TrainCar {car_id: 'car_abc'})\n// CREATE (t:Ticket {ticket_id: 'tkt_1a2b', ...})-[:PART_OF_BOOKING]->(b), (t)-[:ASSIGNED_TO_CAR]->(c)\n// Node Label: :Staff\n// Properties:\n// staff_id: String (Constraint: UNIQUE)\n// first_name: String\n// last_name: String\n// role: String\n// employee_number: String (Constraint: UNIQUE)\n// hire_date: Date\n// contact_email: String (Constraint: UNIQUE, if not null)\n// contact_phone: String\n// is_active: Boolean\n// Relationship (Optional):\n// (:Staff)-[:BASED_AT]->(:Station)\n// Example Cypher CREATE:\n// CREATE (:Staff {staff_id: 'staff_mno', first_name: 'Bob', ...})\n// OPTIONAL MATCH (s:Station {station_id: 'station_xyz'}) // If primary_station_id exists\n// WITH s, staff_mno // Need to get the created staff node reference\n// WHERE s IS NOT NULL\n// CREATE (staff_mno)-[:BASED_AT]->(s)\n"} {"conversations": [{"role": "user", "content": "List all patients who have been diagnosed with chronic conditions, including their diagnosis descriptions and dates."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, d.description, d.diagnosis_date FROM healthcare.patients p JOIN healthcare.diagnoses d ON p.patient_id = d.patient_id WHERE d.is_chronic = true ORDER BY d.diagnosis_date DESC;"}, {"role": "user", "content": "Actually, I only need patients who were diagnosed in the last year."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, d.description, d.diagnosis_date FROM healthcare.patients p JOIN healthcare.diagnoses d ON p.patient_id = d.patient_id WHERE d.is_chronic = true AND d.diagnosis_date >= CURRENT_DATE - INTERVAL '1 year' ORDER BY d.diagnosis_date DESC;"}, {"role": "user", "content": "Can you also include the diagnosing doctor's last name?"}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, d.description, d.diagnosis_date, doc.last_name AS doctor_last_name FROM healthcare.patients p JOIN healthcare.diagnoses d ON p.patient_id = d.patient_id JOIN healthcare.doctors doc ON d.doctor_id = doc.doctor_id WHERE d.is_chronic = true AND d.diagnosis_date >= CURRENT_DATE - INTERVAL '1 year' ORDER BY d.diagnosis_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 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 (\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)\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 (\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.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)\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 all claims that were reported more than 30 days after the incident date."}, {"role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, incident_date, reported_date FROM insurance.claims WHERE DATEDIFF(reported_date, incident_date) > 30;"}, {"role": "user", "content": "Now show only claims that are still pending (status = 'pending')."}, {"role": "assistant", "content": "SELECT claim_id, policy_id, customer_id, incident_date, reported_date FROM insurance.claims WHERE DATEDIFF(reported_date, incident_date) > 30 AND status = 'pending';"}], "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, 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": [{"role": "user", "content": "Show me the first name, last name, and email for all clients registered in January 2023."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.clients WHERE EXTRACT(YEAR FROM date_registered) = 2023 AND EXTRACT(MONTH FROM date_registered) = 1;"}, {"role": "user", "content": "Only show those who have provided a phone number."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.clients WHERE EXTRACT(YEAR FROM date_registered) = 2023 AND EXTRACT(MONTH FROM date_registered) = 1 AND phone IS NOT NULL;"}, {"role": "user", "content": "Also, exclude any clients whose status is 'inactive'."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.clients WHERE EXTRACT(YEAR FROM date_registered) = 2023 AND EXTRACT(MONTH FROM date_registered) = 1 AND phone IS NOT NULL AND status != 'inactive';"}, {"role": "user", "content": "Order the results by last name, then first name."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.clients WHERE EXTRACT(YEAR FROM date_registered) = 2023 AND EXTRACT(MONTH FROM date_registered) = 1 AND phone IS NOT NULL AND status != 'inactive' ORDER BY last_name, first_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 legal_services.clients (\n client_id character varying(64) NOT NULL, -- unique identifier for the client\n first_name character varying(100) NOT NULL, -- client's first name\n last_name character varying(100) NOT NULL, -- client's last name\n company_name character varying(200), -- company name if applicable\n email character varying(128) UNIQUE NOT NULL, -- client's primary email\n phone character varying(32), -- client's contact phone number\n address text, -- client's full address\n date_registered timestamp NOT NULL, -- when the client was first registered\n status character varying(32) NOT NULL, -- client status (e.g., active, inactive, prospect)\n PRIMARY KEY (client_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show the number of staff members for each property, along with the property name."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(s.staff_id) AS staff_count\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.staff s ON p.property_id = s.property_id\nGROUP BY p.property_name;"}, {"role": "user", "content": "Only include properties with more than 20 staff members, and order the result by staff count descending."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(s.staff_id) AS staff_count\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.staff s ON p.property_id = s.property_id\nGROUP BY p.property_name\nHAVING COUNT(s.staff_id) > 20\nORDER BY 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.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.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)\n"} {"conversations": [{"role": "user", "content": "Find all nodes that were last seen in the last 30 days and have port numbers between 8000 and 9000."}, {"role": "assistant", "content": "SELECT node_id, ip_address, port FROM blockchain.nodes WHERE last_seen >= NOW() - INTERVAL '30 days' AND port BETWEEN 8000 AND 9000"}, {"role": "user", "content": "Can you also show the count of transactions sent from wallet addresses that share the same IP as these nodes?"}, {"role": "assistant", "content": "This query isn't possible with the current schema as there's no relationship between nodes IP addresses and wallet addresses."}, {"role": "user", "content": "Then just show me nodes that share the same IP address along with how many nodes share each IP."}, {"role": "assistant", "content": "SELECT ip_address, COUNT(*) as node_count FROM blockchain.nodes GROUP BY ip_address HAVING COUNT(*) > 1"}, {"role": "user", "content": "Now filter this to only show IP addresses with more than 3 nodes and include the earliest and latest last_seen timestamps."}, {"role": "assistant", "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"}], "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": [{"role": "user", "content": "List all users and the count of wallets they own."}, {"role": "assistant", "content": "SELECT u.username, COUNT(w.wallet_id) AS wallet_count FROM blockchain.users u JOIN blockchain.wallets w ON u.user_id = w.user_id GROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Filter the previous list to only include users who own more than 2 wallets."}, {"role": "assistant", "content": "SELECT u.username, COUNT(w.wallet_id) AS wallet_count FROM blockchain.users u JOIN blockchain.wallets w ON u.user_id = w.user_id GROUP BY u.user_id, u.username HAVING COUNT(w.wallet_id) > 2;"}, {"role": "user", "content": "Now, for those users, also include the total sum of balances across all addresses associated with their wallets."}, {"role": "assistant", "content": "SELECT u.username, COUNT(DISTINCT w.wallet_id) AS wallet_count, SUM(a.balance) AS total_balance FROM blockchain.users u JOIN blockchain.wallets w ON u.user_id = w.user_id JOIN blockchain.addresses a ON w.address_id = a.address_id GROUP BY u.user_id, u.username HAVING COUNT(DISTINCT w.wallet_id) > 2;"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.addresses ( address_id character varying(128) NOT NULL, public_key text NOT NULL, balance numeric(38,14) NOT NULL, PRIMARY KEY (address_id) )\nCREATE TABLE blockchain.nodes ( node_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (node_id) )\nCREATE TABLE blockchain.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address_id character varying(128) NOT NULL, private_key text NOT NULL, PRIMARY KEY (wallet_id) )\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": [{"role": "user", "content": "Give me the total number of reservations and the sum of total_amount by month for the year 2023."}, {"role": "assistant", "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": "user", "content": "Actually, I only want reservations with status 'CheckedOut' or 'Completed'."}, {"role": "assistant", "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;"}], "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": [{"role": "user", "content": "I need to identify pairs of verified documents submitted by the same citizen. For each pair, display the citizen_id, the earlier document_id with its verification timestamp, and the later document_id with its verification timestamp."}, {"role": "assistant", "content": "SELECT\n d1.citizen_id,\n d1.document_id AS earlier_document_id,\n d1.verification_timestamp AS earlier_verification,\n d2.document_id AS later_document_id,\n d2.verification_timestamp AS later_verification\nFROM government_services.documents d1\nJOIN government_services.documents d2\n ON d1.citizen_id = d2.citizen_id\n AND d1.verification_timestamp < d2.verification_timestamp\nWHERE d1.verification_status = 'Verified'\n AND d2.verification_status = 'Verified';"}], "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) )\n"} {"conversations": [{"role": "user", "content": "Show me the list of hashtags that have been used, along with the time they were first used."}, {"role": "assistant", "content": "SELECT tag_name, created_at \nFROM social_media.hashtags;"}], "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": [{"role": "user", "content": "Give me the number of patient insurance policies for each plan where the policy is currently active. Return plan_id and policy_count."}, {"role": "assistant", "content": "SELECT\n plan_id,\n COUNT(*) AS policy_count\nFROM healthcare.patient_insurance\nWHERE (expiration_date IS NULL OR expiration_date >= CURRENT_DATE)\nGROUP BY plan_id;"}, {"role": "user", "content": "Now, only include plans where the count is greater than 5 and sort by policy_count descending."}, {"role": "assistant", "content": "SELECT\n plan_id,\n COUNT(*) AS policy_count\nFROM healthcare.patient_insurance\nWHERE (expiration_date IS NULL OR expiration_date >= CURRENT_DATE)\nGROUP BY plan_id\nHAVING COUNT(*) > 5\nORDER BY policy_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 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": "Find employees who are managers and list the number of employees they directly manage. Show the manager's full name and the count of their direct reports."}, {"role": "assistant", "content": "SELECT m.first_name || ' ' || m.last_name AS manager_full_name, COUNT(e.employee_id) AS number_of_direct_reports FROM government_services.employees AS e JOIN government_services.employees AS m ON e.manager_employee_id = m.employee_id GROUP BY m.employee_id, manager_full_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 government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me the average market cap and average 24-hour price change percentage for tokens on each chain."}, {"role": "assistant", "content": "SELECT chain, AVG(market_cap) AS average_market_cap, AVG(price_change_percentage_24h) AS average_price_change_24h FROM token_basic_info GROUP BY chain;"}, {"role": "user", "content": "Now, only show chains where the average market cap is greater than 1,000,000,000."}, {"role": "assistant", "content": "SELECT chain, AVG(market_cap) AS average_market_cap, AVG(price_change_percentage_24h) AS average_price_change_24h FROM token_basic_info GROUP BY chain HAVING AVG(market_cap) > 1000000000;"}, {"role": "user", "content": "Also, order the results by average market cap in descending order."}, {"role": "assistant", "content": "SELECT chain, AVG(market_cap) AS average_market_cap, AVG(price_change_percentage_24h) AS average_price_change_24h FROM token_basic_info GROUP BY chain HAVING AVG(market_cap) > 1000000000 ORDER BY average_market_cap DESC;"}, {"role": "user", "content": "Can you also include the total number of tokens for each of these chains?"}, {"role": "assistant", "content": "SELECT chain, COUNT(*) AS number_of_tokens, AVG(market_cap) AS average_market_cap, AVG(price_change_percentage_24h) AS average_price_change_24h FROM token_basic_info GROUP BY chain HAVING AVG(market_cap) > 1000000000 ORDER BY average_market_cap DESC;"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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"} {"conversations": [{"role": "user", "content": "List each group conversation with its group name and the number of verified users who have posted in it."}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, COUNT(DISTINCT u.user_id) AS verified_posters\nFROM social_media.conversations c\nJOIN social_media.posts p ON p.location_lat IS NOT NULL -- Simulate posts linked to conversation (since no mapping, using location as a proxy)\nJOIN social_media.users u ON p.user_id = u.user_id AND u.is_verified = true\nWHERE c.is_group_chat = true\nGROUP BY c.conversation_id, c.group_name;"}, {"role": "user", "content": "Actually, only show groups created after May 1, 2024."}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, COUNT(DISTINCT u.user_id) AS verified_posters\nFROM social_media.conversations c\nJOIN social_media.posts p ON p.location_lat IS NOT NULL -- Simulate posts linked to conversation (since no mapping, using location as a proxy)\nJOIN social_media.users u ON p.user_id = u.user_id AND u.is_verified = true\nWHERE c.is_group_chat = true AND c.created_at > '2024-05-01'\nGROUP BY c.conversation_id, c.group_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 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.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\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.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": [{"role": "user", "content": "What is the total revenue generated for each department from delivered service orders? Return department and total_revenue."}, {"role": "assistant", "content": "SELECT s.department,\n SUM(so.total_price) AS total_revenue\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.services s ON so.service_id = s.service_id\nWHERE so.status = 'Delivered'\nGROUP BY s.department;"}, {"role": "user", "content": "Now limit to service orders delivered in the last month and only include departments with total_revenue > 1000."}, {"role": "assistant", "content": "SELECT s.department,\n SUM(so.total_price) AS total_revenue\nFROM hospitality_technology.service_orders so\nJOIN hospitality_technology.services s ON so.service_id = s.service_id\nWHERE so.status = 'Delivered'\n AND so.delivery_timestamp >= date_trunc('month', current_date - INTERVAL '1 month')\n AND so.delivery_timestamp < date_trunc('month', current_date)\nGROUP BY s.department\nHAVING SUM(so.total_price) > 1000;"}], "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 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 (\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 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.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 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.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 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": [{"role": "user", "content": "List pairs of maintenance logs for the same vehicle where the service date is the same, showing the log IDs and service types."}, {"role": "assistant", "content": "SELECT T1.log_id AS log_id_1, T1.service_type AS service_type_1, T2.log_id AS log_id_2, T2.service_type AS service_type_2, T1.vehicle_id, T1.service_date FROM transportation.maintenance_logs AS T1 JOIN transportation.maintenance_logs AS T2 ON T1.vehicle_id = T2.vehicle_id AND T1.service_date = T2.service_date AND T1.log_id < T2.log_id;"}, {"role": "user", "content": "Filter this list to only include pairs where at least one of the logs has a cost greater than 500."}, {"role": "assistant", "content": "SELECT T1.log_id AS log_id_1, T1.service_type AS service_type_1, T2.log_id AS log_id_2, T2.service_type AS service_type_2, T1.vehicle_id, T1.service_date FROM transportation.maintenance_logs AS T1 JOIN transportation.maintenance_logs AS T2 ON T1.vehicle_id = T2.vehicle_id AND T1.service_date = T2.service_date AND T1.log_id < T2.log_id WHERE T1.cost > 500 OR T2.cost > 500;"}], "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": "How many documents were uploaded in the year 2023?"}, {"role": "assistant", "content": "SELECT count(*) FROM government_services.documents WHERE date_part('year', upload_timestamp) = 2023;"}], "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) )\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 tokens by 24-hour trading volume on the Ethereum chain, along with their narrative and 7-day price change percentage."}, {"role": "assistant", "content": "SELECT t.token_symbol, t.narrative, t.price_change_percentage_7d FROM token_basic_info t WHERE t.chain = 'Ethereum' ORDER BY CAST(t.total_volume AS numeric) DESC LIMIT 5;"}, {"role": "user", "content": "Can you also include their liquidity from the token_dexpool_info table?"}, {"role": "assistant", "content": "SELECT t.token_symbol, t.narrative, t.price_change_percentage_7d, d.liquidity FROM token_basic_info t JOIN token_dexpool_info d ON t.token_symbol = d.token_symbol AND t.chain = d.chain WHERE t.chain = 'Ethereum' ORDER BY CAST(t.total_volume AS numeric) 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 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, -- 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) )\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) )\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) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n"} {"conversations": [{"role": "user", "content": "List all ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses."}, {"role": "assistant", "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": "user", "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": "assistant", "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": "user", "content": "That doesn't seem right either. Let's just get the basic ERC20 token information without price filtering for now."}, {"role": "assistant", "content": "SELECT name, symbol, contract_address FROM token_metas WHERE is_erc20 = 1 LIMIT 100;"}], "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": [{"role": "user", "content": "List all pairs of token transfers where the sender is the same but the recipients differ. Show both transfer IDs and the common sender address."}, {"role": "assistant", "content": "SELECT t1.transfer_id AS transfer_id_1, t2.transfer_id AS transfer_id_2, t1.from_address AS common_from_address\nFROM web3.token_transfers t1\nJOIN web3.token_transfers t2\n ON t1.from_address = t2.from_address\n AND t1.to_address <> t2.to_address\n AND t1.transfer_id < t2.transfer_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.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": [{"role": "user", "content": "Show each contract's address along with the total number of events it has emitted and the total number of transactions sent to it."}, {"role": "assistant", "content": "SELECT\n c.address,\n COUNT(e.event_id) AS event_count,\n COUNT(t.transaction_id) AS tx_count\nFROM web3.contracts c\nLEFT JOIN web3.events e\n ON c.contract_id = e.contract_id\nLEFT JOIN web3.transactions t\n ON c.address = t.to_address\nGROUP BY c.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 web3.contracts (\n contract_id character varying(64) NOT NULL, -- unique identifier for the contract\n address character varying(128) NOT NULL, -- address of the deployed contract\n abi text NOT NULL, -- application binary interface of the contract\n bytecode text NOT NULL, -- bytecode of the contract\n deployer_address character varying(128) NOT NULL, -- address of the deployer\n deployed_at timestamp NOT NULL, -- time when the contract was deployed\n network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed\n status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)\n PRIMARY KEY (contract_id)\n)\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 (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128), -- address of the receiver (can be null for contract deployment)\n value numeric(38,14) NOT NULL, -- value transferred\n gas_used integer NOT NULL, -- amount of gas used by the transaction\n gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction\n block_number integer NOT NULL, -- block number containing the transaction\n timestamp timestamp NOT NULL, -- time when the transaction was mined\n input_data text, -- input data of the transaction (can be null)\n status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)\n nonce integer NOT NULL, -- nonce of the sender at the time of the transaction\n PRIMARY KEY (transaction_id)\n)\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.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": "What is the detailed repair history of the equipment used by the staff with staff_id 'STAFF123' during maintenance tasks?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information on the detailed repair history of equipment used by staff members. The data in the maintenance_records table only includes information about maintenance tasks, such as record_id, asset_id, maintenance type, and staff_id, but does not cover equipment repair histories."}], "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, 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": [{"role": "user", "content": "Show me all users who have placed orders but have no trades, along with their order count and average order quantity."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(o.order_id) AS order_count, AVG(o.quantity) AS avg_order_quantity FROM trading_platform.users u JOIN trading_platform.orders o ON u.user_id = o.user_id LEFT JOIN trading_platform.trades t ON o.order_id = t.order_id WHERE t.trade_id IS NULL GROUP BY u.user_id, u.email"}, {"role": "user", "content": "Now modify the query to only include users who have placed more than 3 orders and show their earliest order date."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(o.order_id) AS order_count, AVG(o.quantity) AS avg_order_quantity, MIN(o.created_at) AS earliest_order_date FROM trading_platform.users u JOIN trading_platform.orders o ON u.user_id = o.user_id LEFT JOIN trading_platform.trades t ON o.order_id = t.order_id WHERE t.trade_id IS NULL GROUP BY u.user_id, u.email HAVING COUNT(o.order_id) > 3"}, {"role": "user", "content": "Actually, I want to see these results grouped by order_type as well, and only for buy orders."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, o.order_type, COUNT(o.order_id) AS order_count, AVG(o.quantity) AS avg_order_quantity, MIN(o.created_at) AS earliest_order_date FROM trading_platform.users u JOIN trading_platform.orders o ON u.user_id = o.user_id LEFT JOIN trading_platform.trades t ON o.order_id = t.order_id WHERE t.trade_id IS NULL AND o.order_type = 'buy' GROUP BY u.user_id, u.email, o.order_type HAVING COUNT(o.order_id) > 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 trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\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 ( 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.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.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\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.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": "user", "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": "assistant", "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;"}], "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": "Show me the top 5 users who have interacted with DApps, along with the count of distinct DApps they interacted with and their wallet addresses."}, {"role": "assistant", "content": "SELECT w.user_id, COUNT(DISTINCT d.dapp_id) AS dapp_count, w.address FROM trading_platform.wallets w JOIN trading_platform.dapps d ON 1=1 GROUP BY w.user_id, w.address ORDER BY dapp_count DESC LIMIT 5;"}, {"role": "user", "content": "This query doesn't properly show DApp interactions. Please modify it to correctly join with a table that records user-DApp interactions."}, {"role": "assistant", "content": "I notice there's no interaction table in the provided schema. Without a table recording user-DApp interactions, I cannot generate this query accurately. Would you like to see users who have wallets and DApps separately instead?"}, {"role": "user", "content": "You're right. Instead, show me users who have wallets but have never interacted with any DApps, along with their wallet addresses."}, {"role": "assistant", "content": "SELECT w.user_id, w.address FROM trading_platform.wallets w WHERE NOT EXISTS (SELECT 1 FROM trading_platform.dapps d WHERE 1=1) GROUP BY w.user_id, w.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.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\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.text, name.text, symbol.text, type.text )\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.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) )\n"} {"conversations": [{"role": "user", "content": "Retrieve all beneficiaries with their policy numbers, including beneficiary first and last name, relationship, and the policy end date."}, {"role": "assistant", "content": "SELECT pb.beneficiary_id, pb.first_name, pb.last_name, pb.relationship, p.policy_number, p.end_date\nFROM insurance.policy_beneficiaries pb\nJOIN insurance.policies p ON pb.policy_id = p.policy_id;"}, {"role": "user", "content": "Actually, I only need beneficiaries whose percentage share is greater than 20% and sorted by percentage share in descending order."}, {"role": "assistant", "content": "SELECT pb.beneficiary_id, pb.first_name, pb.last_name, pb.relationship, p.policy_number, p.end_date, pb.percentage_share\nFROM insurance.policy_beneficiaries pb\nJOIN insurance.policies p ON pb.policy_id = p.policy_id\nWHERE pb.percentage_share > 20\nORDER BY pb.percentage_share DESC;"}, {"role": "user", "content": "Also include the policy status and only show records where the policy is still active."}, {"role": "assistant", "content": "SELECT pb.beneficiary_id, pb.first_name, pb.last_name, pb.relationship, p.policy_number, p.end_date, p.status AS policy_status, pb.percentage_share\nFROM insurance.policy_beneficiaries pb\nJOIN insurance.policies p ON pb.policy_id = p.policy_id\nWHERE pb.percentage_share > 20\n AND p.status = 'Active'\nORDER BY pb.percentage_share DESC;"}, {"role": "user", "content": "Limit the results to the top 5 beneficiaries."}, {"role": "assistant", "content": "SELECT pb.beneficiary_id, pb.first_name, pb.last_name, pb.relationship, p.policy_number, p.end_date, p.status AS policy_status, pb.percentage_share\nFROM insurance.policy_beneficiaries pb\nJOIN insurance.policies p ON pb.policy_id = p.policy_id\nWHERE pb.percentage_share > 20\n AND p.status = 'Active'\nORDER BY pb.percentage_share 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 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.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, 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, 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": "For each claim, show the corresponding product_type of the insurance product for the related policy."}, {"role": "assistant", "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": "user", "content": "Sorry, there is no policies table, I got an error. Can you try joining claims to insurance_products another way?"}, {"role": "assistant", "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;"}], "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": [{"role": "user", "content": "Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens with decimals equal to 18."}, {"role": "assistant", "content": "SELECT name, contract_address, total_supply FROM token_metas WHERE is_erc20 = 1 AND decimals = 18 ORDER BY CAST(total_supply AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Can you join this with the token_prices table to include the current price of each token?"}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply, tp.price FROM token_metas tm JOIN token_prices tp ON tm.contract_address = tp.address WHERE tm.is_erc20 = 1 AND tm.decimals = 18 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Now filter these results to only show tokens where the price is greater than $0.1."}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply, tp.price FROM token_metas tm JOIN token_prices tp ON tm.contract_address = tp.address WHERE tm.is_erc20 = 1 AND tm.decimals = 18 AND tp.price > 0.1 ORDER BY CAST(tm.total_supply AS decimal) 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 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 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_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\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, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\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 (\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 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(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, 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 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_info_bitcoin (\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(255) NOT NULL, -- Ticker: Identifier of the inscription\n max_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n lim decimal(38,0) NOT NULL, -- Mint limit: limit per inscription\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_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 (\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)\n"} {"conversations": [{"role": "user", "content": "Show me all active policies for customers who live in California, along with their total premium payments made so far."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount;"}, {"role": "user", "content": "I also want to see how many claims each of these policies has had."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made, COUNT(cl.claim_id) AS claim_count FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id LEFT JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount;"}, {"role": "user", "content": "Actually, I only want to see policies that have at least one claim."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made, COUNT(cl.claim_id) AS claim_count FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount HAVING COUNT(cl.claim_id) > 0;"}, {"role": "user", "content": "Now show me the average settlement amount for these policies' claims."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made, COUNT(cl.claim_id) AS claim_count, AVG(cl.settlement_amount) AS avg_settlement FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount HAVING COUNT(cl.claim_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 (\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 (\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.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)\n"} {"conversations": [{"role": "user", "content": "Provide a count of citizens registered per calendar year."}, {"role": "assistant", "content": "SELECT CAST(EXTRACT(YEAR FROM registration_date) AS INTEGER) AS registration_year, COUNT(*) AS citizen_count FROM government_services.citizens GROUP BY 1 ORDER BY 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 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": [{"role": "user", "content": "Which chain has the highest total USD inflow from buy transactions (type=1), and how many distinct tokens were involved in that inflow?"}, {"role": "assistant", "content": "SELECT chain, SUM(usd_value) AS total_inflow, COUNT(DISTINCT token_symbol) AS distinct_tokens\nFROM smart_money_token_inflow\nWHERE type = 1\nGROUP BY chain\nORDER BY total_inflow DESC\nLIMIT 1;"}, {"role": "user", "content": "I also want to see the average price at which those tokens were bought for that chain."}, {"role": "assistant", "content": "WITH inflow AS (\n SELECT chain, SUM(usd_value) AS total_inflow\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY chain\n), top_chain AS (\n SELECT chain FROM inflow ORDER BY total_inflow DESC LIMIT 1\n)\nSELECT i.chain, AVG(i.avg_price) AS avg_buy_price\nFROM smart_money_token_inflow i\nJOIN top_chain t ON i.chain = t.chain\nWHERE i.type = 1;"}, {"role": "user", "content": "Actually, filter to narratives where the total USD inflow is above 50000."}, {"role": "assistant", "content": "SELECT narrative, SUM(usd_value) AS total_inflow, COUNT(DISTINCT token_symbol) AS distinct_tokens\nFROM smart_money_token_inflow\nWHERE type = 1\nGROUP BY narrative\nHAVING SUM(usd_value) > 50000;"}, {"role": "user", "content": "Please order the results by average price descending and show the top 2 chains."}, {"role": "assistant", "content": "SELECT chain, SUM(usd_value) AS total_inflow, COUNT(DISTINCT token_symbol) AS distinct_tokens, AVG(avg_price) AS avg_buy_price\nFROM smart_money_token_inflow\nWHERE type = 1\nGROUP BY chain\nORDER BY avg_buy_price DESC\nLIMIT 2;"}], "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_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": [{"role": "user", "content": "List the ERC20 tokens (from token_metas) with exactly 6 decimals. Show their symbol, contract_address, and name."}, {"role": "assistant", "content": "SELECT symbol, contract_address, name FROM token_metas WHERE is_erc20 = 1 AND decimals = 6;"}, {"role": "user", "content": "Can you also include the total current supply for each token?"}, {"role": "assistant", "content": "SELECT symbol, contract_address, name, total_supply FROM token_metas WHERE is_erc20 = 1 AND decimals = 6;"}, {"role": "user", "content": "Now, join with token_prices_latest to also include the latest price for each token."}, {"role": "assistant", "content": "SELECT tm.symbol, tm.contract_address, tm.name, tm.total_supply, tpl.price AS latest_price\nFROM token_metas tm\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nWHERE tm.is_erc20 = 1 AND tm.decimals = 6;"}, {"role": "user", "content": "Only include tokens where the latest price is between 0.5 and 2.0 USD, and limit the result to the top 5 tokens by price descending."}, {"role": "assistant", "content": "SELECT tm.symbol, tm.contract_address, tm.name, tm.total_supply, tpl.price AS latest_price\nFROM token_metas tm\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nWHERE tm.is_erc20 = 1 AND tm.decimals = 6 AND tpl.price BETWEEN 0.5 AND 2.0\nORDER BY tpl.price 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.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 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 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 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 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 (\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_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, 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 (\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(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\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 ( 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": [{"role": "user", "content": "Count the number of logs for each action type."}, {"role": "assistant", "content": "SELECT action,\n COUNT(*) AS count\nFROM trading_platform.logs\nGROUP BY action;"}], "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.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me all asset types along with the count of distinct assets and the count of log actions for each type."}, {"role": "assistant", "content": "SELECT a.type, COUNT(DISTINCT a.asset_id) AS asset_count, COUNT(l.log_id) AS action_count FROM trading_platform.assets a LEFT JOIN trading_platform.logs l ON a.asset_id = l.details->>'asset_id' GROUP BY a.type ORDER BY action_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 trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.logs ( log_id text, user_id text, action text, details text, logged_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List trips where the actual arrival was earlier than the scheduled arrival, including the trip ID, scheduled and actual arrival times, and the vehicle make and model used."}, {"role": "assistant", "content": "SELECT T1.trip_id, T1.scheduled_arrival, T1.actual_arrival, T2.make, T2.model FROM transportation.trips AS T1 JOIN transportation.vehicles AS T2 ON T1.vehicle_id = T2.vehicle_id WHERE T1.actual_arrival IS NOT NULL AND T1.actual_arrival < T1.scheduled_arrival;"}, {"role": "user", "content": "For those early trips, also include the route number and description and sort by the arrival time difference in descending order."}, {"role": "assistant", "content": "SELECT T1.trip_id, T1.scheduled_arrival, T1.actual_arrival, T2.make, T2.model, T3.route_number, T3.description, EXTRACT(EPOCH FROM (T1.scheduled_arrival - T1.actual_arrival)) / 60 AS early_arrival_minutes FROM transportation.trips AS T1 JOIN transportation.vehicles AS T2 ON T1.vehicle_id = T2.vehicle_id LEFT JOIN transportation.routes AS T3 ON T1.route_id = T3.route_id WHERE T1.actual_arrival IS NOT NULL AND T1.actual_arrival < T1.scheduled_arrival ORDER BY early_arrival_minutes 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 (\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.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)\n"} {"conversations": [{"role": "user", "content": "Can you show me all prescriptions along with each patient's policy number and insurance plan ID?"}, {"role": "assistant", "content": "SELECT p.prescription_id, p.patient_id, p.medication_id, pi.policy_number, pi.plan_id\nFROM healthcare.prescriptions p\nJOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id;"}, {"role": "user", "content": "Actually, only show prescriptions for patients whose insurance policy is still active today."}, {"role": "assistant", "content": "SELECT p.prescription_id, p.patient_id, p.medication_id, pi.policy_number, pi.plan_id\nFROM healthcare.prescriptions p\nJOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id\nWHERE pi.effective_date <= CURRENT_DATE AND (pi.expiration_date IS NULL OR pi.expiration_date >= CURRENT_DATE);"}, {"role": "user", "content": "Only include those policies marked as primary and order by prescription_date descending."}, {"role": "assistant", "content": "SELECT p.prescription_id, p.patient_id, p.medication_id, pi.policy_number, pi.plan_id\nFROM healthcare.prescriptions p\nJOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id\nWHERE pi.effective_date <= CURRENT_DATE\n AND (pi.expiration_date IS NULL OR pi.expiration_date >= CURRENT_DATE)\n AND pi.is_primary = TRUE\nORDER BY p.prescription_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 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": "List all vehicles that use diesel fuel, showing their make, model, and year."}, {"role": "assistant", "content": "SELECT make, model, year FROM transportation.vehicles WHERE fuel_type = 'diesel';"}, {"role": "user", "content": "Now include only vehicles acquired in the last 5 years."}, {"role": "assistant", "content": "SELECT make, model, year FROM transportation.vehicles WHERE fuel_type = 'diesel' AND acquisition_date >= CURRENT_DATE - INTERVAL '5 years';"}, {"role": "user", "content": "Can you also show their status and order the results by year in descending order?"}, {"role": "assistant", "content": "SELECT make, model, year, status FROM transportation.vehicles WHERE fuel_type = 'diesel' AND acquisition_date >= CURRENT_DATE - INTERVAL '5 years' ORDER BY year DESC;"}, {"role": "user", "content": "Actually, I only want to see active vehicles in this list."}, {"role": "assistant", "content": "SELECT make, model, year, status FROM transportation.vehicles WHERE fuel_type = 'diesel' AND acquisition_date >= CURRENT_DATE - INTERVAL '5 years' AND status = 'active' ORDER BY year 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 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 )\n"} {"conversations": [{"role": "user", "content": "Which customers have policies that expired in the last month? Please show the customer ID, policy number, and expiration date."}, {"role": "assistant", "content": "SELECT c.customer_id, p.policy_number, p.end_date\nFROM insurance.customers c\nJOIN insurance.policies p ON c.customer_id = p.customer_id\nWHERE p.end_date >= (CURRENT_DATE - INTERVAL '1 month') AND p.end_date < CURRENT_DATE;"}, {"role": "user", "content": "Add the customer's email to the results."}, {"role": "assistant", "content": "SELECT c.customer_id, c.email, p.policy_number, p.end_date\nFROM insurance.customers c\nJOIN insurance.policies p ON c.customer_id = p.customer_id\nWHERE p.end_date >= (CURRENT_DATE - INTERVAL '1 month') AND p.end_date < CURRENT_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 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.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 ( 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 )\n"} {"conversations": [{"role": "user", "content": "Can you show the total quantity of all in-game items held by each player?"}, {"role": "assistant", "content": "SELECT player_id, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id;"}, {"role": "user", "content": "I'd like to see only players whose total quantity is over 20."}, {"role": "assistant", "content": "SELECT player_id, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20;"}, {"role": "user", "content": "Also, can you include the number of different unique items each player owns?"}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT item_id) AS unique_items, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20;"}, {"role": "user", "content": "Order the final result by unique_items descending, then by total_quantity descending."}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT item_id) AS unique_items, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20\nORDER BY unique_items DESC, total_quantity 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_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": [{"role": "user", "content": "Show the names and types of all assets whose symbol is exactly 3 characters long."}, {"role": "assistant", "content": "SELECT name, type, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3;"}, {"role": "user", "content": "Also, I want to order the results alphabetically by asset name."}, {"role": "assistant", "content": "SELECT name, type, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3 ORDER BY name ASC;"}, {"role": "user", "content": "Actually, can you only show assets of type 'token' in the result?"}, {"role": "assistant", "content": "SELECT name, type, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3 AND type = 'token' ORDER BY name ASC;"}, {"role": "user", "content": "Now, just return the asset name and symbol for these tokens, sorted by symbol descending."}, {"role": "assistant", "content": "SELECT name, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3 AND type = 'token' ORDER BY symbol 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.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )\n"} {"conversations": [{"role": "user", "content": "For each game, show the game title, the total duration of all sessions in seconds, and the average score."}, {"role": "assistant", "content": "SELECT g.title, SUM(gs.duration_seconds) AS total_duration_seconds, AVG(gs.score) AS average_score FROM gaming_technology.games g JOIN gaming_technology.game_sessions gs ON g.game_id = gs.game_id GROUP BY g.game_id, g.title;"}, {"role": "user", "content": "Could you also show the total number of sessions for each game?"}, {"role": "assistant", "content": "SELECT g.title, COUNT(gs.session_id) AS total_sessions, SUM(gs.duration_seconds) AS total_duration_seconds, AVG(gs.score) AS average_score FROM gaming_technology.games g JOIN gaming_technology.game_sessions gs ON g.game_id = gs.game_id GROUP BY g.game_id, g.title;"}, {"role": "user", "content": "Filter the results to only include games with more than 100 sessions."}, {"role": "assistant", "content": "SELECT g.title, COUNT(gs.session_id) AS total_sessions, SUM(gs.duration_seconds) AS total_duration_seconds, AVG(gs.score) AS average_score FROM gaming_technology.games g JOIN gaming_technology.game_sessions gs ON g.game_id = gs.game_id GROUP BY g.game_id, g.title HAVING COUNT(gs.session_id) > 100;"}], "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 )\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.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\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_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": [{"role": "user", "content": "Find all smart contracts where the code length is greater than 1000 characters."}, {"role": "assistant", "content": "SELECT contract_id, creator_address, LENGTH(code) AS code_length FROM blockchain.smart_contracts WHERE LENGTH(code) > 1000;"}, {"role": "user", "content": "Now group these by creator_address and show the count of such contracts per creator."}, {"role": "assistant", "content": "SELECT creator_address, COUNT(*) AS large_code_contract_count FROM blockchain.smart_contracts WHERE LENGTH(code) > 1000 GROUP BY creator_address;"}, {"role": "user", "content": "Can you order the results by the count in descending order?"}, {"role": "assistant", "content": "SELECT creator_address, COUNT(*) AS large_code_contract_count FROM blockchain.smart_contracts WHERE LENGTH(code) > 1000 GROUP BY creator_address ORDER BY large_code_contract_count DESC;"}, {"role": "user", "content": "Now show only creators who have more than 3 such contracts."}, {"role": "assistant", "content": "SELECT creator_address, COUNT(*) AS large_code_contract_count FROM blockchain.smart_contracts WHERE LENGTH(code) > 1000 GROUP BY creator_address HAVING COUNT(*) > 3 ORDER BY large_code_contract_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.smart_contracts ( contract_id.text, creator_address.text, code.text, timestamp.timestamp )\n"} {"conversations": [{"role": "user", "content": "I need a report of patients who have received prescriptions for medications manufactured by 'Pfizer'. Include patient ID, first name, last name, medication_name, and prescription_date."}, {"role": "assistant", "content": "SELECT p.patient_id,\n p.first_name,\n p.last_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.patients AS p\nJOIN healthcare.prescriptions AS pr ON p.patient_id = pr.patient_id\nJOIN healthcare.medications AS m ON pr.medication_id = m.medication_id\nWHERE m.manufacturer = 'Pfizer';"}, {"role": "user", "content": "Actually, only include prescriptions with a dosage containing 'mg' and sort by prescription_date descending."}, {"role": "assistant", "content": "SELECT p.patient_id,\n p.first_name,\n p.last_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.patients AS p\nJOIN healthcare.prescriptions AS pr ON p.patient_id = pr.patient_id\nJOIN healthcare.medications AS m ON pr.medication_id = m.medication_id\nWHERE m.manufacturer = 'Pfizer'\n AND pr.dosage ILIKE '%mg%'\nORDER BY pr.prescription_date DESC;"}, {"role": "user", "content": "Also, include the patient's primary insurance policy number and plan name in the report."}, {"role": "assistant", "content": "SELECT p.patient_id,\n p.first_name,\n p.last_name,\n m.medication_name,\n pr.prescription_date,\n pi.policy_number,\n ip.plan_name\nFROM healthcare.patients AS p\nJOIN healthcare.prescriptions AS pr ON p.patient_id = pr.patient_id\nJOIN healthcare.medications AS m ON pr.medication_id = m.medication_id\nJOIN healthcare.patient_insurance AS pi\n ON p.patient_id = pi.patient_id AND pi.is_primary = true\nJOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id\nWHERE m.manufacturer = 'Pfizer'\n AND pr.dosage ILIKE '%mg%'\nORDER BY pr.prescription_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 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": "Find all appointments at location_id 'LOC123' where the reason contains 'follow-up' and the status is 'Scheduled', showing appointment_time and patient_id."}, {"role": "assistant", "content": "SELECT appointment_time, patient_id FROM healthcare.appointments WHERE location_id = 'LOC123' AND reason LIKE '%follow-up%' AND status = 'Scheduled';"}], "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": "Show me the count of notifications sent for each channel for applications submitted after January 1, 2024."}, {"role": "assistant", "content": "SELECT n.channel, COUNT(*) AS notification_count\nFROM government_services.notifications n\nJOIN government_services.applications a ON n.application_id = a.application_id\nWHERE a.submitted_at > '2024-01-01'\nGROUP BY n.channel;"}, {"role": "user", "content": "Now, only include channels that have sent more than 10 notifications."}, {"role": "assistant", "content": "SELECT n.channel, COUNT(*) AS notification_count\nFROM government_services.notifications n\nJOIN government_services.applications a ON n.application_id = a.application_id\nWHERE a.submitted_at > '2024-01-01'\nGROUP BY n.channel\nHAVING COUNT(*) > 10;"}, {"role": "user", "content": "Exclude notifications with the status 'Failed'."}, {"role": "assistant", "content": "SELECT n.channel, COUNT(*) AS notification_count\nFROM government_services.notifications n\nJOIN government_services.applications a ON n.application_id = a.application_id\nWHERE a.submitted_at > '2024-01-01' AND n.status != 'Failed'\nGROUP BY n.channel\nHAVING COUNT(*) > 10;"}, {"role": "user", "content": "Show for 2023 instead of 2024."}, {"role": "assistant", "content": "SELECT n.channel, COUNT(*) AS notification_count\nFROM government_services.notifications n\nJOIN government_services.applications a ON n.application_id = a.application_id\nWHERE a.submitted_at >= '2023-01-01' AND a.submitted_at < '2024-01-01' AND n.status != 'Failed'\nGROUP BY n.channel\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 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": "List each property_name and the count of available rooms."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(*) AS available_rooms_count\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.properties p\n ON r.property_id = p.property_id\nWHERE r.status = 'Available'\nGROUP BY p.property_name;"}, {"role": "user", "content": "Actually, only include rooms where last_cleaned_at is more than 7 days ago."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(*) AS available_rooms_count\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.properties p\n ON r.property_id = p.property_id\nWHERE r.status = 'Available'\n AND r.last_cleaned_at < now() - INTERVAL '7 days'\nGROUP BY p.property_name;"}, {"role": "user", "content": "Also include the most recent last_cleaned_at date for each property."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(*) AS available_rooms_count,\n MAX(r.last_cleaned_at) AS most_recent_cleaned_at\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.properties p\n ON r.property_id = p.property_id\nWHERE r.status = 'Available'\n AND r.last_cleaned_at < now() - INTERVAL '7 days'\nGROUP BY 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 ( 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.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) )\n"} {"conversations": [{"role": "user", "content": "List all room types that have at least one service in the 'Spa' category, including the room type name, property name, and service name."}, {"role": "assistant", "content": "SELECT DISTINCT rt.type_name, p.property_name, s.service_name\nFROM hospitality_technology.room_types AS rt\nJOIN hospitality_technology.properties AS p ON rt.property_id = p.property_id\nJOIN hospitality_technology.services AS s ON rt.property_id = s.property_id\nWHERE s.category = 'Spa';"}, {"role": "user", "content": "Actually, only show room types with a base_rate above 200."}, {"role": "assistant", "content": "SELECT DISTINCT rt.type_name, p.property_name, s.service_name\nFROM hospitality_technology.room_types AS rt\nJOIN hospitality_technology.properties AS p ON rt.property_id = p.property_id\nJOIN hospitality_technology.services AS s ON rt.property_id = s.property_id\nWHERE s.category = 'Spa'\n AND rt.base_rate > 200;"}, {"role": "user", "content": "Also sort the results by base_rate descending and limit to 10."}, {"role": "assistant", "content": "SELECT DISTINCT rt.type_name, p.property_name, s.service_name\nFROM hospitality_technology.room_types AS rt\nJOIN hospitality_technology.properties AS p ON rt.property_id = p.property_id\nJOIN hospitality_technology.services AS s ON rt.property_id = s.property_id\nWHERE s.category = 'Spa'\n AND rt.base_rate > 200\nORDER BY rt.base_rate 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 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.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.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\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 )\n"} {"conversations": [{"role": "user", "content": "Can you help me retrieve the inventory details for a specific component ID, including the quantity and warehouse location?"}, {"role": "assistant", "content": "HGETALL inv:"}, {"role": "user", "content": "Can you also include the batch number for that inventory record?"}, {"role": "assistant", "content": "HGETALL inv:"}, {"role": "user", "content": "If I want to check the expiry date for this component, how can I retrieve that information?"}, {"role": "assistant", "content": "ZRANGE component_expiry: 0 -1 WITHSCORES"}, {"role": "user", "content": "Can you filter the results to show only inventory records with an expiry date after a specific timestamp?"}, {"role": "assistant", "content": "ZRANGEBYSCORE component_expiry: +inf WITHSCORES"}], "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: 'inv:'. Example: HSET inv:INVREC500 component_id \"component:WINGBOLT\" quantity 5000 location_warehouse \"WH3\" batch_number \"BCH778899\" ... Consider Sorted Set by expiry date: ZADD component_expiry: .\n"} {"conversations": [{"role": "user", "content": "Show me the post ID, content, and creation time for all posts made by user 'user789'."}, {"role": "assistant", "content": "SELECT post_id, content, created_at FROM social_media.posts WHERE user_id = 'user789';"}, {"role": "user", "content": "Modify that to only include posts with media attachments and order by creation time descending."}, {"role": "assistant", "content": "SELECT post_id, content, created_at FROM social_media.posts WHERE user_id = 'user789' AND media_url IS NOT NULL 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 social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) )\n"} {"conversations": [{"role": "user", "content": "For each player, list their username and the total number of unique servers they have played on, only including players who have played on two or more different servers. Also show the titles of all games they've played sessions on."}, {"role": "assistant", "content": "SELECT p.username, COUNT(DISTINCT gs.server_id) AS unique_servers, STRING_AGG(DISTINCT g.title, ', ') AS game_titles\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nJOIN gaming_technology.servers s ON gs.server_id = s.server_id\nJOIN gaming_technology.games g ON gs.game_id = g.game_id\nWHERE gs.server_id IS NOT NULL\nGROUP BY p.player_id\nHAVING COUNT(DISTINCT gs.server_id) >= 2;"}, {"role": "user", "content": "Add another column for the total duration in seconds that each player has spent on these servers."}, {"role": "assistant", "content": "SELECT p.username, COUNT(DISTINCT gs.server_id) AS unique_servers, STRING_AGG(DISTINCT g.title, ', ') AS game_titles, SUM(gs.duration_seconds) AS total_duration_seconds\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nJOIN gaming_technology.servers s ON gs.server_id = s.server_id\nJOIN gaming_technology.games g ON gs.game_id = g.game_id\nWHERE gs.server_id IS NOT NULL\nGROUP BY p.player_id\nHAVING COUNT(DISTINCT gs.server_id) >= 2;"}], "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": [{"role": "user", "content": "I want to list all insurance plans along with the number of medical records that have a record_date in 2024. Display plan_id, plan_name, and the total medical records."}, {"role": "assistant", "content": "SELECT ip.plan_id, ip.plan_name, COUNT(mr.record_id) AS total_medical_records\nFROM healthcare.insurance_plans ip\nLEFT JOIN healthcare.medical_records mr ON 1=0 -- there is no direct relationship in schema, so no records will be counted\nWHERE mr.record_date >= '2024-01-01' AND mr.record_date < '2025-01-01'\nGROUP BY ip.plan_id, ip.plan_name;"}, {"role": "user", "content": "Since there's no direct relationship, can you adjust it to just show all insurance plans of type 'EPO' with their plan_id and plan_name?"}, {"role": "assistant", "content": "SELECT plan_id, plan_name\nFROM healthcare.insurance_plans\nWHERE plan_type = 'EPO';"}], "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": [{"role": "user", "content": "Show the total file size in bytes for all documents uploaded with a MIME type of 'application/pdf'."}, {"role": "assistant", "content": "SELECT SUM(file_size_bytes) FROM insurance.claim_documents WHERE mime_type = 'application/pdf'"}], "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 )\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": [{"role": "user", "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": "assistant", "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;"}], "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": [{"role": "user", "content": "List all wallet addresses that have unspent UTXOs with amounts greater than 100, along with the total unspent amount for each address."}, {"role": "assistant", "content": "SELECT w.address, SUM(u.amount) AS total_unspent FROM trading_platform.wallets w JOIN trading_platform.utxos u ON w.address = u.address WHERE u.spent = false AND u.amount > 100 GROUP BY w.address;"}, {"role": "user", "content": "Now modify the query to only include wallets created in the last year."}, {"role": "assistant", "content": "SELECT w.address, SUM(u.amount) AS total_unspent FROM trading_platform.wallets w JOIN trading_platform.utxos u ON w.address = u.address WHERE u.spent = false AND u.amount > 100 AND w.created_at >= NOW() - INTERVAL '1 year' GROUP BY w.address;"}, {"role": "user", "content": "I notice the query has a typo in 'INTERVAL'. Also, can you include the user's email address in the results?"}, {"role": "assistant", "content": "SELECT w.address, u.email, SUM(ut.amount) AS total_unspent FROM trading_platform.wallets w JOIN trading_platform.users u ON w.user_id = u.user_id JOIN trading_platform.utxos ut ON w.address = ut.address WHERE ut.spent = false AND ut.amount > 100 AND w.created_at >= NOW() - INTERVAL '1 year' GROUP BY w.address, u.email;"}], "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 ( 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 ( 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.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List all Sui NFT collections where the owner is not null, including their name and collection_type."}, {"role": "assistant", "content": "SELECT name, collection_type FROM sui_nfts WHERE owner IS NOT NULL;"}, {"role": "user", "content": "Can you filter these results to only show collections with 'art' in their collection_type and add the display field?"}, {"role": "assistant", "content": "SELECT name, collection_type, display FROM sui_nfts WHERE owner IS NOT NULL AND collection_type LIKE '%art%';"}, {"role": "user", "content": "Now sort these results by name in ascending order and limit to the top 10."}, {"role": "assistant", "content": "SELECT name, collection_type, display FROM sui_nfts WHERE owner IS NOT NULL AND collection_type LIKE '%art%' ORDER BY name ASC 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 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 ( 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 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 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 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 )\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": [{"role": "user", "content": "What is the count of customers for each state where the status is 'Active' and the created_at date is within the last 3 months?"}, {"role": "assistant", "content": "SELECT state, COUNT(*) as customer_count FROM financial_services.customers WHERE status = 'Active' AND created_at >= CURRENT_DATE - INTERVAL '3 months' GROUP BY state;"}], "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 )\n"} {"conversations": [{"role": "user", "content": "Find projects that completed a fundraising round in 2023 and have a corresponding token listed in the smart money performance data. Show the project name, fundraising amount, token symbol, and the token's smart money ROI."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.investment_value, smtp.token_symbol, smtp.roi FROM project_fundraising_record pfr JOIN smart_money_token_performance smtp ON pfr.project_name ILIKE '%' || smtp.token_symbol || '%' WHERE pfr.investment_date LIKE '%2023%' AND smtp.roi IS NOT NULL;"}, {"role": "user", "content": "Modify the query to filter for 'Seed' or 'Series A' rounds and projects with investment value greater than 500,000. Also, add the token's narrative to the output."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.investment_value, smtp.token_symbol, smtp.roi, tbi.narrative FROM project_fundraising_record pfr JOIN smart_money_token_performance smtp ON pfr.project_name ILIKE '%' || smtp.token_symbol || '%' JOIN token_basic_info tbi ON smtp.token_symbol = tbi.token_symbol WHERE pfr.investment_date LIKE '%2023%' AND smtp.roi IS NOT NULL AND pfr.rounds_name IN ('Seed', 'Series A') AND pfr.investment_value > 500000;"}, {"role": "user", "content": "Only show results for tokens on the 'Arbitrum' chain and add the token's current price from the basic info table."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.investment_value, smtp.token_symbol, smtp.roi, tbi.narrative, tbi.price FROM project_fundraising_record pfr JOIN smart_money_token_performance smtp ON pfr.project_name ILIKE '%' || smtp.token_symbol || '%' JOIN token_basic_info tbi ON smtp.token_symbol = tbi.token_symbol WHERE pfr.investment_date LIKE '%2023%' AND smtp.roi IS NOT NULL AND pfr.rounds_name IN ('Seed', 'Series A') AND pfr.investment_value > 500000 AND tbi.chain = 'Arbitrum';"}, {"role": "user", "content": "Finally, order the list by smart money ROI in descending order and display only the top 10 entries."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.investment_value, smtp.token_symbol, smtp.roi, tbi.narrative, tbi.price FROM project_fundraising_record pfr JOIN smart_money_token_performance smtp ON pfr.project_name ILIKE '%' || smtp.token_symbol || '%' JOIN token_basic_info tbi ON smtp.token_symbol = tbi.token_symbol WHERE pfr.investment_date LIKE '%2023%' AND smtp.roi IS NOT NULL AND pfr.rounds_name IN ('Seed', 'Series A') AND pfr.investment_value > 500000 AND tbi.chain = 'Arbitrum' ORDER BY smtp.roi 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 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 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 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 )\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 )\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 pairs of developers from the same country. For each pair, show both developers’ names and their country."}, {"role": "assistant", "content": "SELECT d1.name AS developer1, d2.name AS developer2, d1.country\nFROM gaming_technology.developers d1\nJOIN gaming_technology.developers d2\n ON d1.country = d2.country\n AND d1.developer_id <> d2.developer_id;"}, {"role": "user", "content": "Actually, I want to avoid duplicate pairs; only list each pair once."}, {"role": "assistant", "content": "SELECT d1.name AS developer1, d2.name AS developer2, d1.country\nFROM gaming_technology.developers d1\nJOIN gaming_technology.developers d2\n ON d1.country = d2.country\n AND d1.developer_id < d2.developer_id;"}, {"role": "user", "content": "Also, only include countries that have more than two developers."}, {"role": "assistant", "content": "SELECT d1.name AS developer1, d2.name AS developer2, d1.country\nFROM gaming_technology.developers d1\nJOIN gaming_technology.developers d2\n ON d1.country = d2.country\n AND d1.developer_id < d2.developer_id\nWHERE (\n SELECT COUNT(*)\n FROM gaming_technology.developers d3\n WHERE d3.country = d1.country\n) > 2;"}, {"role": "user", "content": "Finally, order the results by country ascending and then by developer1’s name ascending."}, {"role": "assistant", "content": "SELECT d1.name AS developer1, d2.name AS developer2, d1.country\nFROM gaming_technology.developers d1\nJOIN gaming_technology.developers d2\n ON d1.country = d2.country\n AND d1.developer_id < d2.developer_id\nWHERE (\n SELECT COUNT(*)\n FROM gaming_technology.developers d3\n WHERE d3.country = d1.country\n) > 2\nORDER BY d1.country ASC, d1.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 gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\n"} {"conversations": [{"role": "user", "content": "List the employee's first and last name along with the appointment ID and scheduled start time for all appointments associated with the citizen who has the national ID number 'A123456789'."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, a.appointment_id, a.scheduled_start_time\nFROM government_services.appointments a\nJOIN government_services.employees e ON a.employee_id = e.employee_id\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nWHERE c.national_id_number = 'A123456789';"}], "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.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 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 )\n"} {"conversations": [{"role": "user", "content": "Which service locations do not have a contact phone specified? Show the location_id and location_name."}, {"role": "assistant", "content": "SELECT location_id, location_name\nFROM government_services.service_locations\nWHERE contact_phone IS NULL OR contact_phone = '';"}], "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.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) )\n"} {"conversations": [{"role": "user", "content": "How many appointments are scheduled to start tomorrow?"}, {"role": "assistant", "content": "SELECT count(*) FROM government_services.appointments WHERE DATE(scheduled_start_time) = CURRENT_DATE + INTERVAL '1 day'"}], "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.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 )\n"}