| {"conversations": [{"role": "user", "content": "List the names of service locations and the names of the agencies they belong to, specifically for locations situated in the state of 'Texas' that are marked as accessible."}, {"role": "assistant", "content": "SELECT t1.location_name, t2.agency_name FROM government_services.service_locations AS t1 JOIN government_services.agencies AS t2 ON t1.agency_id = t2.agency_id WHERE t1.state = 'Texas' AND t1.is_accessible = 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 (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.agencies ( agency_id 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.documents ( document_id text, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.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 )\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, for each item, the total number of times it has been acquired and the earliest date it was acquired. Also, show the number of unique players who have acquired each item."}, {"role": "assistant", "content": "SELECT item_id, COUNT(*) AS total_acquisitions, MIN(acquired_at) AS earliest_acquired, COUNT(DISTINCT player_id) AS unique_players FROM gaming_technology.player_inventory GROUP BY item_id;"}, {"role": "user", "content": "Now, could you limit the results to only items that have been acquired by at least 3 unique players?"}, {"role": "assistant", "content": "SELECT item_id, COUNT(*) AS total_acquisitions, MIN(acquired_at) AS earliest_acquired, COUNT(DISTINCT player_id) AS unique_players FROM gaming_technology.player_inventory GROUP BY item_id HAVING COUNT(DISTINCT player_id) >= 3;"}, {"role": "user", "content": "Also, sort the results by total_acquisitions in descending order."}, {"role": "assistant", "content": "SELECT item_id, COUNT(*) AS total_acquisitions, MIN(acquired_at) AS earliest_acquired, COUNT(DISTINCT player_id) AS unique_players FROM gaming_technology.player_inventory GROUP BY item_id HAVING COUNT(DISTINCT player_id) >= 3 ORDER BY total_acquisitions DESC;"}, {"role": "user", "content": "Finally, limit the output to the top 5 items."}, {"role": "assistant", "content": "SELECT item_id, COUNT(*) AS total_acquisitions, MIN(acquired_at) AS earliest_acquired, COUNT(DISTINCT player_id) AS unique_players FROM gaming_technology.player_inventory GROUP BY item_id HAVING COUNT(DISTINCT player_id) >= 3 ORDER BY total_acquisitions 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 gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n"} |
| {"conversations": [{"role": "user", "content": "Count how many users have not specified a value for their bio."}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.users WHERE bio IS NULL OR bio = '';"}], "system": "You are an SQL statement expert. Given the table structure 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": "List the full names and email addresses of users who have liked any comment."}, {"role": "assistant", "content": "SELECT DISTINCT u.full_name, u.email\nFROM social_media.users u\nJOIN social_media.likes l ON u.user_id = l.user_id\nWHERE l.comment_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 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 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) )\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 ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\nCREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.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 ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations (\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 ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n"} |
| {"conversations": [{"role": "user", "content": "For each trade, show the buyer's and seller's usernames, the name and symbol of the traded asset, trade quantity, and trade price."}, {"role": "assistant", "content": "SELECT t.trade_id, ub.username AS buyer_username, us.username AS seller_username, a.name AS asset_name, a.symbol AS asset_symbol, t.quantity, t.price\nFROM trading_platform.trades t\nJOIN trading_platform.users ub ON t.buyer_id = ub.user_id\nJOIN trading_platform.users us ON t.seller_id = us.user_id\nJOIN trading_platform.assets a ON t.asset_id = a.asset_id;"}, {"role": "user", "content": "Please add the traded_at timestamp to the result and only include trades where the asset symbol contains the letter 'E'."}, {"role": "assistant", "content": "SELECT t.trade_id, ub.username AS buyer_username, us.username AS seller_username, a.name AS asset_name, a.symbol AS asset_symbol, t.quantity, t.price, t.traded_at\nFROM trading_platform.trades t\nJOIN trading_platform.users ub ON t.buyer_id = ub.user_id\nJOIN trading_platform.users us ON t.seller_id = us.user_id\nJOIN trading_platform.assets a ON t.asset_id = a.asset_id\nWHERE a.symbol ILIKE '%E%';"}], "system": "You are an SQL statement expert. Given the table structure 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.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)\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": "List the names and types of all properties, along with the full names and positions of their managers."}, {"role": "assistant", "content": "SELECT p.property_name, p.property_type, s.first_name || ' ' || s.last_name AS manager_full_name, s.position AS manager_position\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.staff s ON p.manager_staff_id = s.staff_id;"}, {"role": "user", "content": "Actually, only include properties where the manager is currently active, and show the state as well."}, {"role": "assistant", "content": "SELECT p.property_name, p.property_type, p.state_province, s.first_name || ' ' || s.last_name AS manager_full_name, s.position AS manager_position\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.staff s ON p.manager_staff_id = s.staff_id\nWHERE s.is_active = true;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties (\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": "Get the average price of all services for each category."}, {"role": "assistant", "content": "SELECT category, AVG(price) AS avg_price\nFROM hospitality_technology.services\nGROUP BY category;"}, {"role": "user", "content": "Only include categories where the average price exceeds 50 and order the results by avg_price descending."}, {"role": "assistant", "content": "SELECT category, AVG(price) AS avg_price\nFROM hospitality_technology.services\nGROUP BY category\nHAVING AVG(price) > 50\nORDER BY avg_price DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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) )\n"} |
| {"conversations": [{"role": "user", "content": "List the document ID, file name, document type, and uploaded timestamp for all documents uploaded by 'Alice Johnson' between '2023-01-01' and '2023-12-31'."}, {"role": "assistant", "content": "SELECT document_id, file_name, document_type, uploaded_at FROM insurance.claim_documents WHERE uploaded_by = 'Alice Johnson' AND uploaded_at BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59';"}], "system": "You are an SQL statement expert. Given the table structure 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": "List all non-primary insurance plans for patients, including their policy numbers and effective dates, sorted by expiration date."}, {"role": "assistant", "content": "SELECT patient_id, policy_number, effective_date FROM healthcare.patient_insurance WHERE is_primary = false ORDER BY expiration_date;"}, {"role": "user", "content": "Actually, I only need to see plans that became effective in the last year."}, {"role": "assistant", "content": "SELECT patient_id, policy_number, effective_date FROM healthcare.patient_insurance WHERE is_primary = false AND effective_date >= (CURRENT_DATE - INTERVAL '1 year') ORDER BY expiration_date;"}, {"role": "user", "content": "Can you also include the group number for these plans?"}, {"role": "assistant", "content": "SELECT patient_id, policy_number, effective_date, group_number FROM healthcare.patient_insurance WHERE is_primary = false AND effective_date >= (CURRENT_DATE - INTERVAL '1 year') ORDER BY expiration_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.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": "List the customer ID, first_name, last_name, city, and the number of active policies each customer has, but only include customers who live in 'CA' and have at least 2 active policies."}, {"role": "assistant", "content": "SELECT cu.customer_id, cu.first_name, cu.last_name, cu.city, COUNT(p.policy_id) AS active_policy_count\nFROM insurance.customers cu\nJOIN insurance.policies p ON cu.customer_id = p.customer_id\nWHERE cu.state = 'CA'\n AND p.status = 'Active'\nGROUP BY cu.customer_id, cu.first_name, cu.last_name, cu.city\nHAVING COUNT(p.policy_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 character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL DEFAULT 'USA', phone_number character varying(30), email character varying(128) UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, status character varying(20) NOT NULL DEFAULT 'Active', PRIMARY KEY (customer_id) )\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.premium_payments ( payment_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, amount_paid numeric(12, 2) NOT NULL, payment_method character varying(50), transaction_reference character varying(128) UNIQUE, due_date date, payment_period_start date, payment_period_end date, status character varying(30) NOT NULL DEFAULT 'Completed', PRIMARY KEY (payment_id) )\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\n"} |
| {"conversations": [{"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": "Show me a list of insurance providers and the number of patient insurance policies they have."}, {"role": "assistant", "content": "SELECT p.insurance_provider,\n COUNT(pi.patient_insurance_id) AS policy_count\nFROM healthcare.insurance_plans p\nLEFT JOIN healthcare.patient_insurance pi ON p.plan_id = pi.plan_id\nGROUP BY p.insurance_provider;"}, {"role": "user", "content": "Now only include providers with more than 3 policies and sort by policy_count desc."}, {"role": "assistant", "content": "SELECT p.insurance_provider,\n COUNT(pi.patient_insurance_id) AS policy_count\nFROM healthcare.insurance_plans p\nLEFT JOIN healthcare.patient_insurance pi ON p.plan_id = pi.plan_id\nGROUP BY p.insurance_provider\nHAVING COUNT(pi.patient_insurance_id) > 3\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.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\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 active drivers with their license expiry dates and contact information."}, {"role": "assistant", "content": "SELECT driver_id, first_name, last_name, license_number, license_expiry_date, contact_number, email FROM transportation.drivers WHERE status = 'active';"}, {"role": "user", "content": "Now include the count of trips each driver has completed in the last 3 months."}, {"role": "assistant", "content": "SELECT d.driver_id, d.first_name, d.last_name, d.license_number, d.license_expiry_date, d.contact_number, d.email, COUNT(t.trip_id) AS completed_trips FROM transportation.drivers d LEFT JOIN transportation.trips t ON d.driver_id = t.driver_id WHERE d.status = 'active' AND t.status = 'Completed' AND t.actual_arrival >= CURRENT_DATE - INTERVAL '3 months' GROUP BY d.driver_id, d.first_name, d.last_name, d.license_number, d.license_expiry_date, d.contact_number, d.email;"}, {"role": "user", "content": "Filter this to only show drivers whose licenses expire in the next 60 days."}, {"role": "assistant", "content": "SELECT d.driver_id, d.first_name, d.last_name, d.license_number, d.license_expiry_date, d.contact_number, d.email, COUNT(t.trip_id) AS completed_trips FROM transportation.drivers d LEFT JOIN transportation.trips t ON d.driver_id = t.driver_id WHERE d.status = 'active' AND t.status = 'Completed' AND t.actual_arrival >= CURRENT_DATE - INTERVAL '3 months' AND d.license_expiry_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '60 days' GROUP BY d.driver_id, d.first_name, d.last_name, d.license_number, d.license_expiry_date, d.contact_number, d.email;"}, {"role": "user", "content": "Now order the results by license expiry date with the soonest expiring first."}, {"role": "assistant", "content": "SELECT d.driver_id, d.first_name, d.last_name, d.license_number, d.license_expiry_date, d.contact_number, d.email, COUNT(t.trip_id) AS completed_trips FROM transportation.drivers d LEFT JOIN transportation.trips t ON d.driver_id = t.driver_id WHERE d.status = 'active' AND t.status = 'Completed' AND t.actual_arrival >= CURRENT_DATE - INTERVAL '3 months' AND d.license_expiry_date BETWEEN CURRENT_DATE AND CURRENT_DATE + INTERVAL '60 days' GROUP BY d.driver_id, d.first_name, d.last_name, d.license_number, d.license_expiry_date, d.contact_number, d.email ORDER BY d.license_expiry_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 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 (\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.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "List for each fuel type the number of unique vehicle models available. Show the fuel_type and the model count."}, {"role": "assistant", "content": "SELECT fuel_type, COUNT(DISTINCT model) AS model_count FROM transportation.vehicles GROUP BY fuel_type ORDER BY fuel_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 transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )\n"} |
| {"conversations": [{"role": "user", "content": "Count the number of agents for each status."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM insurance.agents GROUP BY status;"}], "system": "You are an SQL statement expert. Given the table structure 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.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.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 )\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 savings accounts (account_id, account_number, balance) with an interest rate above 2.5%, along with the security details (ticker_symbol, issuer_name) for securities in the same currency as the account."}, {"role": "assistant", "content": "SELECT a.account_id, a.account_number, a.balance, s.ticker_symbol, s.issuer_name FROM financial_services.accounts a JOIN financial_services.securities s ON a.currency = s.currency WHERE a.account_type = 'Savings' AND a.interest_rate > 0.025"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )\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 )\n"} |
| {"conversations": [{"role": "user", "content": "I need a list of all chronic diagnoses marked as 'Active', showing diagnosis_id, diagnosis_date, doctor_id, and the associated chief_complaint from medical_records."}, {"role": "assistant", "content": "SELECT d.diagnosis_id,\n d.diagnosis_date,\n d.doctor_id,\n m.chief_complaint\nFROM healthcare.diagnoses d\nJOIN healthcare.medical_records m\n ON d.record_id = m.record_id\nWHERE d.is_chronic = TRUE\n AND d.status = 'Active';"}, {"role": "user", "content": "Actually, only include those diagnoses that occurred in February 2024 and order the results by diagnosis_date ascending."}, {"role": "assistant", "content": "SELECT d.diagnosis_id,\n d.diagnosis_date,\n d.doctor_id,\n m.chief_complaint\nFROM healthcare.diagnoses d\nJOIN healthcare.medical_records m\n ON d.record_id = m.record_id\nWHERE d.is_chronic = TRUE\n AND d.status = 'Active'\n AND d.diagnosis_date BETWEEN '2024-02-01' AND '2024-02-29'\nORDER BY d.diagnosis_date ASC;"}, {"role": "user", "content": "Also, include the assessment column from medical_records in the output."}, {"role": "assistant", "content": "SELECT d.diagnosis_id,\n d.diagnosis_date,\n d.doctor_id,\n m.chief_complaint,\n m.assessment\nFROM healthcare.diagnoses d\nJOIN healthcare.medical_records m\n ON d.record_id = m.record_id\nWHERE d.is_chronic = TRUE\n AND d.status = 'Active'\n AND d.diagnosis_date BETWEEN '2024-02-01' AND '2024-02-29'\nORDER BY d.diagnosis_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.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.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n"} |
| {"conversations": [{"role": "user", "content": "Show me all appointments for doctor 'doctor_100' in June 2024, including the appointment time and the patient ID."}, {"role": "assistant", "content": "SELECT appointment_id, patient_id, appointment_time\nFROM healthcare.appointments\nWHERE doctor_id = 'doctor_100'\n AND appointment_time >= '2024-06-01'::timestamp\n AND appointment_time < '2024-07-01'::timestamp;"}, {"role": "user", "content": "Can you also add the appointment status and sort by appointment_time ascending?"}, {"role": "assistant", "content": "SELECT appointment_id, patient_id, appointment_time, status\nFROM healthcare.appointments\nWHERE doctor_id = 'doctor_100'\n AND appointment_time >= '2024-06-01'::timestamp\n AND appointment_time < '2024-07-01'::timestamp\nORDER BY appointment_time ASC;"}, {"role": "user", "content": "Now, only include the appointments with status 'Completed'."}, {"role": "assistant", "content": "SELECT appointment_id, patient_id, appointment_time, status\nFROM healthcare.appointments\nWHERE doctor_id = 'doctor_100'\n AND appointment_time >= '2024-06-01'::timestamp\n AND appointment_time < '2024-07-01'::timestamp\n AND status = 'Completed'\nORDER BY appointment_time ASC;"}, {"role": "user", "content": "I got an empty result, but I expected at least one appointment. Could you check if the status value is in lowercase instead?"}, {"role": "assistant", "content": "SELECT appointment_id, patient_id, appointment_time, status\nFROM healthcare.appointments\nWHERE doctor_id = 'doctor_100'\n AND appointment_time >= '2024-06-01'::timestamp\n AND appointment_time < '2024-07-01'::timestamp\n AND LOWER(status) = 'completed'\nORDER BY appointment_time 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.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)\n"} |
| {"conversations": [{"role": "user", "content": "For each city that has a fueling location, show the city name and the total quantity of fuel refueled."}, {"role": "assistant", "content": "SELECT T2.city , SUM(T1.quantity) FROM transportation.fuel_logs AS T1 JOIN transportation.locations AS T2 ON T1.location_id = T2.location_id GROUP BY T2.city"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.locations ( location_id text PRIMARY KEY, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.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.bookings ( booking_id text PRIMARY KEY, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n"} |
| {"conversations": [{"role": "user", "content": "For each snapshot_time in cex_token_balance, calculate the total usd_value across all exchanges and order by snapshot_time ascending."}, {"role": "assistant", "content": "SELECT snapshot_time,\n SUM(usd_value) AS total_usd_value\nFROM cex_token_balance\nGROUP BY snapshot_time\nORDER BY snapshot_time 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 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_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 token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )\nCREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\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": "Find all transactions where the amount is greater than 1000 and the receiver_address starts with '0x1'."}, {"role": "assistant", "content": "SELECT * FROM blockchain.transactions WHERE amount > 1000 AND receiver_address LIKE '0x1%';"}, {"role": "user", "content": "Can you modify this to also include the block_id and order by timestamp in descending order?"}, {"role": "assistant", "content": "SELECT transaction_id, block_id, sender_address, receiver_address, amount, timestamp FROM blockchain.transactions WHERE amount > 1000 AND receiver_address LIKE '0x1%' ORDER BY timestamp DESC;"}, {"role": "user", "content": "Actually, I only want to see transactions that occurred in the last 6 months."}, {"role": "assistant", "content": "SELECT transaction_id, block_id, sender_address, receiver_address, amount, timestamp FROM blockchain.transactions WHERE amount > 1000 AND receiver_address LIKE '0x1%' AND timestamp >= NOW() - INTERVAL '6 months' ORDER BY timestamp DESC;"}, {"role": "user", "content": "Now group these by receiver_address and show the total amount received by each."}, {"role": "assistant", "content": "SELECT receiver_address, SUM(amount) as total_received FROM blockchain.transactions WHERE amount > 1000 AND receiver_address LIKE '0x1%' AND timestamp >= NOW() - INTERVAL '6 months' GROUP BY receiver_address ORDER BY total_received 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.transactions ( transaction_id text PRIMARY KEY, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text )\n"} |
| {"conversations": [{"role": "user", "content": "List all combinations of manufacturers and generic names. For each combination, display the manufacturer, generic_name, and the number of medications."}, {"role": "assistant", "content": "SELECT manufacturer, generic_name, COUNT(*) AS medication_count FROM healthcare.medications GROUP BY manufacturer, generic_name;"}, {"role": "user", "content": "Only show combinations where there are at least 3 medications and exclude rows where generic_name is missing."}, {"role": "assistant", "content": "SELECT manufacturer, generic_name, COUNT(*) AS medication_count FROM healthcare.medications WHERE generic_name IS NOT NULL AND generic_name <> '' GROUP BY manufacturer, generic_name 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 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 each vehicle and the date of its most recent maintenance, including the service type and cost."}, {"role": "assistant", "content": "SELECT vehicle_id, service_type, cost, service_date FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY service_date DESC) AS rn FROM transportation.maintenance_logs) AS ranked_logs WHERE rn = 1;"}, {"role": "user", "content": "I received an error that 'service_type' does not exist in the outermost query."}, {"role": "assistant", "content": "SELECT vehicle_id, service_date, service_type, cost FROM (SELECT log_id, vehicle_id, service_date, service_type, cost, ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY service_date DESC) AS rn FROM transportation.maintenance_logs) AS ranked_logs WHERE rn = 1;"}, {"role": "user", "content": "Also include the name of the mechanic for each latest maintenance."}, {"role": "assistant", "content": "SELECT vehicle_id, service_date, service_type, cost, mechanic_name FROM (SELECT log_id, vehicle_id, service_date, service_type, cost, mechanic_name, ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY service_date DESC) AS rn FROM transportation.maintenance_logs) AS ranked_logs WHERE rn = 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 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 )\n"} |
| {"conversations": [{"role": "user", "content": "Show me all staff members who are currently active, along with their property name and position."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name \nFROM hospitality_technology.staff s \nJOIN hospitality_technology.properties p ON s.property_id = p.property_id \nWHERE s.is_active = TRUE;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id 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.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 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.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 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": "Find the top 3 drivers by their average number of passengers per trip, including driver_id, first_name, last_name, and avg_passengers, ordered by avg_passengers descending."}, {"role": "assistant", "content": "SELECT d.driver_id,\n d.first_name,\n d.last_name,\n AVG(t.passenger_count) AS avg_passengers\nFROM transportation.drivers d\nJOIN transportation.trips t ON d.driver_id = t.driver_id\nGROUP BY d.driver_id, d.first_name, d.last_name\nORDER BY avg_passengers 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 transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.trips ( trip_id text, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count integer, cargo_manifest_id text )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.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": "Show me the total quantity of each item each player currently has in their inventory."}, {"role": "assistant", "content": "SELECT player_id, item_id, SUM(quantity) AS total_quantity FROM gaming_technology.player_inventory GROUP BY player_id, item_id"}, {"role": "user", "content": "I only want to include players who have at least one item with a quantity greater than 20."}, {"role": "assistant", "content": "SELECT player_id, item_id, SUM(quantity) AS total_quantity FROM gaming_technology.player_inventory GROUP BY player_id, item_id HAVING SUM(quantity) > 20"}, {"role": "user", "content": "Can you expand this to also show the number of different items that each of these players has in their inventory?"}, {"role": "assistant", "content": "SELECT pi.player_id, COUNT(DISTINCT pi.item_id) AS num_different_items, SUM(pi.quantity) AS total_quantity FROM gaming_technology.player_inventory pi GROUP BY pi.player_id HAVING MAX(pi.quantity) > 20"}, {"role": "user", "content": "I got an error with the HAVING clause. Please rewrite so it only includes players who have any single item row with quantity > 20."}, {"role": "assistant", "content": "SELECT pi.player_id, COUNT(DISTINCT pi.item_id) AS num_different_items, SUM(pi.quantity) AS total_quantity FROM gaming_technology.player_inventory pi WHERE pi.player_id IN (SELECT player_id FROM gaming_technology.player_inventory WHERE quantity > 20) GROUP BY pi.player_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.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid PRIMARY KEY, player_id uuid, achievement_id uuid, unlocked_at timestamptz )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )\n"} |
| {"conversations": [{"role": "user", "content": "Retrieve the name and city of all locations that act as both origin and destination for any route."}, {"role": "assistant", "content": "SELECT l.name, l.city\nFROM transportation.locations l\nWHERE l.location_id IN (SELECT origin_location_id FROM transportation.routes)\n AND l.location_id IN (SELECT destination_location_id FROM transportation.routes);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\n"} |
| {"conversations": [{"role": "user", "content": "Show me a list of all appointments with the subject and full name of the assigned lawyer."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.subject, l.first_name || ' ' || l.last_name AS lawyer_full_name\nFROM legal_services.appointments a\nJOIN legal_services.lawyers l ON a.lawyer_id = l.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.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\nCREATE TABLE legal_services.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.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "Show me all rooms on floor 4 or above together with their room number, features, and current status."}, {"role": "assistant", "content": "SELECT room_id, room_number, features, status\nFROM hospitality_technology.rooms\nWHERE floor >= 4;"}, {"role": "user", "content": "Only include rooms that are marked as non-smoking and sort the results by floor descending."}, {"role": "assistant", "content": "SELECT room_id, room_number, features, status, floor\nFROM hospitality_technology.rooms\nWHERE floor >= 4 AND is_smoking = FALSE\nORDER BY floor DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( 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 )\n"} |
| {"conversations": [{"role": "user", "content": "List all locations of type 'depot' in the United States, showing their name, state, and city."}, {"role": "assistant", "content": "SELECT name, state_province, city FROM transportation.locations WHERE country = 'United States' AND type = 'depot';"}, {"role": "user", "content": "There's a typo in your SQL - it should be 'state_province' not 'state_province'. Also, can you include the timezone for these depots?"}, {"role": "assistant", "content": "SELECT name, state_province, city, timezone FROM transportation.locations WHERE country = 'United States' AND type = 'depot';"}, {"role": "user", "content": "Now filter these results to only show depots in Texas or California, and order them by city name."}, {"role": "assistant", "content": "SELECT name, state_province, city, timezone FROM transportation.locations WHERE country = 'United States' AND type = 'depot' AND state_province IN ('Texas', 'California') ORDER BY city;"}, {"role": "user", "content": "Actually, I need to see the full address for these depots as well, and limit the results to 10."}, {"role": "assistant", "content": "SELECT name, state_province, city, timezone, address_line1 FROM transportation.locations WHERE country = 'United States' AND type = 'depot' AND state_province IN ('Texas', 'California') ORDER BY city 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 transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\n"} |
| {"conversations": [{"role": "user", "content": "List each wallet with its corresponding user_id and the total number of notifications that user has received."}, {"role": "assistant", "content": "SELECT w.wallet_id, w.user_id, COUNT(n.notification_id) as total_notifications\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.notifications n ON w.user_id = n.user_id\nGROUP BY w.wallet_id, w.user_id;"}, {"role": "user", "content": "Can you also display only wallets for users who have received at least 5 notifications?"}, {"role": "assistant", "content": "SELECT w.wallet_id, w.user_id, COUNT(n.notification_id) as total_notifications\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.notifications n ON w.user_id = n.user_id\nGROUP BY w.wallet_id, w.user_id\nHAVING COUNT(n.notification_id) >= 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id.text, asset_id.text, key.text, value.text )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id.text, user_id.text, status.text, reviewed_at.timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} |
| {"conversations": [{"role": "user", "content": "Show me the top 5 players by their average game session score, including their username and calculated average score."}, {"role": "assistant", "content": "SELECT p.username,\n AVG(gs.score) AS average_score\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs\n ON p.player_id = gs.player_id\nGROUP BY p.username\nORDER BY average_score DESC\nLIMIT 5;"}, {"role": "user", "content": "But only include players who have played at least 10 sessions."}, {"role": "assistant", "content": "SELECT p.username,\n AVG(gs.score) AS average_score\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs\n ON p.player_id = gs.player_id\nGROUP BY p.username\nHAVING COUNT(gs.session_id) >= 10\nORDER BY average_score DESC\nLIMIT 5;"}, {"role": "user", "content": "Also include each player's country_code in the output."}, {"role": "assistant", "content": "SELECT p.username,\n p.country_code,\n AVG(gs.score) AS average_score\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs\n ON p.player_id = gs.player_id\nGROUP BY p.username, p.country_code\nHAVING COUNT(gs.session_id) >= 10\nORDER BY average_score DESC\nLIMIT 5;"}, {"role": "user", "content": "And rename the average_score column to avg_session_score."}, {"role": "assistant", "content": "SELECT p.username,\n p.country_code,\n AVG(gs.score) AS avg_session_score\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs\n ON p.player_id = gs.player_id\nGROUP BY p.username, p.country_code\nHAVING COUNT(gs.session_id) >= 10\nORDER BY avg_session_score 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 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.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, 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.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\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": "List all documents along with the document type and the case name they are associated with."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, c.case_name\nFROM legal_services.documents d\nJOIN legal_services.cases c ON d.case_id = c.case_id;"}, {"role": "user", "content": "Show only documents uploaded by lawyers whose specialization is 'Employment Law'."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, c.case_name\nFROM legal_services.documents d\nJOIN legal_services.cases c ON d.case_id = c.case_id\nJOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id\nWHERE l.specialization = 'Employment Law';"}, {"role": "user", "content": "Also, include the lawyer's full name and order the results by upload_timestamp descending."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name\nFROM legal_services.documents d\nJOIN legal_services.cases c ON d.case_id = c.case_id\nJOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id\nWHERE l.specialization = 'Employment Law'\nORDER BY d.upload_timestamp DESC;"}, {"role": "user", "content": "Exclude any documents where the document_type is null."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name\nFROM legal_services.documents d\nJOIN legal_services.cases c ON d.case_id = c.case_id\nJOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id\nWHERE l.specialization = 'Employment Law' AND d.document_type IS NOT NULL\nORDER 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.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\nCREATE TABLE legal_services.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.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "List all transfers of the token named 'Wrapped Ether', showing the transfer id, token id, value, and the contract address of the token."}, {"role": "assistant", "content": "SELECT tt.transfer_id, tt.token_id, tt.value, t.contract_address\nFROM web3.token_transfers tt\nJOIN web3.tokens t ON tt.token_id = t.token_id\nWHERE t.token_name = 'Wrapped Ether';"}, {"role": "user", "content": "Actually, can you also include the username of the user who owns the sender address, if such a user exists?"}, {"role": "assistant", "content": "SELECT tt.transfer_id, tt.token_id, tt.value, t.contract_address, u.username\nFROM web3.token_transfers tt\nJOIN web3.tokens t ON tt.token_id = t.token_id\nLEFT JOIN web3.users u ON tt.from_address = (\n SELECT w.address FROM web3.wallets w WHERE w.user_id = u.user_id AND w.address = tt.from_address LIMIT 1\n)\nWHERE t.token_name = 'Wrapped Ether';"}], "system": "You are an SQL statement expert. Given the table structure 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.tokens ( token_id character varying(64) NOT NULL, contract_address character varying(128) NOT NULL, token_name character varying(128) NOT NULL, token_symbol character varying(32) NOT NULL, decimals integer NOT NULL, total_supply numeric(38,14) NOT NULL, PRIMARY KEY (token_id) )\nCREATE TABLE web3.token_transfers ( transfer_id character varying(64) NOT NULL, token_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128) NOT NULL, value numeric(38,14) NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (transfer_id) )\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": "Can you show me a list of all players along with all in-game items they have access to, including the player_id, username, and item_name?"}, {"role": "assistant", "content": "SELECT p.player_id, p.username, i.item_name\nFROM gaming_technology.players p\nCROSS JOIN gaming_technology.in_game_items i;"}, {"role": "user", "content": "I'd like to only see items where the rarity is 'Legendary'. Can you filter the items accordingly?"}, {"role": "assistant", "content": "SELECT p.player_id, p.username, i.item_name\nFROM gaming_technology.players p\nCROSS JOIN gaming_technology.in_game_items i\nWHERE i.rarity = 'Legendary';"}, {"role": "user", "content": "Now, please only include players whose status is 'active'."}, {"role": "assistant", "content": "SELECT p.player_id, p.username, i.item_name\nFROM gaming_technology.players p\nCROSS JOIN gaming_technology.in_game_items i\nWHERE i.rarity = 'Legendary' AND p.status = 'active';"}, {"role": "user", "content": "Also include the item_type and order the results by item_name ascending."}, {"role": "assistant", "content": "SELECT p.player_id, p.username, i.item_name, i.item_type\nFROM gaming_technology.players p\nCROSS JOIN gaming_technology.in_game_items i\nWHERE i.rarity = 'Legendary' AND p.status = 'active'\nORDER BY i.item_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.players ( player_id uuid, username text, email text, password_hash text, registration_date timestamp with time zone, last_login timestamp with time zone, country_code text, status text, profile_data jsonb )\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": "Find pairs of documents within the same case that were uploaded on the same day but by different lawyers. Show the case_id, upload_date, document_id and uploader_id for both documents in the pair."}, {"role": "assistant", "content": "SELECT d1.case_id, DATE(d1.upload_timestamp) AS upload_date, d1.document_id AS document1_id, d1.uploaded_by_lawyer_id AS lawyer1_id, d2.document_id AS document2_id, d2.uploaded_by_lawyer_id AS lawyer2_id FROM legal_services.documents AS d1 JOIN legal_services.documents AS d2 ON d1.case_id = d2.case_id AND DATE(d1.upload_timestamp) = DATE(d2.upload_timestamp) AND d1.uploaded_by_lawyer_id <> d2.uploaded_by_lawyer_id WHERE d1.document_id < d2.document_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": "Find the security name and ticker symbol for all securities that have a market data entry with a trading volume greater than 5,000,000."}, {"role": "assistant", "content": "SELECT DISTINCT T1.security_name, T1.ticker_symbol FROM financial_services.securities AS T1 JOIN financial_services.market_data AS T2 ON T1.security_id = T2.security_id WHERE T2.volume > 5000000"}], "system": "You are an SQL statement expert. Given the table structure 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 )\n"} |
| {"conversations": [{"role": "user", "content": "Can you help me find all bookings made by passengers from a specific city, say 'Boston', including the passenger details and the scheduled trip information?"}, {"role": "assistant", "content": "MATCH (p:Passenger)-[:MADE_BOOKING]->(b:Booking)-[:FOR_TRIP]->(st:ScheduledTrip)\nMATCH (p)-[:BASED_AT]->(s:Station)\nWHERE s.city = 'Boston'\nRETURN p.passenger_id, p.first_name, p.last_name, b.booking_id, b.booking_datetime, b.status, st.schedule_id"}, {"role": "user", "content": "Can you modify the query to include only bookings with a status of 'Confirmed'?"}, {"role": "assistant", "content": "MATCH (p:Passenger)-[:MADE_BOOKING]->(b:Booking)-[:FOR_TRIP]->(st:ScheduledTrip)\nMATCH (p)-[:BASED_AT]->(s:Station)\nWHERE s.city = 'Boston' AND b.status = 'Confirmed'\nRETURN p.passenger_id, p.first_name, p.last_name, b.booking_id, b.booking_datetime, b.status, st.schedule_id"}, {"role": "user", "content": "Can you also add the total price of each booking to the result?"}, {"role": "assistant", "content": "MATCH (p:Passenger)-[:MADE_BOOKING]->(b:Booking)-[:FOR_TRIP]->(st:ScheduledTrip)\nMATCH (p)-[:BASED_AT]->(s:Station)\nWHERE s.city = 'Boston' AND b.status = 'Confirmed'\nRETURN p.passenger_id, p.first_name, p.last_name, b.booking_id, b.booking_datetime, b.status, b.total_price, st.schedule_id"}, {"role": "user", "content": "Can you sort the results by booking datetime in ascending order?"}, {"role": "assistant", "content": "MATCH (p:Passenger)-[:MADE_BOOKING]->(b:Booking)-[:FOR_TRIP]->(st:ScheduledTrip)\nMATCH (p)-[:BASED_AT]->(s:Station)\nWHERE s.city = 'Boston' AND b.status = 'Confirmed'\nRETURN p.passenger_id, p.first_name, p.last_name, b.booking_id, b.booking_datetime, b.status, b.total_price, st.schedule_id\nORDER BY b.booking_datetime ASC"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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<String> 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// 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: :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: :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 ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses."}, {"role": "assistant", "content": "SELECT t.name, t.symbol, t.address FROM token_prices_latest t WHERE t.price BETWEEN 1 AND 10;"}, {"role": "user", "content": "I think there's an error in your query - it should be joining with sui_coins_metadata on coin_type not address. Also, can you add the current price to the results?"}, {"role": "assistant", "content": "SELECT scm.name, scm.symbol, tpl.address, tpl.price FROM token_prices_latest tpl JOIN sui_coins_metadata scm ON tpl.address = scm.coin_type WHERE tpl.price BETWEEN 1 AND 10;"}, {"role": "user", "content": "Now filter these results to only show tokens with decimals equal to 18 and sort by name alphabetically."}, {"role": "assistant", "content": "SELECT scm.name, scm.symbol, tpl.address, tpl.price FROM token_prices_latest tpl JOIN sui_coins_metadata scm ON tpl.address = scm.coin_type WHERE tpl.price BETWEEN 1 AND 10 AND scm.decimals = 18 ORDER BY scm.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 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 sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE 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_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\n"} |
| {"conversations": [{"role": "user", "content": "Show me all intercity routes with their origin and destination cities, along with the average passenger count for completed trips on these routes."}, {"role": "assistant", "content": "SELECT r.route_id, lo.city AS origin_city, ld.city AS destination_city, AVG(t.passenger_count) AS avg_passengers FROM transportation.routes r JOIN transportation.locations lo ON r.origin_location_id = lo.location_id JOIN transportation.locations ld ON r.destination_location_id = ld.location_id JOIN transportation.trips t ON r.route_id = t.route_id WHERE r.type = 'intercity' AND t.status = 'completed' GROUP BY r.route_id, lo.city, ld.city"}, {"role": "user", "content": "Can you include the route distance and filter to only show routes with an average passenger count greater than 15?"}, {"role": "assistant", "content": "SELECT r.route_id, lo.city AS origin_city, ld.city AS destination_city, r.distance_km, AVG(t.passenger_count) AS avg_passengers FROM transportation.routes r JOIN transportation.locations lo ON r.origin_location_id = lo.location_id JOIN transportation.locations ld ON r.destination_location_id = ld.location_id JOIN transportation.trips t ON r.route_id = t.route_id WHERE r.type = 'intercity' AND t.status = 'completed' GROUP BY r.route_id, lo.city, ld.city, r.distance_km HAVING AVG(t.passenger_count) > 15"}, {"role": "user", "content": "Now order these results by distance in descending order and include the count of trips for each route."}, {"role": "assistant", "content": "SELECT r.route_id, lo.city AS origin_city, ld.city AS destination_city, r.distance_km, AVG(t.passenger_count) AS avg_passengers, COUNT(t.trip_id) AS trip_count FROM transportation.routes r JOIN transportation.locations lo ON r.origin_location_id = lo.location_id JOIN transportation.locations ld ON r.destination_location_id = ld.location_id JOIN transportation.trips t ON r.route_id = t.route_id WHERE r.type = 'intercity' AND t.status = 'completed' GROUP BY r.route_id, lo.city, ld.city, r.distance_km HAVING AVG(t.passenger_count) > 15 ORDER BY r.distance_km DESC"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.trips ( trip_id text, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count integer, cargo_manifest_id text )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs ( log_id text, vehicle_id text, service_date date, odometer_reading integer, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\n"} |
| {"conversations": [{"role": "user", "content": "Find all peers that haven't been seen in the last 30 days, along with their IP addresses and ports."}, {"role": "assistant", "content": "SELECT peer_id, ip_address, port FROM trading_platform.peers WHERE last_seen < CURRENT_DATE - INTERVAL '30 days';"}, {"role": "user", "content": "Now show me the count of such inactive peers grouped by their port numbers."}, {"role": "assistant", "content": "SELECT port, COUNT(*) AS inactive_peer_count FROM trading_platform.peers WHERE last_seen < CURRENT_DATE - INTERVAL '30 days' GROUP BY port;"}, {"role": "user", "content": "Actually, I want to see only ports with more than 5 inactive peers."}, {"role": "assistant", "content": "SELECT port, COUNT(*) AS inactive_peer_count FROM trading_platform.peers WHERE last_seen < CURRENT_DATE - INTERVAL '30 days' GROUP BY port 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 trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.trades ( trade_id text, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) )\n"} |
| {"conversations": [{"role": "user", "content": "List all customers (customer_id, first_name, last_name) who were born before 1990 (date_of_birth < '1990-01-01') and have an email address ending with '@gmail.com', along with their city and state information."}, {"role": "assistant", "content": "SELECT customer_id, first_name, last_name, city, state FROM financial_services.customers WHERE date_of_birth < '1990-01-01' AND email LIKE '%@gmail.com';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address text NOT NULL, city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status character varying(32) NOT NULL, risk_profile character varying(50), PRIMARY KEY (customer_id) )\n"} |
| {"conversations": [{"role": "user", "content": "For each account type and status, can you show the total number of accounts and their combined balance per currency?"}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance\nFROM financial_services.accounts\nGROUP BY account_type, status, currency;"}, {"role": "user", "content": "Can you add the average interest rate for each group in the result?"}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, status, currency;"}, {"role": "user", "content": "Please filter the results to only include groups where the total_balance is above 50000."}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, status, currency\nHAVING SUM(balance) > 50000;"}, {"role": "user", "content": "Finally, sort the result by average_interest_rate in descending order."}, {"role": "assistant", "content": "SELECT account_type, status, currency, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(interest_rate) AS average_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, status, currency\nHAVING SUM(balance) > 50000\nORDER BY average_interest_rate 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 ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )\n"} |
| {"conversations": [{"role": "user", "content": "Show me all doctors specializing in Pediatrics along with their upcoming appointments, including the patient ID and appointment time."}, {"role": "assistant", "content": "SELECT d.doctor_id, d.first_name, d.last_name, a.patient_id, a.appointment_time FROM healthcare.doctors d JOIN healthcare.appointments a ON d.doctor_id = a.doctor_id WHERE d.specialty = 'Pediatrics' AND a.appointment_time > CURRENT_TIMESTAMP ORDER BY a.appointment_time;"}], "system": "You are an SQL statement expert. Given the table structure 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 by the total number of trades they participated in as buyers, along with their email addresses."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, u.email, COUNT(t.trade_id) AS total_trades FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id GROUP BY u.user_id, u.username, u.email ORDER BY total_trades DESC LIMIT 5;"}, {"role": "user", "content": "Now modify the query to also include the total trade volume (quantity * price) for each of these users."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, u.email, COUNT(t.trade_id) AS total_trades, SUM(t.quantity * t.price) AS total_volume FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id GROUP BY u.user_id, u.username, u.email ORDER BY total_trades DESC LIMIT 5;"}, {"role": "user", "content": "Actually, I want to see the top 5 users by total trade volume instead of number of trades."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, u.email, COUNT(t.trade_id) AS total_trades, SUM(t.quantity * t.price) AS total_volume FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id GROUP BY u.user_id, u.username, u.email 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.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.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.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.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": "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": "Show all beneficiaries assigned to policy ID 'POL67890', with their first and last names, relationship, and the date they were added."}, {"role": "assistant", "content": "SELECT first_name, last_name, relationship, added_at\nFROM insurance.policy_beneficiaries\nWHERE policy_id = 'POL67890';"}, {"role": "user", "content": "Actually, only include beneficiaries whose percentage_share is at least 15%."}, {"role": "assistant", "content": "SELECT first_name, last_name, relationship, added_at\nFROM insurance.policy_beneficiaries\nWHERE policy_id = 'POL67890' AND percentage_share >= 15;"}, {"role": "user", "content": "I received an error because some percentage_share values are null. Please adjust the query to exclude those."}, {"role": "assistant", "content": "SELECT first_name, last_name, relationship, added_at\nFROM insurance.policy_beneficiaries\nWHERE policy_id = 'POL67890' AND percentage_share >= 15 AND percentage_share IS NOT NULL;"}, {"role": "user", "content": "Instead, show the results ordered by percentage_share descending, and just display the first name, last name, and percentage_share."}, {"role": "assistant", "content": "SELECT first_name, last_name, percentage_share\nFROM insurance.policy_beneficiaries\nWHERE policy_id = 'POL67890' AND percentage_share >= 15 AND percentage_share IS NOT NULL\nORDER BY percentage_share 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.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": "Retrieve each completed booking's booking_id, passenger full name, trip_id, scheduled_departure, and fare for bookings where the trip's passenger_count is at least 10."}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name || ' ' || p.last_name AS passenger_name, b.trip_id, t.scheduled_departure, b.fare\nFROM transportation.bookings b\nJOIN transportation.passengers p ON b.passenger_id = p.passenger_id\nJOIN transportation.trips t ON b.trip_id = t.trip_id\nWHERE b.status = 'Completed'\n AND t.passenger_count >= 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles (\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 ( 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.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.maintenance_logs ( log_id text PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\nCREATE TABLE transportation.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.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 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 the full names and hire dates of all employees who report directly to a manager with the job title 'Director'."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, e.hire_date\nFROM government_services.employees e\nJOIN government_services.employees m ON e.manager_employee_id = m.employee_id\nWHERE m.job_title = 'Director';"}], "system": "You are an SQL statement expert. Given the table structure 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 ( 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 )\n"} |
| {"conversations": [{"role": "user", "content": "List the first name, last name, and job title of each employee, along with the job title of their manager."}, {"role": "assistant", "content": "SELECT e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.job_title AS employee_job_title, m.job_title AS manager_job_title FROM government_services.employees AS e LEFT JOIN government_services.employees AS m ON e.manager_employee_id = m.employee_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.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": "List all pairs of insurance products that share the same product_type but have different base premiums, showing both product_ids, their product_type, and their base_premiums."}, {"role": "assistant", "content": "SELECT p1.product_id AS product1_id, p2.product_id AS product2_id, p1.product_type, p1.base_premium AS premium1, p2.base_premium AS premium2\nFROM insurance.insurance_products p1\nJOIN insurance.insurance_products p2\n ON p1.product_type = p2.product_type\n AND p1.product_id < p2.product_id;"}, {"role": "user", "content": "Actually, I only want pairs where both products are active."}, {"role": "assistant", "content": "SELECT p1.product_id AS product1_id, p2.product_id AS product2_id, p1.product_type, p1.base_premium AS premium1, p2.base_premium AS premium2\nFROM insurance.insurance_products p1\nJOIN insurance.insurance_products p2\n ON p1.product_type = p2.product_type\n AND p1.product_id < p2.product_id\nWHERE p1.is_active = true\n AND p2.is_active = true;"}, {"role": "user", "content": "Also include the absolute difference between their base premiums as premium_diff."}, {"role": "assistant", "content": "SELECT p1.product_id AS product1_id, p2.product_id AS product2_id, p1.product_type, p1.base_premium AS premium1, p2.base_premium AS premium2,\n ABS(p1.base_premium - p2.base_premium) AS premium_diff\nFROM insurance.insurance_products p1\nJOIN insurance.insurance_products p2\n ON p1.product_type = p2.product_type\n AND p1.product_id < p2.product_id\nWHERE p1.is_active = true\n AND p2.is_active = true;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "List all service orders with service name, guest's full name, order timestamp and status for orders with status 'Delivered'."}, {"role": "assistant", "content": "SELECT so.order_id, s.service_name, g.first_name || ' ' || g.last_name AS guest_full_name, so.order_timestamp, so.status FROM hospitality_technology.service_orders so JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id WHERE so.status = 'Delivered';"}, {"role": "user", "content": "Filter to only include orders delivered in March 2023 and sort by delivery_timestamp."}, {"role": "assistant", "content": "SELECT so.order_id, s.service_name, g.first_name || ' ' || g.last_name AS guest_full_name, so.order_timestamp, so.delivery_timestamp, so.status FROM hospitality_technology.service_orders so JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id WHERE so.status = 'Delivered' AND so.delivery_timestamp BETWEEN '2023-03-01' AND '2023-03-31' ORDER BY so.delivery_timestamp;"}, {"role": "user", "content": "Also, show the name of the staff who delivered the order and alias the columns appropriately."}, {"role": "assistant", "content": "SELECT so.order_id AS order_id, s.service_name AS service, g.first_name || ' ' || g.last_name AS guest, so.order_timestamp AS ordered_at, so.delivery_timestamp AS delivered_at, so.status AS order_status, sd.first_name || ' ' || sd.last_name AS delivered_by FROM hospitality_technology.service_orders so JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id LEFT JOIN hospitality_technology.staff sd ON so.staff_id_delivered = sd.staff_id WHERE so.status = 'Delivered' AND so.delivery_timestamp BETWEEN '2023-03-01' AND '2023-03-31' ORDER BY so.delivery_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 hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, work_email character varying(255) UNIQUE, work_phone character varying(30), hire_date date NOT NULL, termination_date date, is_active boolean NOT NULL DEFAULT true, access_level integer NOT NULL, manager_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n"} |
| {"conversations": [{"role": "user", "content": "Show all peers whose last_seen timestamp is before '2023-01-01' and whose port number is less than 1000, listing their peer_id and ip_address."}, {"role": "assistant", "content": "SELECT peer_id, ip_address FROM trading_platform.peers WHERE last_seen < '2023-01-01' AND port < 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 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) )\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": "For each service ID, show the average and maximum payment amount for payments made in the last 90 days."}, {"role": "assistant", "content": "SELECT service_id, AVG(amount), MAX(amount) FROM government_services.payments WHERE payment_timestamp >= NOW() - INTERVAL '90 days' GROUP BY service_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.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 )\n"} |
| {"conversations": [{"role": "user", "content": "For each ERC1155 contract in erc1155_approval_for_all, show contract_address, the count of approval-for-all events, and the number of unique current holders from nft_holders. Order by holder_count descending and limit to 5."}, {"role": "assistant", "content": "SELECT\ne.contract_address,\nCOUNT(*) AS approval_count,\nCOUNT(DISTINCT h.wallet_address) AS holder_count\nFROM erc1155_approval_for_all e\nLEFT JOIN nft_holders h\n ON e.contract_address = h.contract_address\n AND h.contract_type = 'ERC1155'\nGROUP BY e.contract_address\nORDER BY holder_count DESC\nLIMIT 5;"}, {"role": "user", "content": "Actually, I need only contracts with at least 10 unique holders and more than 20 approval events."}, {"role": "assistant", "content": "SELECT\ne.contract_address,\nCOUNT(*) AS approval_count,\nCOUNT(DISTINCT h.wallet_address) AS holder_count\nFROM erc1155_approval_for_all e\nLEFT JOIN nft_holders h\n ON e.contract_address = h.contract_address\n AND h.contract_type = 'ERC1155'\nGROUP BY e.contract_address\nHAVING COUNT(*) > 20\n AND COUNT(DISTINCT h.wallet_address) >= 10\nORDER BY holder_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 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_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 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_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_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_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": "List all beneficiaries who have a percentage share greater than 50% on a policy. Please include the beneficiary's first name, last name, relationship, the policy ID, and the policy's start date."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.relationship, T2.policy_id, T2.start_date FROM insurance.policy_beneficiaries AS T1 JOIN policies AS T2 ON T1.policy_id = T2.policy_id WHERE T1.percentage_share > 50;"}, {"role": "user", "content": "From those results, only show beneficiaries for policies that are currently 'Active'."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.relationship, T2.policy_id, T2.start_date FROM insurance.policy_beneficiaries AS T1 JOIN policies AS T2 ON T1.policy_id = T2.policy_id WHERE T1.percentage_share > 50 AND T2.status = 'Active';"}, {"role": "user", "content": "Okay, instead of 50%, show all beneficiaries with a share greater than 30%, but only for 'Active' policies that started before 2024. Sort the results by percentage share descending."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.relationship, T2.policy_id, T2.start_date FROM insurance.policy_beneficiaries AS T1 JOIN policies AS T2 ON T1.policy_id = T2.policy_id WHERE T1.percentage_share > 30 AND T2.status = 'Active' AND T2.start_date < '2024-01-01' ORDER BY T1.percentage_share DESC;"}, {"role": "user", "content": "Actually, just give me the policy ID, beneficiary's full name (combined), percentage share, and relationship for the top 10 results."}, {"role": "assistant", "content": "SELECT T2.policy_id, T1.first_name || ' ' || T1.last_name AS full_name, T1.percentage_share, T1.relationship FROM insurance.policy_beneficiaries AS T1 JOIN policies AS T2 ON T1.policy_id = T2.policy_id WHERE T1.percentage_share > 30 AND T2.status = 'Active' AND T2.start_date < '2024-01-01' ORDER BY T1.percentage_share 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 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 tokens with a market cap rank under 50 that have negative price changes in both the last 24 hours and last 7 days."}, {"role": "assistant", "content": "SELECT token_name, token_symbol, price_change_percentage_24h, price_change_percentage_7d, market_cap_rank FROM token_basic_info WHERE market_cap_rank < 50 AND price_change_percentage_24h < 0 AND price_change_percentage_7d < 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 project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\nCREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, chain character varying(128) NOT NULL, address character varying(128) NOT NULL, exchange character varying(512) NOT NULL, token_address character varying(128) NOT NULL, token_symbol character varying(512), balance numeric(38,10), usd_value numeric(38,14), price double precision )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\n"} |
| {"conversations": [{"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": "For each completed trip, list the trip ID, the driver's full name, and the name of the origin location."}, {"role": "assistant", "content": "SELECT t.trip_id, d.first_name || ' ' || d.last_name AS driver_name, l.name AS origin_location_name\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.locations l ON t.origin_location_id = l.location_id\nWHERE t.status = 'Completed';"}, {"role": "user", "content": "Can you also include the scheduled and actual departure times in the results?"}, {"role": "assistant", "content": "SELECT t.trip_id, d.first_name || ' ' || d.last_name AS driver_name, l.name AS origin_location_name, t.scheduled_departure, t.actual_departure\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.locations l ON t.origin_location_id = l.location_id\nWHERE t.status = 'Completed';"}, {"role": "user", "content": "Add the city of the origin location and sort the list by scheduled departure in ascending order."}, {"role": "assistant", "content": "SELECT t.trip_id, d.first_name || ' ' || d.last_name AS driver_name, l.name AS origin_location_name, l.city AS origin_city, t.scheduled_departure, t.actual_departure\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.locations l ON t.origin_location_id = l.location_id\nWHERE t.status = 'Completed'\nORDER BY t.scheduled_departure ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\nCREATE TABLE transportation.drivers (\n driver_id character varying(64) NOT NULL, -- unique identifier for the driver\n employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number\n first_name character varying(128) NOT NULL, -- driver's first name\n last_name character varying(128) NOT NULL, -- driver's last name\n license_number character varying(64) NOT NULL UNIQUE, -- driving license number\n license_expiry_date date NOT NULL, -- expiry date of the license\n contact_number character varying(32), -- phone number\n email character varying(128) UNIQUE, -- email address\n hire_date date NOT NULL, -- date the driver was hired\n status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated\n PRIMARY KEY (driver_id)\n)\nCREATE TABLE transportation.routes (\n route_id character varying(64) NOT NULL, -- unique identifier for the route\n route_number character varying(32) NOT NULL UNIQUE, -- public-facing route number/name\n description text, -- description of the route\n origin_location_id character varying(64) NOT NULL, -- identifier of the starting location\n destination_location_id character varying(64) NOT NULL, -- identifier of the ending location\n distance_km numeric(10, 2), -- estimated distance in kilometers\n estimated_duration_minutes integer, -- estimated travel time in minutes\n type character varying(32) NOT NULL, -- e.g., City Bus, Intercity Train, Cargo Delivery\n PRIMARY KEY (route_id)\n)\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\nCREATE TABLE transportation.locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the location\n name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)\n type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address\n address_line1 character varying(255), -- street address\n city character varying(128), -- city name\n state_province character varying(128), -- state or province\n postal_code character varying(32), -- postal code\n country character varying(64) NOT NULL, -- country name\n latitude numeric(9, 6), -- geographic latitude\n longitude numeric(9, 6), -- geographic longitude\n timezone character varying(64), -- IANA timezone name (e.g., America/New_York)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\nCREATE TABLE transportation.bookings (\n booking_id character varying(64) NOT NULL, -- unique identifier for the booking\n passenger_id character varying(64) NOT NULL, -- identifier of the passenger making the booking\n trip_id character varying(64) NOT NULL, -- identifier of the trip being booked\n seat_number character varying(16), -- assigned seat number (if applicable)\n booking_time timestamp with time zone NOT NULL, -- time when the booking was made\n status character varying(32) NOT NULL, -- e.g., Confirmed, Cancelled, Pending Payment\n fare numeric(10, 2) NOT NULL, -- price paid for the booking\n payment_transaction_id character varying(128), -- reference to the payment transaction\n special_requests text, -- any special requests from the passenger\n PRIMARY KEY (booking_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "For each prescription, find the next prescription for the same patient. Return current prescription_id, next_prescription_id, patient_id, and days between start dates."}, {"role": "assistant", "content": "SELECT p1.patient_id,\n p1.prescription_id AS current_id,\n p2.prescription_id AS next_id,\n (p2.start_date - p1.start_date) AS days_between\nFROM healthcare.prescriptions p1\nJOIN healthcare.prescriptions p2\n ON p1.patient_id = p2.patient_id\n AND p2.start_date = (\n SELECT MIN(start_date)\n FROM healthcare.prescriptions p3\n WHERE p3.patient_id = p1.patient_id\n AND p3.start_date > p1.start_date\n );"}, {"role": "user", "content": "Only include pairs where days_between is less than 30 days."}, {"role": "assistant", "content": "SELECT p1.patient_id,\n p1.prescription_id AS current_id,\n p2.prescription_id AS next_id,\n (p2.start_date - p1.start_date) AS days_between\nFROM healthcare.prescriptions p1\nJOIN healthcare.prescriptions p2\n ON p1.patient_id = p2.patient_id\n AND p2.start_date = (\n SELECT MIN(start_date)\n FROM healthcare.prescriptions p3\n WHERE p3.patient_id = p1.patient_id\n AND p3.start_date > p1.start_date\n )\nWHERE (p2.start_date - p1.start_date) < 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.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\n"} |
| {"conversations": [{"role": "user", "content": "For Avalanche tokens, show me the token `tick`, `creator`, and `max_supply` from the `token_info_avalanche` table."}, {"role": "assistant", "content": "SELECT tick, creator, max_supply FROM token_info_avalanche"}, {"role": "user", "content": "Now, for each of these ticks, calculate the total transfer volume (`amt`) from the `token_activities_avalanche` table over the last 30 days."}, {"role": "assistant", "content": "SELECT T1.tick, T2.creator, T2.max_supply, SUM(T1.amt) AS total_volume FROM token_activities_avalanche AS T1 JOIN token_info_avalanche AS T2 ON T1.tick = T2.tick WHERE T1.block_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30' DAY GROUP BY T1.tick, T2.creator, T2.max_supply"}, {"role": "user", "content": "Filter the results to only include ticks where the `total_volume` is greater than 10000."}, {"role": "assistant", "content": "SELECT T1.tick, T2.creator, T2.max_supply, SUM(T1.amt) AS total_volume FROM token_activities_avalanche AS T1 JOIN token_info_avalanche AS T2 ON T1.tick = T2.tick WHERE T1.block_timestamp >= CURRENT_TIMESTAMP - INTERVAL '30' DAY GROUP BY T1.tick, T2.creator, T2.max_supply HAVING SUM(T1.amt) > 10000"}], "system": "You are an SQL statement expert. Given the table structure 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 all insurance policies along with the product name and product type for each policy."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, p.start_date, p.end_date, p.premium_amount, ip.product_name, ip.product_type\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.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.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 )\n"} |
| {"conversations": [{"role": "user", "content": "What is the average investment_value and total number of projects for each rounds_name in project_fundraising_record?"}, {"role": "assistant", "content": "SELECT rounds_name,\n AVG(investment_value) AS avg_investment,\n COUNT(DISTINCT project_id) AS project_count\nFROM project_fundraising_record\nGROUP BY rounds_name;"}, {"role": "user", "content": "Please show only rounds where project_count > 5, and order by avg_investment descending."}, {"role": "assistant", "content": "SELECT rounds_name,\n AVG(investment_value) AS avg_investment,\n COUNT(DISTINCT project_id) AS project_count\nFROM project_fundraising_record\nGROUP BY rounds_name\nHAVING COUNT(DISTINCT project_id) > 5\nORDER BY avg_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 text, project_id text, project_name text, rounds_name text, investment_value numeric, investment_date text, introduction text, valuation numeric )\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 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 )\n"} |
| {"conversations": [{"role": "user", "content": "For each game, count how many achievements it has and calculate the average points."}, {"role": "assistant", "content": "SELECT game_id,\n COUNT(*) AS total_achievements,\n AVG(points) AS avg_points\nFROM achievements\nGROUP BY game_id;"}, {"role": "user", "content": "Actually, only count visible achievements (hidden = false)."}, {"role": "assistant", "content": "SELECT game_id,\n COUNT(*) AS visible_achievements,\n AVG(points) AS avg_points\nFROM achievements\nWHERE hidden = false\nGROUP BY game_id;"}, {"role": "user", "content": "Also include the total count of hidden achievements per game."}, {"role": "assistant", "content": "SELECT v.game_id,\n v.visible_achievements,\n v.avg_points,\n h.hidden_count\nFROM (\n SELECT game_id,\n COUNT(*) AS visible_achievements,\n AVG(points) AS avg_points\n FROM achievements\n WHERE hidden = false\n GROUP BY game_id\n) v\nLEFT JOIN (\n SELECT game_id,\n COUNT(*) AS hidden_count\n FROM achievements\n WHERE hidden = true\n GROUP BY game_id\n) h ON v.game_id = h.game_id;"}, {"role": "user", "content": "Now filter the results to only games with at least 3 visible achievements."}, {"role": "assistant", "content": "SELECT v.game_id,\n v.visible_achievements,\n v.avg_points,\n h.hidden_count\nFROM (\n SELECT game_id,\n COUNT(*) AS visible_achievements,\n AVG(points) AS avg_points\n FROM achievements\n WHERE hidden = false\n GROUP BY game_id\n HAVING COUNT(*) >= 3\n) v\nLEFT JOIN (\n SELECT game_id,\n COUNT(*) AS hidden_count\n FROM achievements\n WHERE hidden = true\n GROUP BY game_id\n) h ON v.game_id = h.game_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.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\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": "List each wallet that has received tokens of more than one distinct token type. Show wallet_id, address, the number of distinct tokens received as distinct_token_count, and the total received value, ordered by total_received_value descending."}, {"role": "assistant", "content": "SELECT w.wallet_id,\n w.address,\n COUNT(DISTINCT t.token_id) AS distinct_token_count,\n SUM(tt.value) AS total_received_value\nFROM web3.wallets w\nJOIN web3.token_transfers tt\n ON w.address = tt.to_address\nJOIN web3.tokens t\n ON tt.token_id = t.token_id\nGROUP BY w.wallet_id, w.address\nHAVING COUNT(DISTINCT t.token_id) > 1\nORDER BY total_received_value DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "Can you provide the total number of accounts and the average balance for each account_type?"}, {"role": "assistant", "content": "SELECT account_type, COUNT(*) AS total_accounts, AVG(balance) AS avg_balance\nFROM financial_services.accounts\nGROUP BY account_type;"}, {"role": "user", "content": "Exclude account types with fewer than 5 accounts."}, {"role": "assistant", "content": "SELECT account_type, COUNT(*) AS total_accounts, AVG(balance) AS avg_balance\nFROM financial_services.accounts\nGROUP BY account_type\nHAVING COUNT(*) >= 5;"}, {"role": "user", "content": "Sort the result by avg_balance in descending order."}, {"role": "assistant", "content": "SELECT account_type, COUNT(*) AS total_accounts, AVG(balance) AS avg_balance\nFROM financial_services.accounts\nGROUP BY account_type\nHAVING COUNT(*) >= 5\nORDER BY avg_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 ( 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 )\n"} |
| {"conversations": [{"role": "user", "content": "Please list the first name, last name, and date of birth for all female patients who were created in the year 2023."}, {"role": "assistant", "content": "SELECT first_name, last_name, date_of_birth FROM healthcare.patients WHERE gender = 'Female' AND created_at >= '2023-01-01' AND created_at < '2024-01-01';"}, {"role": "user", "content": "Okay, now only show those patients whose last name starts with the letter 'S'."}, {"role": "assistant", "content": "SELECT first_name, last_name, date_of_birth FROM healthcare.patients WHERE gender = 'Female' AND created_at >= '2023-01-01' AND created_at < '2024-01-01' AND last_name LIKE 'S%';"}, {"role": "user", "content": "Could you also include their patient_id and sort the results by last name in ascending order?"}, {"role": "assistant", "content": "SELECT patient_id, first_name, last_name, date_of_birth FROM healthcare.patients WHERE gender = 'Female' AND created_at >= '2023-01-01' AND created_at < '2024-01-01' AND last_name LIKE 'S%' ORDER BY last_name ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text PRIMARY KEY, 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": "List all spa services available at properties in New York, along with their prices and property names."}, {"role": "assistant", "content": "SELECT s.service_name, s.price, p.property_name FROM hospitality_technology.services s JOIN hospitality_technology.properties p ON s.property_id = p.property_id WHERE s.category = 'spa' AND p.state_province = 'New York' AND s.is_available = true;"}, {"role": "user", "content": "Now, include only services priced over $100 and order them by price in descending order."}, {"role": "assistant", "content": "SELECT s.service_name, s.price, p.property_name FROM hospitality_technology.services s JOIN hospitality_technology.properties p ON s.property_id = p.property_id WHERE s.category = 'spa' AND p.state_province = 'New York' AND s.is_available = true AND s.price > 100 ORDER BY s.price DESC;"}, {"role": "user", "content": "The query is missing the service description. Can you include that as well?"}, {"role": "assistant", "content": "SELECT s.service_name, s.description, s.price, p.property_name FROM hospitality_technology.services s JOIN hospitality_technology.properties p ON s.property_id = p.property_id WHERE s.category = 'spa' AND p.state_province = 'New York' AND s.is_available = true AND s.price > 100 ORDER BY s.price DESC;"}, {"role": "user", "content": "Actually, I only need services from properties with a star rating of 4.5 or higher."}, {"role": "assistant", "content": "SELECT s.service_name, s.description, s.price, p.property_name FROM hospitality_technology.services s JOIN hospitality_technology.properties p ON s.property_id = p.property_id WHERE s.category = 'spa' AND p.state_province = 'New York' AND s.is_available = true AND s.price > 100 AND p.star_rating >= 4.5 ORDER BY s.price DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id.text, property_name.text, address_line1.text, address_line2.text, city.text, state_province.text, postal_code.text, country_code.text, phone_number.text, email_address.text, property_type.text, star_rating.numeric, timezone.text, manager_staff_id.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.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.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": "List all invoices, showing the invoice number, issue date, total amount, and the payment status."}, {"role": "assistant", "content": "SELECT invoice_number, issue_date, total_amount, status FROM invoices"}, {"role": "user", "content": "Only include invoices issued in the last 90 days."}, {"role": "assistant", "content": "SELECT invoice_number, issue_date, total_amount, status FROM invoices WHERE issue_date >= CURRENT_DATE - INTERVAL '90 days'"}, {"role": "user", "content": "From those, only show invoices with a status of 'Overdue'."}, {"role": "assistant", "content": "SELECT invoice_number, issue_date, total_amount, status FROM invoices WHERE issue_date >= CURRENT_DATE - INTERVAL '90 days' AND status = 'Overdue'"}, {"role": "user", "content": "Also include the client's full name for these overdue invoices."}, {"role": "assistant", "content": "SELECT T1.invoice_number, T1.issue_date, T1.total_amount, T1.status, T2.first_name, T2.last_name FROM invoices AS T1 JOIN clients AS T2 ON T1.client_id = T2.client_id WHERE T1.issue_date >= CURRENT_DATE - INTERVAL '90 days' AND T1.status = 'Overdue'"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\nCREATE TABLE legal_services.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, case_id.text, lawyer_id.text, date_worked.date, hours_spent.numeric, billing_rate.numeric, description.text, is_billable.boolean, is_billed.boolean, invoice_id.text, created_at.timestamp )\nCREATE TABLE legal_services.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "List the names of employees and the agency they work for who have scheduled at least one appointment. Show the employee's first name, last name, and agency_id."}, {"role": "assistant", "content": "SELECT DISTINCT e.first_name, e.last_name, e.agency_id\nFROM government_services.employees e\nJOIN government_services.appointments a ON e.employee_id = a.employee_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.services ( service_id text, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days integer, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\nCREATE TABLE government_services.notifications ( notification_id text, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n"} |
| {"conversations": [{"role": "user", "content": "List all policies where the premium_amount exceeds the base_premium of its insurance product. Display the policy_number, premium_amount, product_name, and base_premium. Sort the results by premium_amount descending."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nORDER BY p.premium_amount DESC;"}, {"role": "user", "content": "Actually, I only want policies that are active and whose insurance products are also active."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'active'\n AND ip.is_active = TRUE\nORDER BY p.premium_amount DESC;"}, {"role": "user", "content": "Also, limit the output to policies with a coverage_limit greater than 1000000."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'active'\n AND ip.is_active = TRUE\n AND p.coverage_limit > 1000000\nORDER BY p.premium_amount DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text PRIMARY KEY, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n"} |
| {"conversations": [{"role": "user", "content": "Show me all cryptocurrency assets that have been traded more than 50 times but have never been traded in quantities greater than 100, along with their average trade price."}, {"role": "assistant", "content": "SELECT a.asset_id, a.name, a.symbol, COUNT(t.trade_id) AS trade_count, AVG(t.price) AS avg_price FROM trading_platform.assets a JOIN trading_platform.trades t ON a.asset_id = t.asset_id WHERE a.type = 'cryptocurrency' GROUP BY a.asset_id, a.name, a.symbol HAVING COUNT(t.trade_id) > 50 AND MAX(t.quantity) <= 100;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\nCREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) )\nCREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )\n"} |
| {"conversations": [{"role": "user", "content": "How many distinct token symbols are recorded for each chain in the smart money performance data?"}, {"role": "assistant", "content": "SELECT chain, COUNT(DISTINCT token_symbol) FROM smart_money_token_performance GROUP BY chain"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\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": "How many unique wallets hold each NFT (by contract_address and token_id) currently?"}, {"role": "assistant", "content": "SELECT contract_address, token_id, COUNT(DISTINCT wallet_address) AS holder_count\nFROM nft_holders\nGROUP BY contract_address, token_id;"}, {"role": "user", "content": "Filter the results to only include NFTs with more than 10 holders."}, {"role": "assistant", "content": "SELECT contract_address, token_id, COUNT(DISTINCT wallet_address) AS holder_count\nFROM nft_holders\nGROUP BY contract_address, token_id\nHAVING COUNT(DISTINCT wallet_address) > 10;"}, {"role": "user", "content": "Order the results by holder_count descending and limit to the top 20."}, {"role": "assistant", "content": "SELECT contract_address, token_id, COUNT(DISTINCT wallet_address) AS holder_count\nFROM nft_holders\nGROUP BY contract_address, token_id\nHAVING COUNT(DISTINCT wallet_address) > 10\nORDER BY holder_count DESC\nLIMIT 20;"}, {"role": "user", "content": "Also show the total amount held across all wallets for each NFT."}, {"role": "assistant", "content": "SELECT contract_address,\n token_id,\n COUNT(DISTINCT wallet_address) AS holder_count,\n SUM(CAST(amount AS numeric)) AS total_amount\nFROM nft_holders\nGROUP BY contract_address, token_id\nHAVING COUNT(DISTINCT wallet_address) > 10\nORDER BY holder_count DESC\nLIMIT 20;"}], "system": "You are an SQL statement expert. Given the table structure 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_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 (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_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 text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n"} |
| {"conversations": [{"role": "user", "content": "Which bed types are offered in each property and how many different room types are associated with each bed type?"}, {"role": "assistant", "content": "SELECT property_id, bed_type, COUNT(DISTINCT room_type_id) AS room_type_count FROM hospitality_technology.room_types GROUP BY property_id, bed_type;"}, {"role": "user", "content": "Now, show only bed types that are available for at least 3 different room types within the same property."}, {"role": "assistant", "content": "SELECT property_id, bed_type, COUNT(DISTINCT room_type_id) AS room_type_count FROM hospitality_technology.room_types GROUP BY property_id, bed_type HAVING COUNT(DISTINCT room_type_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 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 )\n"} |
| {"conversations": [{"role": "user", "content": "Show me the top 5 NFT collections with the highest average rarity score, along with their contract addresses and names."}, {"role": "assistant", "content": "SELECT contract_address, name, AVG(rarity_score) as avg_rarity_score FROM nft_metadata GROUP BY contract_address, name ORDER BY avg_rarity_score DESC LIMIT 5;"}, {"role": "user", "content": "Can you filter these results to only include ERC721 collections and add their image URIs?"}, {"role": "assistant", "content": "SELECT m.contract_address, m.name, AVG(m.rarity_score) as avg_rarity_score, m.image_uri FROM nft_metadata m WHERE m.erc_type = 'ERC721' GROUP BY m.contract_address, m.name, m.image_uri ORDER BY avg_rarity_score DESC LIMIT 5;"}, {"role": "user", "content": "Now join this with the token_prices_latest table to include the current price of each collection's native token."}, {"role": "assistant", "content": "SELECT m.contract_address, m.name, AVG(m.rarity_score) as avg_rarity_score, m.image_uri, p.price FROM nft_metadata m JOIN token_prices_latest p ON m.contract_address = p.address WHERE m.erc_type = 'ERC721' GROUP BY m.contract_address, m.name, m.image_uri, p.price ORDER BY avg_rarity_score 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 erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n token_id varchar NOT NULL, -- The number of the token\n contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n amount bigint NOT NULL, -- amount fields for the functionType in contract\n minter varchar NOT NULL, -- minter fields for the functionType in contract\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract\n mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract\n mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract\n mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract\n token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract\n metadata varchar NOT NULL, -- metadata fields for the functionType in contract\n name varchar NOT NULL, -- name fields for the functionType in contract\n image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n status varchar NOT NULL, -- status fields for the functionType in contract\n rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract\n rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract\n unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(mint_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n"} |
| {"conversations": [{"role": "user", "content": "List all fuel logs including the timestamp, fuel type, quantity, and total cost."}, {"role": "assistant", "content": "SELECT log_timestamp, fuel_type, quantity, total_cost FROM transportation.fuel_logs;"}, {"role": "user", "content": "Add the vehicle ID and the odometer reading to the result."}, {"role": "assistant", "content": "SELECT vehicle_id, log_timestamp, fuel_type, quantity, total_cost, odometer_reading FROM transportation.fuel_logs;"}, {"role": "user", "content": "Filter this to only include logs where the total cost is greater than 50."}, {"role": "assistant", "content": "SELECT vehicle_id, log_timestamp, fuel_type, quantity, total_cost, odometer_reading FROM transportation.fuel_logs WHERE total_cost > 50;"}, {"role": "user", "content": "Sort the results by timestamp descending and limit to the 10 most recent records."}, {"role": "assistant", "content": "SELECT vehicle_id, log_timestamp, fuel_type, quantity, total_cost, odometer_reading FROM transportation.fuel_logs WHERE total_cost > 50 ORDER BY log_timestamp 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 transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\nCREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )\nCREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.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": "List all properties that have at least one room on the 10th floor. Include the property name and the count of such rooms."}, {"role": "assistant", "content": "SELECT p.property_name,\n COUNT(r.room_id) AS room_count\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.rooms r\n ON p.property_id = r.property_id\nWHERE r.floor = 10\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.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.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.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 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": "For each customer with at least one open claim, list the customer_id, first_name, last_name, policy_number, claim_id, and incident_date."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, p.policy_number, cl.claim_id, cl.incident_date\nFROM insurance.customers c\nJOIN insurance.claims cl ON c.customer_id = cl.customer_id\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nWHERE cl.status = 'Open';"}, {"role": "user", "content": "Actually, filter the results to only include claims reported after January 1, 2024."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name, c.last_name, p.policy_number, cl.claim_id, cl.incident_date\nFROM insurance.customers c\nJOIN insurance.claims cl ON c.customer_id = cl.customer_id\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nWHERE cl.status = 'Open'\n AND cl.reported_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.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\nCREATE TABLE insurance.policies ( policy_id.text, 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 )\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) )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n"} |
| {"conversations": [{"role": "user", "content": "List projects that have raised funds and also have an associated token, showing their name, fundraising amount, and current token price."}, {"role": "assistant", "content": "SELECT T1.project_name, T1.investment_value, T2.price FROM project_fundraising_record AS T1 INNER JOIN token_basic_info AS T2 ON T1.project_name = T2.token_symbol"}, {"role": "user", "content": "Only show results for projects that raised funds in 2023, and also include the token's market cap."}, {"role": "assistant", "content": "SELECT T1.project_name, T1.investment_value, T2.price, T2.market_cap FROM project_fundraising_record AS T1 INNER JOIN token_basic_info AS T2 ON T1.project_name = T2.token_symbol WHERE T1.investment_date LIKE '%2023%'"}, {"role": "user", "content": "Order the results by investment amount descending and show the top 10."}, {"role": "assistant", "content": "SELECT T1.project_name, T1.investment_value, T2.price, T2.market_cap FROM project_fundraising_record AS T1 INNER JOIN token_basic_info AS T2 ON T1.project_name = T2.token_symbol WHERE T1.investment_date LIKE '%2023%' ORDER BY T1.investment_value DESC LIMIT 10"}, {"role": "user", "content": "Filter to only include tokens on the 'Ethereum' chain."}, {"role": "assistant", "content": "SELECT T1.project_name, T1.investment_value, T2.price, T2.market_cap FROM project_fundraising_record AS T1 INNER JOIN token_basic_info AS T2 ON T1.project_name = T2.token_symbol WHERE T1.investment_date LIKE '%2023%' AND T2.chain = 'Ethereum' ORDER BY T1.investment_value 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 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 )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n"} |
| {"conversations": [{"role": "user", "content": "List each client's first_name, last_name and the sum of total_amount from invoices where status is either 'Sent' or 'Paid'."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, SUM(i.total_amount) AS total_amount_sum\nFROM legal_services.clients c\nJOIN legal_services.invoices i ON c.client_id = i.client_id\nWHERE i.status IN ('Sent', 'Paid')\nGROUP BY c.first_name, c.last_name;"}, {"role": "user", "content": "But I need only those clients who registered after January 1, 2022."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, SUM(i.total_amount) AS total_amount_sum\nFROM legal_services.clients c\nJOIN legal_services.invoices i ON c.client_id = i.client_id\nWHERE i.status IN ('Sent', 'Paid')\n AND c.date_registered > '2022-01-01'\nGROUP BY c.first_name, c.last_name;"}, {"role": "user", "content": "Also, include a count of invoices for each client and only show those with at least 5 invoices, sorted by the invoice count descending."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name,\n SUM(i.total_amount) AS total_amount_sum,\n COUNT(i.invoice_id) AS invoice_count\nFROM legal_services.clients c\nJOIN legal_services.invoices i ON c.client_id = i.client_id\nWHERE i.status IN ('Sent', 'Paid')\n AND c.date_registered > '2022-01-01'\nGROUP BY c.first_name, c.last_name\nHAVING COUNT(i.invoice_id) >= 5\nORDER BY invoice_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "List all beneficiaries who have a contact_info field containing an email address, showing their full names and relationship to the policyholder."}, {"role": "assistant", "content": "SELECT first_name, last_name, relationship FROM insurance.policy_beneficiaries WHERE contact_info LIKE '%@%';"}, {"role": "user", "content": "Now include only those beneficiaries who are listed as 'parent' in the relationship field."}, {"role": "assistant", "content": "SELECT first_name, last_name, relationship FROM insurance.policy_beneficiaries WHERE contact_info LIKE '%@%' AND relationship = 'parent';"}], "system": "You are an SQL statement expert. Given the table structure 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": "List developers along with the count of games they released in the 2010s (2010-2019)."}, {"role": "assistant", "content": "SELECT\n d.developer_id,\n d.name,\n COUNT(g.game_id) AS games_in_2010s_count\nFROM\n gaming_technology.developers d\nJOIN\n gaming_technology.games g ON d.developer_id = g.developer_id\nWHERE\n EXTRACT(YEAR FROM g.release_date) BETWEEN 2010 AND 2019\nGROUP BY\n d.developer_id, d.name;"}, {"role": "user", "content": "Only show developers who released more than 3 games in that decade."}, {"role": "assistant", "content": "SELECT\n d.developer_id,\n d.name,\n COUNT(g.game_id) AS games_in_2010s_count\nFROM\n gaming_technology.developers d\nJOIN\n gaming_technology.games g ON d.developer_id = g.developer_id\nWHERE\n EXTRACT(YEAR FROM g.release_date) BETWEEN 2010 AND 2019\nGROUP BY\n d.developer_id, d.name\nHAVING\n COUNT(g.game_id) > 3;"}, {"role": "user", "content": "Can you also include the developer's country in the results?"}, {"role": "assistant", "content": "SELECT\n d.developer_id,\n d.name,\n d.country,\n COUNT(g.game_id) AS games_in_2010s_count\nFROM\n gaming_technology.developers d\nJOIN\n gaming_technology.games g ON d.developer_id = g.developer_id\nWHERE\n EXTRACT(YEAR FROM g.release_date) BETWEEN 2010 AND 2019\nGROUP BY\n d.developer_id, d.name, d.country\nHAVING\n COUNT(g.game_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 gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.games ( game_id uuid 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.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": "Identify all instances where a vehicle's odometer_reading increased by more than 500 miles between two consecutive fuel log entries."}, {"role": "assistant", "content": "SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n a.log_timestamp AS previous_time,\n b.log_timestamp AS next_time,\n b.odometer_reading - a.odometer_reading AS mile_increase\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500;"}, {"role": "user", "content": "Now restrict these increases to those where the time difference between entries is less than 7 days."}, {"role": "assistant", "content": "SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n a.log_timestamp AS previous_time,\n b.log_timestamp AS next_time,\n b.odometer_reading - a.odometer_reading AS mile_increase,\n EXTRACT(epoch FROM (b.log_timestamp - a.log_timestamp))/3600 AS hours_diff\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500\n AND b.log_timestamp - a.log_timestamp < INTERVAL '7 days';"}, {"role": "user", "content": "Also include both the mile increase and the time difference in hours in the final output columns."}, {"role": "assistant", "content": "SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n b.odometer_reading - a.odometer_reading AS mile_increase,\n EXTRACT(epoch FROM (b.log_timestamp - a.log_timestamp))/3600 AS hours_difference\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500\n AND b.log_timestamp - a.log_timestamp < INTERVAL '7 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 transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\n"} |
| {"conversations": [{"role": "user", "content": "List all users who performed more than 10 'view' actions in the logs, along with their action counts."}, {"role": "assistant", "content": "SELECT user_id, COUNT(log_id) AS view_action_count FROM trading_platform.logs WHERE action = 'view' GROUP BY user_id HAVING COUNT(log_id) > 10 ORDER BY view_action_count DESC;"}, {"role": "user", "content": "Now include only users who performed these actions on cryptocurrency assets."}, {"role": "assistant", "content": "SELECT l.user_id, COUNT(l.log_id) AS view_action_count FROM trading_platform.logs l JOIN trading_platform.assets a ON l.details->>'asset_id' = a.asset_id WHERE l.action = 'view' AND a.type = 'cryptocurrency' GROUP BY l.user_id HAVING COUNT(l.log_id) > 10 ORDER BY view_action_count DESC;"}, {"role": "user", "content": "Actually, I want to see the most recent timestamp of their last view action as well."}, {"role": "assistant", "content": "SELECT l.user_id, COUNT(l.log_id) AS view_action_count, MAX(l.logged_at) AS last_view_time FROM trading_platform.logs l JOIN trading_platform.assets a ON l.details->>'asset_id' = a.asset_id WHERE l.action = 'view' AND a.type = 'cryptocurrency' GROUP BY l.user_id HAVING COUNT(l.log_id) > 10 ORDER BY view_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 all payments made using a credit card, including guest_id, amount, payment_method, and payment_timestamp."}, {"role": "assistant", "content": "SELECT guest_id, amount, payment_method, payment_timestamp FROM hospitality_technology.payments WHERE payment_method = 'CreditCard';"}, {"role": "user", "content": "Could you also include the last four digits of the card used for each payment?"}, {"role": "assistant", "content": "SELECT guest_id, amount, payment_method, card_last_four, payment_timestamp FROM hospitality_technology.payments WHERE payment_method = 'CreditCard';"}], "system": "You are an SQL statement expert. Given the table structure 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.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": "Find all pairs of users who registered at exactly the same timestamp, showing both user IDs, usernames, and the shared registration timestamp."}, {"role": "assistant", "content": "SELECT u1.user_id AS user_id_1, u1.username AS username_1, u2.user_id AS user_id_2, u2.username AS username_2, u1.created_at\nFROM web3.users u1\nJOIN web3.users u2\n ON u1.created_at = u2.created_at\n AND u1.user_id < u2.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 web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} |
| {"conversations": [{"role": "user", "content": "Show me the latest 10 NFTs minted on Ethereum with their name, mint_block_number, collection name and floor price."}, {"role": "assistant", "content": "SELECT nm.name,\n nm.token_id,\n nm.mint_block_number,\n nc.name AS collection_name,\n nc.floor_price\nFROM nft_metadata nm\nJOIN nft_collections nc\n ON nm.contract_address = nc.contract_address\n AND nm.blockchain = nc.blockchain\nWHERE nm.blockchain = 'Ethereum'\nORDER BY nm.mint_block_number DESC\nLIMIT 10;"}, {"role": "user", "content": "Filter to only include NFTs with rarity_score > 80."}, {"role": "assistant", "content": "SELECT nm.name,\n nm.token_id,\n nm.mint_block_number,\n nc.name AS collection_name,\n nc.floor_price\nFROM nft_metadata nm\nJOIN nft_collections nc\n ON nm.contract_address = nc.contract_address\n AND nm.blockchain = nc.blockchain\nWHERE nm.blockchain = 'Ethereum'\n AND nm.rarity_score > 80\nORDER BY nm.mint_block_number DESC\nLIMIT 10;"}, {"role": "user", "content": "Also include the number of unique holders of each NFT by joining nft_holders."}, {"role": "assistant", "content": "SELECT nm.name,\n nm.token_id,\n nm.mint_block_number,\n nc.name AS collection_name,\n nc.floor_price,\n COUNT(DISTINCT nh.wallet_address) AS holder_count\nFROM nft_metadata nm\nJOIN nft_collections nc\n ON nm.contract_address = nc.contract_address\n AND nm.blockchain = nc.blockchain\nJOIN nft_holders nh\n ON nm.contract_address = nh.contract_address\n AND nm.token_id = nh.token_id\nWHERE nm.blockchain = 'Ethereum'\n AND nm.rarity_score > 80\nGROUP BY nm.name, nm.token_id, nm.mint_block_number, nc.name, nc.floor_price\nORDER BY nm.mint_block_number DESC\nLIMIT 10;"}, {"role": "user", "content": "Only show NFTs with holder_count > 5."}, {"role": "assistant", "content": "SELECT nm.name,\n nm.token_id,\n nm.mint_block_number,\n nc.name AS collection_name,\n nc.floor_price,\n COUNT(DISTINCT nh.wallet_address) AS holder_count\nFROM nft_metadata nm\nJOIN nft_collections nc\n ON nm.contract_address = nc.contract_address\n AND nm.blockchain = nc.blockchain\nJOIN nft_holders nh\n ON nm.contract_address = nh.contract_address\n AND nm.token_id = nh.token_id\nWHERE nm.blockchain = 'Ethereum'\n AND nm.rarity_score > 80\nGROUP BY nm.name, nm.token_id, nm.mint_block_number, nc.name, nc.floor_price\nHAVING COUNT(DISTINCT nh.wallet_address) > 5\nORDER BY nm.mint_block_number 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 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 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 ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE 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 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_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\n"} |
| {"conversations": [{"role": "user", "content": "Give me the count of locations per country and type. List country, type, and location_count."}, {"role": "assistant", "content": "SELECT country, type, COUNT(*) AS location_count\nFROM transportation.locations\nGROUP BY country, type;"}, {"role": "user", "content": "Only include types where the location count is at least 3."}, {"role": "assistant", "content": "SELECT country, type, COUNT(*) AS location_count\nFROM transportation.locations\nGROUP BY country, type\nHAVING COUNT(*) >= 3;"}, {"role": "user", "content": "Now, sort the results by country ascending and then by location_count descending."}, {"role": "assistant", "content": "SELECT country, type, COUNT(*) AS location_count\nFROM transportation.locations\nGROUP BY country, type\nHAVING COUNT(*) >= 3\nORDER BY country ASC, location_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.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)\n"} |
| {"conversations": [{"role": "user", "content": "What is the most recent closing price for each security, along with its ticker symbol?"}, {"role": "assistant", "content": "WITH LatestMarketData AS (\n SELECT\n security_id,\n close_price,\n data_timestamp,\n ROW_NUMBER() OVER(PARTITION BY security_id ORDER BY data_timestamp DESC) as rn\n FROM financial_services.market_data\n)\nSELECT\n s.ticker_symbol,\n lmd.close_price\nFROM financial_services.securities s\nJOIN LatestMarketData lmd ON s.security_id = lmd.security_id\nWHERE lmd.rn = 1;"}, {"role": "user", "content": "Filter the results to only show securities whose latest closing price is above 100."}, {"role": "assistant", "content": "WITH LatestMarketData AS (\n SELECT\n security_id,\n close_price,\n data_timestamp,\n ROW_NUMBER() OVER(PARTITION BY security_id ORDER BY data_timestamp DESC) as rn\n FROM financial_services.market_data\n)\nSELECT\n s.ticker_symbol,\n lmd.close_price\nFROM financial_services.securities s\nJOIN LatestMarketData lmd ON s.security_id = lmd.security_id\nWHERE lmd.rn = 1 AND lmd.close_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 financial_services.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address text NOT NULL, city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status character varying(32) NOT NULL, risk_profile character varying(50), PRIMARY KEY (customer_id) )\nCREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) )\nCREATE TABLE financial_services.securities ( security_id character varying(64) NOT NULL, ticker_symbol character varying(20) NOT NULL UNIQUE, isin_code character varying(12) UNIQUE, cusip_code character varying(9) UNIQUE, security_name text NOT NULL, security_type character varying(50) NOT NULL, exchange character varying(50), currency character varying(3) NOT NULL, issuer_name character varying(255), sector character varying(100), last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (security_id) )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\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": "List all claims that have at least one document of type 'INVOICE', including the claim ID, incident date, estimated loss, and the document's file name."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, c.estimated_loss, d.file_name\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.document_type = 'INVOICE';"}, {"role": "user", "content": "Also show the file size in bytes and the uploaded date for each document."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, c.estimated_loss, d.file_name, d.file_size_bytes, d.uploaded_at\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.document_type = 'INVOICE';"}, {"role": "user", "content": "Actually, just show the claims where the document file size is greater than 100,000 bytes."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, c.estimated_loss, d.file_name, d.file_size_bytes, d.uploaded_at\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.document_type = 'INVOICE'\n AND d.file_size_bytes > 100000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.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": "For each day, can you show me the total number of unique players and total number of sessions per server?"}, {"role": "assistant", "content": "SELECT server_id, date_trunc('day', start_time) AS session_day, COUNT(DISTINCT player_id) AS unique_players, COUNT(session_id) AS total_sessions\nFROM gaming_technology.game_sessions\nGROUP BY server_id, session_day;"}, {"role": "user", "content": "Can you adjust it to only include data for days where there were at least 20 unique players on a server?"}, {"role": "assistant", "content": "SELECT server_id, session_day, unique_players, total_sessions\nFROM (\n SELECT server_id, date_trunc('day', start_time) AS session_day, COUNT(DISTINCT player_id) AS unique_players, COUNT(session_id) AS total_sessions\n FROM gaming_technology.game_sessions\n GROUP BY server_id, session_day\n) sub\nWHERE unique_players >= 20;"}, {"role": "user", "content": "Actually, add the average score for each server and day as well."}, {"role": "assistant", "content": "SELECT server_id, session_day, unique_players, total_sessions, avg_score\nFROM (\n SELECT server_id, date_trunc('day', start_time) AS session_day, COUNT(DISTINCT player_id) AS unique_players, COUNT(session_id) AS total_sessions, AVG(score) AS avg_score\n FROM gaming_technology.game_sessions\n GROUP BY server_id, session_day\n) sub\nWHERE unique_players >= 20;"}, {"role": "user", "content": "Now please only show results for servers where avg_score is at least 300."}, {"role": "assistant", "content": "SELECT server_id, session_day, unique_players, total_sessions, avg_score\nFROM (\n SELECT server_id, date_trunc('day', start_time) AS session_day, COUNT(DISTINCT player_id) AS unique_players, COUNT(session_id) AS total_sessions, AVG(score) AS avg_score\n FROM gaming_technology.game_sessions\n GROUP BY server_id, session_day\n) sub\nWHERE unique_players >= 20 AND avg_score >= 300;"}], "system": "You are an SQL statement expert. Given the table structure 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 )\n"} |
| {"conversations": [{"role": "user", "content": "Show a list of clients whose status is 'inactive', including their first and last name, email, phone, and date registered."}, {"role": "assistant", "content": "SELECT first_name, last_name, email, phone, date_registered\nFROM legal_services.clients\nWHERE status = 'inactive';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\nCREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n case_id character varying(64) NOT NULL, -- FK to cases table\n document_name character varying(255) NOT NULL, -- name of the document file\n document_type character varying(100), -- e.g., Pleading, Contract, Evidence, Correspondence\n storage_path text NOT NULL, -- path or reference to the document storage location\n uploaded_by_lawyer_id character varying(64), -- FK to lawyers table (who uploaded it)\n upload_timestamp timestamp NOT NULL, -- time the document was uploaded\n version integer DEFAULT 1, -- document version number\n description text, -- brief description or notes about the document\n PRIMARY KEY (document_id)\n)\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n"} |
| {"conversations": [{"role": "user", "content": "How many times is hashtag 'H001' used across all posts?"}, {"role": "assistant", "content": "SELECT COUNT(*)\nFROM social_media.post_hashtags\nWHERE hashtag_id = 'H001';"}], "system": "You are an SQL statement expert. Given the table structure 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.post_hashtags ( post_hashtag_id text, post_id text, hashtag_id text )\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": "Show me wallet addresses that hold more than 1000 of any ERC1155 token, along with the token ID and contract address."}, {"role": "assistant", "content": "SELECT wallet_address, token_id, contract_address FROM erc20_balances WHERE CAST(amount AS decimal) > 1000;"}, {"role": "user", "content": "I think there's an error in your query - it should be using the nft_metadata table for ERC1155 tokens. Also, can you include the token name from the nft_metadata table?"}, {"role": "assistant", "content": "SELECT nm.owner as wallet_address, nm.token_id, nm.contract_address, nm.name FROM nft_metadata nm WHERE nm.erc_type = 'ERC1155' AND CAST(nm.amount AS decimal) > 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 erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_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 nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE token_prices ( uuid 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 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 ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_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_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": "What is the average difficulty and the maximum nonce value for all blocks recorded?"}, {"role": "assistant", "content": "SELECT AVG(difficulty), MAX(nonce) FROM blockchain.blocks"}], "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.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer )\n"} |
| {"conversations": [{"role": "user", "content": "Show me the top 5 tokens by USD value held on the Binance Smart Chain, along with their average price and total balance."}, {"role": "assistant", "content": "SELECT token_symbol, SUM(usd_value) as total_usd_value, AVG(price) as average_price, SUM(balance) as total_balance FROM cex_token_balance WHERE chain = 'Binance Smart Chain' GROUP BY token_symbol ORDER BY total_usd_value DESC LIMIT 5;"}, {"role": "user", "content": "Actually, I want to see this for the Polygon chain instead, and only include tokens with a total balance over 1000."}, {"role": "assistant", "content": "SELECT token_symbol, SUM(usd_value) as total_usd_value, AVG(price) as average_price, SUM(balance) as total_balance FROM cex_token_balance WHERE chain = 'Polygon' GROUP BY token_symbol HAVING SUM(balance) > 1000 ORDER BY total_usd_value DESC LIMIT 5;"}, {"role": "user", "content": "Can you add the exchange name to these results and filter to only show Binance holdings?"}, {"role": "assistant", "content": "SELECT exchange, token_symbol, SUM(usd_value) as total_usd_value, AVG(price) as average_price, SUM(balance) as total_balance FROM cex_token_balance WHERE chain = 'Polygon' AND exchange = 'Binance' GROUP BY exchange, token_symbol HAVING SUM(balance) > 1000 ORDER BY total_usd_value DESC LIMIT 5;"}, {"role": "user", "content": "Now order these results by total balance instead of USD value."}, {"role": "assistant", "content": "SELECT exchange, token_symbol, SUM(usd_value) as total_usd_value, AVG(price) as average_price, SUM(balance) as total_balance FROM cex_token_balance WHERE chain = 'Polygon' AND exchange = 'Binance' GROUP BY exchange, token_symbol HAVING SUM(balance) > 1000 ORDER BY total_balance 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 cex_token_balance ( snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp chain character varying(128) NOT NULL, -- the chain that the token resides address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX exchange character varying(512) NOT NULL, -- a centralized exchange name token_address character varying(128) NOT NULL, -- token contract address token_symbol character varying(512), --token symbol balance numeric(38,10), -- token balance usd_value numeric(38,14), -- value of the token held in USD price double precision, --price of the token in USD ,PRIMARY KEY (snapshot_time, exchange, address, chain, token_address) )\n"} |
|
|