diff --git "a/data.jsonl" "b/data.jsonl" --- "a/data.jsonl" +++ "b/data.jsonl" @@ -1,250 +1,250 @@ -{"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 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.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 (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "List the first name and last name of citizens who have uploaded documents that are still valid, together with the type of document and the upload timestamp."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, d.document_type, d.upload_timestamp\nFROM government_services.documents d\nJOIN government_services.citizens c ON d.citizen_id = c.citizen_id\nWHERE d.expiry_date IS NULL OR d.expiry_date >= CURRENT_DATE;"}, {"role": "user", "content": "Now, only include documents that have been verified, and show also the first and last name of the employee who verified each document."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, d.document_type, d.upload_timestamp, e.first_name AS verifier_first_name, e.last_name AS verifier_last_name\nFROM government_services.documents d\nJOIN government_services.citizens c ON d.citizen_id = c.citizen_id\nJOIN government_services.employees e ON d.verified_by_employee_id = e.employee_id\nWHERE (d.expiry_date IS NULL OR d.expiry_date >= CURRENT_DATE) AND d.verification_status = 'Verified';"}]} -{"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 trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )\n", "conversations": [{"role": "user", "content": "List all asset symbols where the asset type is 'token'."}, {"role": "assistant", "content": "SELECT symbol FROM trading_platform.assets WHERE type = 'token';"}]} -{"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 government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\n", "conversations": [{"role": "user", "content": "For all scheduled appointments in the next 14 days, list the appointment ID, scheduled start time, the name of the service, and the standard fee."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.scheduled_start_time, s.service_name, s.standard_fee\nFROM government_services.appointments a\nJOIN government_services.services s ON a.service_id = s.service_id\nWHERE a.status = 'Scheduled'\n AND a.scheduled_start_time >= CURRENT_DATE\n AND a.scheduled_start_time < CURRENT_DATE + INTERVAL '14 day';"}]} -{"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 insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\nCREATE TABLE insurance.policies (\n policy_id character varying(64) NOT NULL, -- unique identifier for the policy\n customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)\n product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)\n agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)\n policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number\n start_date date NOT NULL, -- date the policy coverage begins\n end_date date NOT NULL, -- date the policy coverage ends\n premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term\n coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered\n deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in\n status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending\n issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the policy was issued\n cancellation_date date,\n cancellation_reason text,\n PRIMARY KEY (policy_id)\n)\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.premium_payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment\n policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)\n payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received\n amount_paid numeric(12, 2) NOT NULL, -- amount of the payment\n payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check\n transaction_reference character varying(128) UNIQUE, -- reference from payment processor\n due_date date, -- due date for this payment installment\n payment_period_start date, -- start date of the period this payment covers\n payment_period_end date, -- end date of the period this payment covers\n status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded\n PRIMARY KEY (payment_id)\n)\nCREATE TABLE insurance.claim_documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n claim_id character varying(64) NOT NULL, -- identifier of the claim this document relates to (FK to claims)\n document_type character varying(50) NOT NULL, -- e.g., Police Report, Photo, Invoice, Medical Bill\n file_name character varying(255) NOT NULL, -- original name of the uploaded file\n file_path character varying(512) NOT NULL, -- storage path (e.g., S3 URL, network path)\n file_size_bytes integer, -- size of the file in bytes\n mime_type character varying(100), -- MIME type of the file (e.g., 'image/jpeg', 'application/pdf')\n uploaded_by character varying(64), -- identifier of the user/system who uploaded (FK to users/customers)\n uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- time of upload\n description text, -- optional description of the document\n PRIMARY KEY (document_id)\n)\n", "conversations": [{"role": "user", "content": "Show me all active policies for customers who live in California, along with their total premium payments made so far."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount;"}, {"role": "user", "content": "I also want to see how many claims each of these policies has had."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made, COUNT(cl.claim_id) AS claim_count FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id LEFT JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount;"}, {"role": "user", "content": "Actually, I only want to see policies that have at least one claim."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made, COUNT(cl.claim_id) AS claim_count FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount HAVING COUNT(cl.claim_id) > 0;"}, {"role": "user", "content": "Now show me the average settlement amount for these policies' claims."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount, SUM(pp.amount_paid) AS total_payments_made, COUNT(cl.claim_id) AS claim_count, AVG(cl.settlement_amount) AS avg_settlement FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'Active' AND c.state = 'California' GROUP BY p.policy_id, p.policy_number, c.first_name, c.last_name, p.premium_amount HAVING COUNT(cl.claim_id) > 0;"}]} -{"system": "You are an 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 erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner 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 sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_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 ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n", "conversations": [{"role": "user", "content": "List the object ID, collection type, and owner for all Sui NFTs with status 'exists'."}, {"role": "assistant", "content": "SELECT object_id, collection_type, owner FROM sui_nfts WHERE status = 'exists';"}, {"role": "user", "content": "Now, only include NFTs from collections with package ID starting with '0x123'."}, {"role": "assistant", "content": "SELECT object_id, collection_type, owner FROM sui_nfts WHERE status = 'exists' AND package_id LIKE '0x123%';"}, {"role": "user", "content": "Also show the name of each NFT and order the results by name ascending."}, {"role": "assistant", "content": "SELECT object_id, collection_type, owner, name FROM sui_nfts WHERE status = 'exists' AND package_id LIKE '0x123%' ORDER BY name ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "Find application IDs that have received notifications with both a 'Sent' status and a 'Failed' status."}, {"role": "assistant", "content": "SELECT application_id FROM government_services.notifications WHERE status IN ('Sent', 'Failed') GROUP BY application_id HAVING COUNT(DISTINCT status) = 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid, player_id uuid, game_id uuid, server_id uuid, start_time timestamp with time zone, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb )\n", "conversations": [{"role": "user", "content": "Show me all game sessions that do not have a score recorded. List the session_id, player_id, game_id, and start_time."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, start_time FROM gaming_technology.game_sessions WHERE score IS NULL;"}, {"role": "user", "content": "For each game, how many of its sessions have a missing score? Show game_id and the count."}, {"role": "assistant", "content": "SELECT game_id, COUNT(session_id) AS sessions_with_no_score FROM gaming_technology.game_sessions WHERE score IS NULL GROUP BY game_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n", "conversations": [{"role": "user", "content": "List all users whose email notifications are disabled, showing their usernames and the last time their settings were updated."}, {"role": "assistant", "content": "SELECT u.username, us.updated_at\nFROM social_media.users u\nJOIN social_media.user_settings us ON u.user_id = us.user_id\nWHERE us.email_notifications_enabled = false;"}]} -{"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 legal_services.time_entries ( entry_id text PRIMARY KEY, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable bool, is_billed bool, invoice_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List each case_id along with the total hours worked and total billed amount for that case."}, {"role": "assistant", "content": "SELECT case_id, SUM(hours_spent) AS total_hours, SUM(hours_spent * billing_rate) AS total_billed_amount FROM legal_services.time_entries GROUP BY case_id;"}, {"role": "user", "content": "Only include entries that have been billed."}, {"role": "assistant", "content": "SELECT case_id, SUM(hours_spent) AS total_hours, SUM(hours_spent * billing_rate) AS total_billed_amount FROM legal_services.time_entries WHERE is_billed = TRUE GROUP BY case_id;"}, {"role": "user", "content": "And restrict to cases worked on in February 2024 only."}, {"role": "assistant", "content": "SELECT case_id, SUM(hours_spent) AS total_hours, SUM(hours_spent * billing_rate) AS total_billed_amount FROM legal_services.time_entries WHERE is_billed = TRUE AND date_worked >= '2024-02-01' AND date_worked < '2024-03-01' GROUP BY case_id;"}, {"role": "user", "content": "Please order the results by total_billed_amount descending."}, {"role": "assistant", "content": "SELECT case_id, SUM(hours_spent) AS total_hours, SUM(hours_spent * billing_rate) AS total_billed_amount FROM legal_services.time_entries WHERE is_billed = TRUE AND date_worked >= '2024-02-01' AND date_worked < '2024-03-01' GROUP BY case_id ORDER BY total_billed_amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.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.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "Which claims have at least one document uploaded by an agent located in 'NY'? Show the claim_id, document_type, file_name, uploaded_by, and the agent's first and last name."}, {"role": "assistant", "content": "SELECT cd.claim_id, cd.document_type, cd.file_name, cd.uploaded_by, a.first_name, a.last_name\nFROM insurance.claim_documents cd\nJOIN insurance.agents a ON cd.uploaded_by = a.agent_id\nWHERE a.license_state = 'NY';"}]} -{"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 social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "Show me all conversations that have more than 10 messages, along with the group name and the usernames of their participants."}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, u.username\nFROM social_media.conversations c\nJOIN social_media.messages m ON c.conversation_id = m.conversation_id\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nGROUP BY c.conversation_id, c.group_name, u.username\nHAVING COUNT(m.message_id) > 10;"}, {"role": "user", "content": "Instead, can you only show group chats where the group name contains 'Study' and list the time each participant joined?"}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, u.username, cp.joined_at\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true AND c.group_name ILIKE '%Study%';"}]} -{"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 social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )\nCREATE TABLE social_media.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": "How many users have their profile pictures set and also have written a bio?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS user_count\nFROM social_media.users\nWHERE profile_picture_url IS NOT NULL AND profile_picture_url <> ''\n AND bio IS NOT NULL AND bio <> '';"}]} -{"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 web3.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show the user_id, username, and email for users who registered at the same timestamp as another user."}, {"role": "assistant", "content": "SELECT u1.user_id, u1.username, u1.email FROM web3.users u1 JOIN web3.users u2 ON u1.created_at = u2.created_at AND u1.user_id <> u2.user_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.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.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\n", "conversations": [{"role": "user", "content": "Count the number of maintenance services per service_type and show service_type and service_count."}, {"role": "assistant", "content": "SELECT service_type, COUNT(*) AS service_count\nFROM transportation.maintenance_logs\nGROUP BY service_type;"}, {"role": "user", "content": "Only include service types with more than 5 services and order the results by service_count descending."}, {"role": "assistant", "content": "SELECT service_type, COUNT(*) AS service_count\nFROM transportation.maintenance_logs\nGROUP BY service_type\nHAVING COUNT(*) > 5\nORDER BY service_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show the total number of likes made by each user, including the user_id and their like count."}, {"role": "assistant", "content": "SELECT user_id, COUNT(*) AS like_count FROM social_media.likes GROUP BY user_id;"}, {"role": "user", "content": "Only show users who have made more than 50 likes."}, {"role": "assistant", "content": "SELECT user_id, COUNT(*) AS like_count FROM social_media.likes GROUP BY user_id HAVING COUNT(*) > 50;"}]} -{"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 social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\n", "conversations": [{"role": "user", "content": "Show me the usernames and full names of all users who have liked at least one post that was created in May 2024."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, u.full_name\nFROM social_media.users u\nJOIN social_media.likes l ON u.user_id = l.user_id\nJOIN social_media.posts p ON l.post_id = p.post_id\nWHERE p.created_at >= '2024-05-01' AND p.created_at < '2024-06-01';"}, {"role": "user", "content": "Some of these users appear multiple times. Can you also include the count of distinct posts they have liked from May 2024, as liked_posts_count?"}, {"role": "assistant", "content": "SELECT u.username, u.full_name, COUNT(DISTINCT p.post_id) AS liked_posts_count\nFROM social_media.users u\nJOIN social_media.likes l ON u.user_id = l.user_id\nJOIN social_media.posts p ON l.post_id = p.post_id\nWHERE p.created_at >= '2024-05-01' AND p.created_at < '2024-06-01'\nGROUP BY u.user_id, u.username, u.full_name;"}, {"role": "user", "content": "Now, only show users who have liked more than 2 distinct posts from May 2024 and order them by liked_posts_count descending."}, {"role": "assistant", "content": "SELECT u.username, u.full_name, COUNT(DISTINCT p.post_id) AS liked_posts_count\nFROM social_media.users u\nJOIN social_media.likes l ON u.user_id = l.user_id\nJOIN social_media.posts p ON l.post_id = p.post_id\nWHERE p.created_at >= '2024-05-01' AND p.created_at < '2024-06-01'\nGROUP BY u.user_id, u.username, u.full_name\nHAVING COUNT(DISTINCT p.post_id) > 2\nORDER BY liked_posts_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )\n", "conversations": [{"role": "user", "content": "List patient insurance details, including patient ID, policy number, and subscriber name, along with the corresponding plan name for each entry."}, {"role": "assistant", "content": "SELECT T1.patient_id, T1.policy_number, T1.subscriber_name, T2.plan_name FROM healthcare.patient_insurance AS T1 JOIN healthcare.insurance_plan AS T2 ON T1.plan_id = T2.plan_id"}, {"role": "user", "content": "Modify the query to only include entries where the insurance plan type is 'PPO'."}, {"role": "assistant", "content": "SELECT T1.patient_id, T1.policy_number, T1.subscriber_name, T2.plan_name FROM healthcare.patient_insurance AS T1 JOIN healthcare.insurance_plan AS T2 ON T1.plan_id = T2.plan_id WHERE T2.plan_type = 'PPO'"}, {"role": "user", "content": "Further filter the results to show only policies marked as primary (is_primary = true) and sort the output by subscriber name in ascending order."}, {"role": "assistant", "content": "SELECT T1.patient_id, T1.policy_number, T1.subscriber_name, T2.plan_name FROM healthcare.patient_insurance AS T1 JOIN healthcare.insurance_plan AS T2 ON T1.plan_id = T2.plan_id WHERE T2.plan_type = 'PPO' AND T1.is_primary = true ORDER BY T1.subscriber_name ASC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n", "conversations": [{"role": "user", "content": "List tokens on 'Arbitrum' with liquidity over 5000000."}, {"role": "assistant", "content": "SELECT * FROM token_dexpool_info WHERE chain = 'Arbitrum' AND liquidity > 5000000;"}, {"role": "user", "content": "Filter those tokens to only include ones with a positive price change in the last 24 hours."}, {"role": "assistant", "content": "SELECT * FROM token_dexpool_info WHERE chain = 'Arbitrum' AND liquidity > 5000000 AND price_change_percentage_24h > 0;"}, {"role": "user", "content": "Order the results by 24-hour trading volume descending and show the top 5 tokens."}, {"role": "assistant", "content": "SELECT * FROM token_dexpool_info WHERE chain = 'Arbitrum' AND liquidity > 5000000 AND price_change_percentage_24h > 0 ORDER BY volume_24h DESC LIMIT 5;"}, {"role": "user", "content": "Also show their market cap and trend rank."}, {"role": "assistant", "content": "SELECT token_symbol, token_name, chain, price, liquidity, price_change_percentage_24h, volume_24h, market_cap, trend_rank FROM token_dexpool_info WHERE chain = 'Arbitrum' AND liquidity > 5000000 AND price_change_percentage_24h > 0 ORDER BY volume_24h DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.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": "Provide each developer_id, the number of games they have released, and the total items acquired across all their games."}, {"role": "assistant", "content": "SELECT g.developer_id,\n COUNT(g.game_id) AS game_count,\n SUM(pi.quantity) AS total_items_acquired\nFROM gaming_technology.games g\nJOIN gaming_technology.player_inventory pi\n ON (pi.instance_data->>'game_id')::uuid = g.game_id\nGROUP BY g.developer_id;"}, {"role": "user", "content": "Only include developers who have released more than 2 games."}, {"role": "assistant", "content": "SELECT g.developer_id,\n COUNT(g.game_id) AS game_count,\n SUM(pi.quantity) AS total_items_acquired\nFROM gaming_technology.games g\nJOIN gaming_technology.player_inventory pi\n ON (pi.instance_data->>'game_id')::uuid = g.game_id\nGROUP BY g.developer_id\nHAVING COUNT(g.game_id) > 2;"}, {"role": "user", "content": "Also require total_items_acquired to exceed 500 and sort by that value descending."}, {"role": "assistant", "content": "SELECT g.developer_id,\n COUNT(g.game_id) AS game_count,\n SUM(pi.quantity) AS total_items_acquired\nFROM gaming_technology.games g\nJOIN gaming_technology.player_inventory pi\n ON (pi.instance_data->>'game_id')::uuid = g.game_id\nGROUP BY g.developer_id\nHAVING COUNT(g.game_id) > 2\n AND SUM(pi.quantity) > 500\nORDER BY total_items_acquired DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\n", "conversations": [{"role": "user", "content": "Find pairs of players from the same country who have different last login dates. Show their usernames, country code, and last login dates. Exclude pairs where either last login date is null."}, {"role": "assistant", "content": "SELECT p1.username AS player1_username, p2.username AS player2_username, p1.country_code, p1.last_login AS player1_last_login, p2.last_login AS player2_last_login FROM gaming_technology.players p1 JOIN gaming_technology.players p2 ON p1.country_code = p2.country_code AND p1.player_id < p2.player_id WHERE p1.last_login IS NOT NULL AND p2.last_login IS NOT NULL AND p1.last_login != p2.last_login;"}, {"role": "user", "content": "Filter the results to only include pairs where the last login date difference is more than 30 days."}, {"role": "assistant", "content": "SELECT p1.username AS player1_username, p2.username AS player2_username, p1.country_code, p1.last_login AS player1_last_login, p2.last_login AS player2_last_login FROM gaming_technology.players p1 JOIN gaming_technology.players p2 ON p1.country_code = p2.country_code AND p1.player_id < p2.player_id WHERE p1.last_login IS NOT NULL AND p2.last_login IS NOT NULL AND p1.last_login != p2.last_login AND ABS(EXTRACT(EPOCH FROM (p1.last_login - p2.last_login))) > 30 * 86400;"}, {"role": "user", "content": "Exclude pairs where the country code is NULL."}, {"role": "assistant", "content": "SELECT p1.username AS player1_username, p2.username AS player2_username, p1.country_code, p1.last_login AS player1_last_login, p2.last_login AS player2_last_login FROM gaming_technology.players p1 JOIN gaming_technology.players p2 ON p1.country_code = p2.country_code AND p1.player_id < p2.player_id WHERE p1.last_login IS NOT NULL AND p2.last_login IS NOT NULL AND p1.last_login != p2.last_login AND ABS(EXTRACT(EPOCH FROM (p1.last_login - p2.last_login))) > 30 * 86400 AND p1.country_code IS NOT NULL;"}, {"role": "user", "content": "Order the results by the country code and then by the larger of the two last login dates in descending order. Limit to the top 10 results."}, {"role": "assistant", "content": "SELECT p1.username AS player1_username, p2.username AS player2_username, p1.country_code, p1.last_login AS player1_last_login, p2.last_login AS player2_last_login FROM gaming_technology.players p1 JOIN gaming_technology.players p2 ON p1.country_code = p2.country_code AND p1.player_id < p2.player_id WHERE p1.last_login IS NOT NULL AND p2.last_login IS NOT NULL AND p1.last_login != p2.last_login AND ABS(EXTRACT(EPOCH FROM (p1.last_login - p2.last_login))) > 30 * 86400 AND p1.country_code IS NOT NULL ORDER BY p1.country_code, GREATEST(p1.last_login, p2.last_login) DESC LIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n", "conversations": [{"role": "user", "content": "How many participants are there in each conversation? Return conversation_id and participant_count."}, {"role": "assistant", "content": "SELECT conversation_id,\n COUNT(*) AS participant_count\nFROM social_media.conversation_participants\nGROUP BY conversation_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 )\n", "conversations": [{"role": "user", "content": "Find all cities that contain at least one location of type 'Depot' and at least one location of type 'Station'."}, {"role": "assistant", "content": "SELECT city FROM transportation.locations WHERE type IN ('Depot', 'Station') GROUP BY city HAVING COUNT(DISTINCT CASE WHEN type = 'Depot' THEN location_id END) > 0 AND COUNT(DISTINCT CASE WHEN type = 'Station' THEN location_id END) > 0;"}]} -{"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 government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.services ( service_id.text, agency_id.text, service_name.text, description.text, category.text, eligibility_criteria.text, standard_fee.numeric, average_processing_time_days.integer, is_active.boolean, online_application_url.text )\n", "conversations": [{"role": "user", "content": "Show the IDs and registration dates of all verified citizens who could be eligible for at least one active service. Display the citizen ID and registration date."}, {"role": "assistant", "content": "SELECT DISTINCT c.citizen_id, c.registration_date\nFROM government_services.citizens c\nJOIN government_services.services s ON s.is_active = true\nWHERE c.is_verified = true;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\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 claim IDs, incident dates, and file names for all 'Accident Report' claim documents."}, {"role": "assistant", "content": "SELECT cd.claim_id, cl.incident_date, cd.file_name\nFROM insurance.claim_documents cd\nJOIN insurance.claims cl ON cd.claim_id = cl.claim_id\nWHERE cd.document_type = 'Accident Report';"}, {"role": "user", "content": "Include both 'Accident Report' and 'Theft Report' document types."}, {"role": "assistant", "content": "SELECT cd.claim_id, cl.incident_date, cd.file_name\nFROM insurance.claim_documents cd\nJOIN insurance.claims cl ON cd.claim_id = cl.claim_id\nWHERE cd.document_type IN ('Accident Report','Theft Report');"}, {"role": "user", "content": "Instead of listing each file, show the number of these documents per claim."}, {"role": "assistant", "content": "SELECT cd.claim_id, COUNT(*) AS document_count\nFROM insurance.claim_documents cd\nJOIN insurance.claims cl ON cd.claim_id = cl.claim_id\nWHERE cd.document_type IN ('Accident Report','Theft Report')\nGROUP BY cd.claim_id;"}, {"role": "user", "content": "Also restrict to claims reported in 2024 and order by document_count descending."}, {"role": "assistant", "content": "SELECT cd.claim_id, COUNT(*) AS document_count\nFROM insurance.claim_documents cd\nJOIN insurance.claims cl ON cd.claim_id = cl.claim_id\nWHERE cd.document_type IN ('Accident Report','Theft Report')\n AND EXTRACT(YEAR FROM cl.reported_date) = 2024\nGROUP BY cd.claim_id\nORDER BY document_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.services ( 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 (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\nCREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "Get the name of each agency and the count of accessible service locations it operates in. Only include agencies that have more than two accessible locations."}, {"role": "assistant", "content": "SELECT a.agency_name, COUNT(sl.location_id) AS accessible_locations\nFROM government_services.agencies a\nJOIN government_services.service_locations sl ON a.agency_id = sl.agency_id\nWHERE sl.is_accessible = TRUE\nGROUP BY a.agency_name\nHAVING COUNT(sl.location_id) > 2;"}, {"role": "user", "content": "Modify the query so that it counts distinct cities instead of locations."}, {"role": "assistant", "content": "SELECT a.agency_name, COUNT(DISTINCT sl.city) AS accessible_cities\nFROM government_services.agencies a\nJOIN government_services.service_locations sl ON a.agency_id = sl.agency_id\nWHERE sl.is_accessible = TRUE\nGROUP BY a.agency_name\nHAVING COUNT(DISTINCT sl.city) > 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 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 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 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.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 number of vehicles for each make in the system."}, {"role": "assistant", "content": "SELECT make, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY make"}, {"role": "user", "content": "Now, only show makes that have more than 3 vehicles and order them by vehicle_count descending."}, {"role": "assistant", "content": "SELECT make, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY make\nHAVING COUNT(*) > 3\nORDER BY vehicle_count DESC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "Show me all payments made using the 'CreditCard' method in USD, including payment_id, amount, and payment_timestamp."}, {"role": "assistant", "content": "SELECT payment_id, amount, payment_timestamp\nFROM hospitality_technology.payments\nWHERE payment_method = 'CreditCard'\n AND currency_code = 'USD';"}, {"role": "user", "content": "Sort these by amount descending and only include payments made after January 1, 2023."}, {"role": "assistant", "content": "SELECT payment_id, amount, payment_timestamp\nFROM hospitality_technology.payments\nWHERE payment_method = 'CreditCard'\n AND currency_code = 'USD'\n AND payment_timestamp >= '2023-01-01'\nORDER BY amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\n", "conversations": [{"role": "user", "content": "For each fuel type, list the number of unique locations where fuel refueling occurred, and also show the total quantity refueled for that fuel type and location."}, {"role": "assistant", "content": "SELECT fuel_type, location_id, COUNT(DISTINCT location_id) AS unique_location_count, SUM(quantity) AS total_quantity\nFROM transportation.fuel_logs\nGROUP BY fuel_type, location_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\n", "conversations": [{"role": "user", "content": "Show me the number of lawyers for each law firm, along with the firm's ID."}, {"role": "assistant", "content": "SELECT firm_id, COUNT(*) AS lawyer_count FROM legal_services.lawyers GROUP BY firm_id;"}, {"role": "user", "content": "Can you also include the number of partners per firm in the result?"}, {"role": "assistant", "content": "SELECT firm_id, COUNT(*) AS lawyer_count, SUM(CASE WHEN is_partner THEN 1 ELSE 0 END) AS partner_count FROM legal_services.lawyers GROUP BY firm_id;"}, {"role": "user", "content": "Please restrict the results to only those firms that have more than 3 partners."}, {"role": "assistant", "content": "SELECT firm_id, COUNT(*) AS lawyer_count, SUM(CASE WHEN is_partner THEN 1 ELSE 0 END) AS partner_count FROM legal_services.lawyers GROUP BY firm_id HAVING SUM(CASE WHEN is_partner THEN 1 ELSE 0 END) > 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nIndex 'suppliers'. Mapping: { properties: { supplier_id: { type: 'keyword' }, supplier_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, address: { type: 'text' }, country: { type: 'keyword' }, contact_person: { type: 'text', index: false }, contact_email: { type: 'keyword' }, quality_rating: { type: 'float' }, certified_date: { type: 'date' } } }. Document _id can be supplier_id.\n", "conversations": [{"role": "user", "content": "\ud2b9\uc815 \ud488\uc9c8 \ub4f1\uae09 \uc774\uc0c1\uc758 \uacf5\uae09\uc5c5\uccb4\ub97c \uc870\ud68c\ud558\uace0 \uc2f6\uc2b5\ub2c8\ub2e4. \ud488\uc9c8 \ub4f1\uae09, \uacf5\uae09\uc5c5\uccb4 \uc774\ub984, \uad6d\uac00\ub97c \ud3ec\ud568\ud574 \uc8fc\uc138\uc694."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\"]\n}"}, {"role": "user", "content": "\ud2b9\uc815 \uad6d\uac00\uc5d0 \uc18d\ud55c \uacf5\uae09\uc5c5\uccb4\ub9cc \ucd94\uac00\ub85c \ud544\ud130\ub9c1\ud558\uace0 \uc2f6\uc2b5\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, \uc77c\ubcf8 \uc18c\uc18d \uacf5\uae09\uc5c5\uccb4\ub85c \uc81c\ud55c\ud558\uace0 \uc2f6\uc2b5\ub2c8\ub2e4."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n {\n \"term\": {\n \"country\": \"Japan\"\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\"]\n}"}, {"role": "user", "content": "\uc5f0\ub77d\ucc98 \ub2f4\ub2f9\uc790 \uc774\ub984\uacfc \uc778\uc99d \ub0a0\uc9dc\ub3c4 \uacb0\uacfc\uc5d0 \ud3ec\ud568\ud574 \uc8fc\uc138\uc694."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n {\n \"term\": {\n \"country\": \"Japan\"\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\", \"contact_person\", \"certified_date\"]\n}"}, {"role": "user", "content": "\uc778\uc99d \ub0a0\uc9dc\ub97c \uae30\uc900\uc73c\ub85c \uc624\ub984\ucc28\uc21c \uc815\ub82c\uc744 \ucd94\uac00\ud574 \uc8fc\uc138\uc694."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 4.0\n }\n }\n },\n {\n \"term\": {\n \"country\": \"Japan\"\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"country\", \"quality_rating\", \"contact_person\", \"certified_date\"],\n \"sort\": [\n {\n \"certified_date\": {\n \"order\": \"asc\"\n }\n }\n ]\n}"}]} -{"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 gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\n", "conversations": [{"role": "user", "content": "Give me the count of developers per country."}, {"role": "assistant", "content": "SELECT country,\n COUNT(*) AS developer_count\nFROM gaming_technology.developers\nGROUP BY country;\n"}, {"role": "user", "content": "Actually, include only countries with more than 5 developers."}, {"role": "assistant", "content": "SELECT country,\n COUNT(*) AS developer_count\nFROM gaming_technology.developers\nGROUP BY country\nHAVING COUNT(*) > 5;\n"}, {"role": "user", "content": "Also calculate the average founded_year per country as avg_year."}, {"role": "assistant", "content": "SELECT country,\n COUNT(*) AS developer_count,\n AVG(founded_year) AS avg_year\nFROM gaming_technology.developers\nGROUP BY country\nHAVING COUNT(*) > 5;\n"}, {"role": "user", "content": "Order the results by avg_year descending."}, {"role": "assistant", "content": "SELECT country,\n COUNT(*) AS developer_count,\n AVG(founded_year) AS avg_year\nFROM gaming_technology.developers\nGROUP BY country\nHAVING COUNT(*) > 5\nORDER BY avg_year DESC;\n"}]} -{"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 social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\n", "conversations": [{"role": "user", "content": "Show me the usernames and email addresses for users who have a non-empty bio and are verified."}, {"role": "assistant", "content": "SELECT username, email FROM social_media.users WHERE bio IS NOT NULL AND bio != '' AND is_verified = TRUE;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id.text, username.text, email.text, password_hash.text, full_name.text, profile_picture_url.text, bio.text, location.text, created_at.timestamp, updated_at.timestamp, is_verified.boolean )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id.text, user_id.text, theme.text, email_notifications_enabled.boolean, push_notifications_enabled.boolean, private_profile.boolean, updated_at.timestamp )\n", "conversations": [{"role": "user", "content": "List the username and full name of all users who have set their profile to private."}, {"role": "assistant", "content": "SELECT u.username, u.full_name FROM social_media.users u JOIN social_media.user_settings us ON u.user_id = us.user_id WHERE us.private_profile = TRUE;"}, {"role": "user", "content": "Now, narrow down the list to only show those users who also have email notifications enabled."}, {"role": "assistant", "content": "SELECT u.username, u.full_name FROM social_media.users u JOIN social_media.user_settings us ON u.user_id = us.user_id WHERE us.private_profile = TRUE AND us.email_notifications_enabled = TRUE;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\n", "conversations": [{"role": "user", "content": "For each contract, can you show the number of different types of events it has emitted along with the contract ID?"}, {"role": "assistant", "content": "SELECT contract_id, COUNT(DISTINCT event_name) AS distinct_event_types FROM web3.events GROUP BY contract_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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": "Find all pairs of inventory entries where the same player acquired the same item twice. Show the player_id, item_id, the earlier inventory_id as first_inv, and the later inventory_id as second_inv."}, {"role": "assistant", "content": "SELECT p1.player_id,\n p1.item_id,\n p1.inventory_id AS first_inv,\n p2.inventory_id AS second_inv\nFROM gaming_technology.player_inventory p1\nJOIN gaming_technology.player_inventory p2\n ON p1.player_id = p2.player_id\n AND p1.item_id = p2.item_id\n AND p1.acquired_at < p2.acquired_at;"}, {"role": "user", "content": "Also include the time difference in minutes between the two acquisitions as diff_minutes."}, {"role": "assistant", "content": "SELECT p1.player_id,\n p1.item_id,\n p1.inventory_id AS first_inv,\n p2.inventory_id AS second_inv,\n EXTRACT(EPOCH FROM (p2.acquired_at - p1.acquired_at)) / 60 AS diff_minutes\nFROM gaming_technology.player_inventory p1\nJOIN gaming_technology.player_inventory p2\n ON p1.player_id = p2.player_id\n AND p1.item_id = p2.item_id\n AND p1.acquired_at < p2.acquired_at;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 pairs of fuel log entries for the same vehicle that occurred more than 7 days apart, showing vehicle_id, first_log_id, second_log_id, and the time difference in days."}, {"role": "assistant", "content": "SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))/86400 AS days_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days';"}, {"role": "user", "content": "Now filter to only include pairs where the quantity increased by at least 50 units."}, {"role": "assistant", "content": "SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))/86400 AS days_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days'\nWHERE (f2.quantity - f1.quantity) >= 50;"}, {"role": "user", "content": "Also display the difference in total_cost between the two logs."}, {"role": "assistant", "content": "SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))/86400 AS days_difference,\n (f2.quantity - f1.quantity) AS quantity_difference,\n (f2.total_cost - f1.total_cost) AS cost_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days'\nWHERE (f2.quantity - f1.quantity) >= 50;"}]} -{"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 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": "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 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 insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\n", "conversations": [{"role": "user", "content": "List the product_name and description for all active products."}, {"role": "assistant", "content": "SELECT product_name, description FROM insurance.insurance_products WHERE is_active = true;"}, {"role": "user", "content": "Can you also include the product_type and order the results by product_name?"}, {"role": "assistant", "content": "SELECT product_name, description, product_type FROM insurance.insurance_products WHERE is_active = true ORDER BY product_name;"}, {"role": "user", "content": "Now, only show products of type 'Life' and exclude the description column."}, {"role": "assistant", "content": "SELECT product_name, product_type FROM insurance.insurance_products WHERE is_active = true AND product_type = 'Life' ORDER BY product_name;"}, {"role": "user", "content": "Finally, just count how many 'Life' products are active."}, {"role": "assistant", "content": "SELECT count(*) FROM insurance.insurance_products WHERE is_active = true AND product_type = 'Life';"}]} -{"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 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.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\nCREATE TABLE healthcare.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": "I\u2019d like to see a list of appointments along with any prescriptions made on the same day. Include appointment_id, prescription_id, medication_name, and appointment_time."}, {"role": "assistant", "content": "SELECT a.appointment_id, p.prescription_id, m.medication_name, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.prescriptions p ON a.patient_id = p.patient_id\nJOIN healthcare.medications m ON p.medication_id = m.medication_id\nWHERE DATE(a.appointment_time) = DATE(p.prescription_date);"}, {"role": "user", "content": "Only include prescriptions where the medication description contains 'injection'."}, {"role": "assistant", "content": "SELECT a.appointment_id, p.prescription_id, m.medication_name, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.prescriptions p ON a.patient_id = p.patient_id\nJOIN healthcare.medications m ON p.medication_id = m.medication_id\nWHERE DATE(a.appointment_time) = DATE(p.prescription_date)\n AND m.description ILIKE '%injection%';"}, {"role": "user", "content": "Also order the results by appointment_time descending."}, {"role": "assistant", "content": "SELECT a.appointment_id, p.prescription_id, m.medication_name, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.prescriptions p ON a.patient_id = p.patient_id\nJOIN healthcare.medications m ON p.medication_id = m.medication_id\nWHERE DATE(a.appointment_time) = DATE(p.prescription_date)\n AND m.description ILIKE '%injection%'\nORDER BY a.appointment_time DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\n", "conversations": [{"role": "user", "content": "Show me the top 5 smart money addresses by profit on the Ethereum chain, along with their most profitable token and ROI, but only include addresses with a realized profit ratio above 70%."}, {"role": "assistant", "content": "SELECT address, most_profit_token, roi FROM smart_money_profit WHERE chain = 'Ethereum' AND realized_ratio > 70 ORDER BY profit DESC LIMIT 5;"}, {"role": "user", "content": "Can you also include their rank and filter to only show addresses with ROI greater than 50%?"}, {"role": "assistant", "content": "SELECT address, most_profit_token, roi, rank FROM smart_money_profit WHERE chain = 'Ethereum' AND realized_ratio > 70 AND roi > 50 ORDER BY profit DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, top_3_coins text, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, market_cap double precision, volume_24h double precision, trend_rank bigint, token_num bigint )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n", "conversations": [{"role": "user", "content": "Show the total USD value held by CEX addresses for each token belonging to the 'Gaming' narrative. List the token symbol, narrative, and the total USD value across all CEX holdings for that token."}, {"role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, SUM(ctb.usd_value) AS total_cex_usd_value FROM cex_token_balance ctb JOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol WHERE tbi.narrative = 'Gaming' GROUP BY ctb.token_symbol, tbi.narrative ORDER BY total_cex_usd_value DESC;"}, {"role": "user", "content": "Modify the query to add the smart money ROI and net flow from the `smart_money_token_performance` table, and filter the results to only include tokens where the calculated total CEX USD value is greater than 5,000,000."}, {"role": "assistant", "content": "WITH TokenCexValue AS ( SELECT ctb.token_symbol, tbi.narrative, SUM(ctb.usd_value) AS total_cex_usd_value FROM cex_token_balance ctb JOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol WHERE tbi.narrative = 'Gaming' GROUP BY ctb.token_symbol, tbi.narrative ) SELECT tcv.token_symbol, tcv.narrative, tcv.total_cex_usd_value, smtp.roi, smtp.net_flow FROM TokenCexValue tcv JOIN smart_money_token_performance smtp ON tcv.token_symbol = smtp.token_symbol WHERE tcv.total_cex_usd_value > 5000000 ORDER BY tcv.total_cex_usd_value DESC;"}, {"role": "user", "content": "Filter the results to only include tokens where the smart money ROI is positive and the smart money net flow is greater than 1000."}, {"role": "assistant", "content": "WITH TokenCexValue AS ( SELECT ctb.token_symbol, tbi.narrative, SUM(ctb.usd_value) AS total_cex_usd_value FROM cex_token_balance ctb JOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol WHERE tbi.narrative = 'Gaming' GROUP BY ctb.token_symbol, tbi.narrative ) SELECT tcv.token_symbol, tcv.narrative, tcv.total_cex_usd_value, smtp.roi, smtp.net_flow FROM TokenCexValue tcv JOIN smart_money_token_performance smtp ON tcv.token_symbol = smtp.token_symbol WHERE tcv.total_cex_usd_value > 5000000 AND smtp.roi > 0 AND smtp.net_flow > 1000 ORDER BY tcv.total_cex_usd_value DESC;"}, {"role": "user", "content": "Order the results by smart money ROI in descending order and limit the output to the top 5. Please also include the token's current price from the basic info table."}, {"role": "assistant", "content": "WITH TokenCexValue AS ( SELECT ctb.token_symbol, tbi.narrative, SUM(ctb.usd_value) AS total_cex_usd_value FROM cex_token_balance ctb JOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol WHERE tbi.narrative = 'Gaming' GROUP BY ctb.token_symbol, tbi.narrative ) SELECT tcv.token_symbol, tcv.narrative, tcv.total_cex_usd_value, smtp.roi, smtp.net_flow, tbi.price FROM TokenCexValue tcv JOIN smart_money_token_performance smtp ON tcv.token_symbol = smtp.token_symbol JOIN token_basic_info tbi ON tcv.token_symbol = tbi.token_symbol WHERE tcv.total_cex_usd_value > 5000000 AND smtp.roi > 0 AND smtp.net_flow > 1000 ORDER BY smtp.roi DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\n", "conversations": [{"role": "user", "content": "How many cases are associated with each unique lead lawyer ID? Show the lead lawyer ID and the count of cases, but only for lawyers who lead at least 5 cases. Sort the results by the case count in descending order."}, {"role": "assistant", "content": "SELECT lead_lawyer_id, count(case_id) FROM legal_services.cases GROUP BY lead_lawyer_id HAVING count(case_id) >= 5 ORDER BY count(case_id) DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )\nCREATE TABLE financial_services.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.trades ( trade_id.text, account_id.text, security_id.text, order_id.text, trade_type.text, quantity.numeric, price_per_unit.numeric, total_amount.numeric, commission.numeric, trade_timestamp.timestamp, settlement_date.date, status.text, execution_venue.text )\nCREATE TABLE financial_services.market_data ( data_point_id.bigint, security_id.text, data_timestamp.timestamp, open_price.numeric, high_price.numeric, low_price.numeric, close_price.numeric, adjusted_close_price.numeric, volume.bigint, source.text )\nCREATE TABLE financial_services.employees ( employee_id.text, first_name.text, last_name.text, job_title.text, department.text, branch_id.text, email.text, phone_extension.text, hire_date.date, termination_date.date, manager_id.text, status.text )\nCREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )\n", "conversations": [{"role": "user", "content": "List the number of completed transactions and the total amount per currency."}, {"role": "assistant", "content": "SELECT currency, COUNT(*) AS transaction_count, SUM(amount) AS total_amount\nFROM financial_services.transactions\nWHERE status = 'COMPLETED'\nGROUP BY currency;"}, {"role": "user", "content": "Exclude any currency groups where total_amount is less than 10000 and order by total_amount descending."}, {"role": "assistant", "content": "SELECT currency, COUNT(*) AS transaction_count, SUM(amount) AS total_amount\nFROM financial_services.transactions\nWHERE status = 'COMPLETED'\nGROUP BY currency\nHAVING SUM(amount) >= 10000\nORDER BY total_amount DESC;"}, {"role": "user", "content": "Finally, include only transaction_types 'TRANSFER' or 'PAYMENT' and show the result grouped by currency and transaction_type."}, {"role": "assistant", "content": "SELECT currency, transaction_type, COUNT(*) AS transaction_count, SUM(amount) AS total_amount\nFROM financial_services.transactions\nWHERE status = 'COMPLETED'\n AND transaction_type IN ('TRANSFER', 'PAYMENT')\nGROUP BY currency, transaction_type\nHAVING SUM(amount) >= 10000\nORDER BY total_amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n", "conversations": [{"role": "user", "content": "Count the total number of unique insurance providers in the system."}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT insurance_provider) FROM healthcare.insurance_plans;"}]} -{"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 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 character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )\nCREATE TABLE hospitality_technology.reviews ( review_id text 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": "List all staff members who processed payments for guest ID 'G123', including their first name, last name, and the payment ID."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.payment_id FROM staff AS T1 JOIN payments AS T2 ON T1.staff_id = T2.staff_id_processed WHERE T2.guest_id = 'G123';"}]} -{"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 healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "Show all medications that share a manufacturer with at least one other medication. Return the medication_id, medication_name, and manufacturer for each."}, {"role": "assistant", "content": "SELECT m.medication_id,\n m.medication_name,\n m.manufacturer\nFROM healthcare.medications m\nJOIN (\n SELECT manufacturer\n FROM healthcare.medications\n GROUP BY manufacturer\n HAVING COUNT(*) > 1\n) multi ON m.manufacturer = multi.manufacturer;"}]} -{"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 transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\n", "conversations": [{"role": "user", "content": "Show me the list of all passengers who do not have a loyalty program membership, including their passenger ID and the date their record was created."}, {"role": "assistant", "content": "SELECT passenger_id, created_at FROM transportation.passengers WHERE loyalty_program_id IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.platforms (\n platform_id character varying(64) NOT NULL, -- Unique identifier for the platform\n station_id character varying(64) NOT NULL, -- Foreign key referencing stations\n platform_number character varying(10) NOT NULL, -- Platform identifier (e.g., '1A', '5')\n track_number character varying(10), -- Associated track number, if different\n status character varying(32) NOT NULL DEFAULT 'Operational', -- e.g., Operational, Maintenance, Closed\n length_meters numeric(8,2), -- Length of the platform in meters\n accessible boolean NOT NULL DEFAULT false, -- Is the platform accessible (e.g., wheelchair)?\n PRIMARY KEY (platform_id),\n FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.trains (\n train_id character varying(64) NOT NULL, -- Unique identifier for the train set\n train_number character varying(32) NOT NULL, -- Operational number of the train (e.g., 'Acela 2151')\n model character varying(128), -- Model of the train (e.g., 'Siemens Velaro')\n manufacturer character varying(128), -- Manufacturer of the train\n year_manufactured integer, -- Year the train was built\n capacity integer NOT NULL, -- Total passenger capacity\n status character varying(32) NOT NULL DEFAULT 'Active', -- e.g., Active, Maintenance, Retired\n last_maintenance_date date, -- Date of last scheduled maintenance\n next_maintenance_date date, -- Date of next scheduled maintenance\n PRIMARY KEY (train_id),\n UNIQUE (train_number)\n)\nCREATE TABLE train_station_management.staff (\n staff_id character varying(64) NOT NULL, -- Unique identifier for the staff member\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n role character varying(64) NOT NULL, -- e.g., Station Master, Ticket Agent, Conductor, Engineer, Maintenance Crew\n primary_station_id character varying(64), -- Base station for the staff member (nullable for mobile staff)\n employee_number character varying(32) UNIQUE NOT NULL, -- Unique employee identifier\n hire_date date NOT NULL,\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n is_active boolean NOT NULL DEFAULT true, -- Is the staff member currently employed?\n PRIMARY KEY (staff_id),\n FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id)\n)\n", "conversations": [{"role": "user", "content": "Can you provide the total number of active trains in the database?"}, {"role": "assistant", "content": "SELECT COUNT(*)\nFROM train_station_management.trains\nWHERE status = 'Active';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\n", "conversations": [{"role": "user", "content": "List all cases opened in the 'State Court' jurisdiction in the year 2023, including their name, number, and client ID."}, {"role": "assistant", "content": "SELECT case_name, case_number, client_id FROM legal_services.cases WHERE court_jurisdiction = 'State Court' AND date_opened >= '2023-01-01' AND date_opened < '2024-01-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 all available services along with the property name where they are offered."}, {"role": "assistant", "content": "SELECT s.service_id, s.service_name, p.property_name\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.is_available = true;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.nodes (\n node_id character varying(64) NOT NULL, -- unique identifier for the node\n ip_address character varying(15) NOT NULL, -- IP address of the node\n port integer NOT NULL, -- port number of the node\n last_seen timestamp NOT NULL, -- last time the node was active\n PRIMARY KEY (node_id)\n)\nCREATE TABLE blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )\nCREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE blockchain.smart_contracts ( contract_id character varying(64) NOT NULL, creator_address character varying(128) NOT NULL, code text NOT NULL, timestamp timestamp NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "Retrieve all users and their associated wallet identifiers."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id"}, {"role": "user", "content": "Only show users whose username starts with 'J'."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%'"}, {"role": "user", "content": "Further filter to only include wallets where the address_id contains 'abc'."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%' AND T2.address_id LIKE '%abc%'"}, {"role": "user", "content": "For the filtered users and wallets, count how many wallets each user has."}, {"role": "assistant", "content": "SELECT T1.username , COUNT(T2.wallet_id) FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%' AND T2.address_id LIKE '%abc%' GROUP BY T1.username"}]} -{"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 legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE TABLE legal_services.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 appointments, including their subject and start time, along with the name and status of the case they are linked to."}, {"role": "assistant", "content": "SELECT T1.subject, T1.start_time, T2.case_name, T2.status FROM appointments AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies (\n policy_id character varying(64) NOT NULL, -- unique identifier for the policy\n customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)\n product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)\n agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)\n policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number\n start_date date NOT NULL, -- date the policy coverage begins\n end_date date NOT NULL, -- date the policy coverage ends\n premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term\n coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered\n deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in\n status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending\n issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the policy was issued\n cancellation_date date,\n cancellation_reason text,\n PRIMARY KEY (policy_id)\n)\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.insurance_products (\n product_id character varying(64) NOT NULL, -- unique identifier for the insurance product\n product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')\n product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'\n description text, -- detailed description of the product\n base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments\n coverage_details text, -- details about what is covered (could be JSON or structured text)\n underwriting_rules text, -- rules used for assessing risk and eligibility\n is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at timestamp,\n PRIMARY KEY (product_id)\n)\nCREATE TABLE insurance.agents (\n agent_id character varying(64) NOT NULL, -- unique identifier for the agent\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n agency_name character varying(150),\n license_number character varying(100) NOT NULL UNIQUE, -- state insurance license number\n license_state character varying(50) NOT NULL,\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(30),\n hire_date date,\n termination_date date,\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Terminated, On Leave\n commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, -- percentage commission\n manager_id character varying(64), -- identifier for the agent's manager (FK to agents or employees)\n PRIMARY KEY (agent_id)\n)\nCREATE TABLE insurance.premium_payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment\n policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)\n payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received\n amount_paid numeric(12, 2) NOT NULL, -- amount of the payment\n payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check\n transaction_reference character varying(128) UNIQUE, -- reference from payment processor\n due_date date, -- due date for this payment installment\n payment_period_start date, -- start date of the period this payment covers\n payment_period_end date, -- end date of the period this payment covers\n status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded\n PRIMARY KEY (payment_id)\n)\nCREATE TABLE insurance.claim_documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n claim_id character varying(64) NOT NULL, -- identifier of the claim this document relates to (FK to claims)\n document_type character varying(50) NOT NULL, -- e.g., Police Report, Photo, Invoice, Medical Bill\n file_name character varying(255) NOT NULL, -- original name of the uploaded file\n file_path character varying(512) NOT NULL, -- storage path (e.g., S3 URL, network path)\n file_size_bytes integer, -- size of the file in bytes\n mime_type character varying(100), -- MIME type of the file (e.g., 'image/jpeg', 'application/pdf')\n uploaded_by character varying(64), -- identifier of the user/system who uploaded (FK to users/customers)\n uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- time of upload\n description text, -- optional description of the document\n PRIMARY KEY (document_id)\n)\nCREATE TABLE insurance.policy_beneficiaries (\n beneficiary_id character varying(64) NOT NULL, -- unique identifier for the beneficiary entry\n policy_id character varying(64) NOT NULL, -- identifier of the life/relevant policy (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the beneficiary (could be FK to customers or store info directly)\n first_name character varying(100) NOT NULL, -- beneficiary first name (if not linking to customers table)\n last_name character varying(100) NOT NULL, -- beneficiary last name\n relationship character varying(50) NOT NULL, -- relationship to the policyholder (e.g., Spouse, Child, Parent)\n percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), -- percentage of payout\n contact_info text, -- contact details for the beneficiary\n added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (beneficiary_id),\n UNIQUE (policy_id, customer_id) -- Ensure a person is listed only once per policy\n)\n", "conversations": [{"role": "user", "content": "For each insurance product type, retrieve the total premium_amount and average coverage_limit for policies under active products. Include product_type, total_premium, and avg_coverage_limit, sorted by total_premium descending."}, {"role": "assistant", "content": "SELECT ip.product_type,\n SUM(p.premium_amount) AS total_premium,\n AVG(p.coverage_limit) AS avg_coverage_limit\nFROM insurance.policies p\nJOIN insurance.insurance_products ip\n ON p.product_id = ip.product_id\nWHERE ip.is_active = TRUE\nGROUP BY ip.product_type\nORDER BY total_premium DESC;"}]} -{"system": "You are an 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 government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id.text, citizen_id.text, employee_id.text, location_id.text, service_id.text, scheduled_start_time.timestamp, scheduled_end_time.timestamp, purpose.text, status.text, booking_method.text, created_at.timestamp, notes.text )\n", "conversations": [{"role": "user", "content": "List the names of services that have been scheduled at accessible service locations."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name FROM government_services.services AS T1 JOIN government_services.appointments AS T2 ON T1.service_id = T2.service_id JOIN government_services.service_locations AS T3 ON T2.location_id = T3.location_id WHERE T3.is_accessible = TRUE"}, {"role": "user", "content": "Now, only include services from agencies with 'State' jurisdiction level."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name FROM government_services.services AS T1 JOIN government_services.appointments AS T2 ON T1.service_id = T2.service_id JOIN government_services.service_locations AS T3 ON T2.location_id = T3.location_id JOIN government_services.agencies AS T4 ON T1.agency_id = T4.agency_id WHERE T3.is_accessible = TRUE AND T4.jurisdiction_level = 'State'"}]} -{"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 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 )\n", "conversations": [{"role": "user", "content": "List the reference_number and status for all applications assigned to employee 'emp200', along with the submitted_at date of each application."}, {"role": "assistant", "content": "SELECT reference_number, status, submitted_at FROM government_services.applications WHERE assigned_employee_id = 'emp200';"}, {"role": "user", "content": "Show only those applications that have status 'Pending' and were submitted after January 1, 2024."}, {"role": "assistant", "content": "SELECT reference_number, status, submitted_at FROM government_services.applications WHERE assigned_employee_id = 'emp200' AND status = 'Pending' AND submitted_at > '2024-01-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.applications ( application_id text PRIMARY KEY, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\n", "conversations": [{"role": "user", "content": "For each service ID, what is the average number of days between the submission date and the decision date for applications that have a recorded decision?"}, {"role": "assistant", "content": "SELECT service_id, AVG(EXTRACT(EPOCH FROM (decision_date - submitted_at)) / 86400) AS average_days_to_decision FROM government_services.applications WHERE decision_date IS NOT NULL GROUP BY service_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\n", "conversations": [{"role": "user", "content": "Provide a breakdown of the total number of conversations, showing how many are group chats and how many are not. Also, show the count of conversations that have a recorded last message time."}, {"role": "assistant", "content": "SELECT COUNT(*) AS total_conversations, COUNT(CASE WHEN is_group_chat = true THEN 1 END) AS group_chat_count, COUNT(CASE WHEN is_group_chat = false THEN 1 END) AS private_chat_count, COUNT(last_message_at) AS conversations_with_messages_count FROM social_media.conversations;"}]} -{"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 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 products, showing their ID, name, type, and whether they are active."}, {"role": "assistant", "content": "SELECT product_id, product_name, product_type, is_active FROM insurance.insurance_products;"}, {"role": "user", "content": "Now, only show me products of type 'Auto' or 'Home'."}, {"role": "assistant", "content": "SELECT product_id, product_name, product_type, is_active FROM insurance.insurance_products WHERE product_type IN ('Auto', 'Home');"}, {"role": "user", "content": "Also, only include those products that have a base premium greater than 750."}, {"role": "assistant", "content": "SELECT product_id, product_name, product_type, is_active FROM insurance.insurance_products WHERE product_type IN ('Auto', 'Home') AND base_premium > 750;"}, {"role": "user", "content": "Great, but just show the product name and base premium for those results, ordered by base premium descending."}, {"role": "assistant", "content": "SELECT product_name, base_premium FROM insurance.insurance_products WHERE product_type IN ('Auto', 'Home') AND base_premium > 750 ORDER BY base_premium DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id 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.transactions ( transaction_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, related_account_id character varying(64), transaction_type character varying(50) NOT NULL, amount numeric(19, 4) NOT NULL, currency character varying(3) NOT NULL, transaction_date timestamp NOT NULL, effective_date date NOT NULL, description text, status character varying(32) NOT NULL, reference_number character varying(128), PRIMARY KEY (transaction_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id) )\nCREATE TABLE financial_services.market_data (\n data_point_id bigserial NOT NULL, -- auto-incrementing primary key\n security_id character varying(64) NOT NULL, -- identifier for the security\n data_timestamp timestamp NOT NULL, -- timestamp for the data point (e.g., end of day, intraday)\n open_price numeric(19, 8), -- opening price for the period\n high_price numeric(19, 8), -- highest price during the period\n low_price numeric(19, 8), -- lowest price during the period\n close_price numeric(19, 8) NOT NULL, -- closing price for the period\n adjusted_close_price numeric(19, 8), -- closing price adjusted for dividends and splits\n volume bigint, -- trading volume during the period\n source character varying(50), -- source of the market data (e.g., Bloomberg, Refinitiv)\n PRIMARY KEY (data_point_id),\n UNIQUE (security_id, data_timestamp), -- Ensure unique data point per security per time\n FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id)\n)\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": "Show me the average balance and count of active accounts per account type."}, {"role": "assistant", "content": "SELECT account_type,\n COUNT(*) AS active_count,\n AVG(balance) AS avg_balance\nFROM financial_services.accounts\nWHERE status = 'ACTIVE'\nGROUP BY account_type;"}, {"role": "user", "content": "Exclude account types with an average balance below 10000."}, {"role": "assistant", "content": "SELECT account_type,\n COUNT(*) AS active_count,\n AVG(balance) AS avg_balance\nFROM financial_services.accounts\nWHERE status = 'ACTIVE'\nGROUP BY account_type\nHAVING AVG(balance) >= 10000;"}, {"role": "user", "content": "Order the result by active_count descending."}, {"role": "assistant", "content": "SELECT account_type,\n COUNT(*) AS active_count,\n AVG(balance) AS avg_balance\nFROM financial_services.accounts\nWHERE status = 'ACTIVE'\nGROUP BY account_type\nHAVING AVG(balance) >= 10000\nORDER BY active_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE transportation.bookings (\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": "List the top 5 passengers by total fare spent across all their bookings."}, {"role": "assistant", "content": "SELECT p.passenger_id, p.first_name || ' ' || p.last_name AS full_name, SUM(b.fare) AS total_fare FROM transportation.bookings b JOIN transportation.passengers p ON b.passenger_id = p.passenger_id GROUP BY p.passenger_id, p.first_name, p.last_name ORDER BY total_fare DESC LIMIT 5;"}, {"role": "user", "content": "Now exclude bookings with status 'Pending Payment'."}, {"role": "assistant", "content": "SELECT p.passenger_id, p.first_name || ' ' || p.last_name AS full_name, SUM(b.fare) AS total_fare FROM transportation.bookings b JOIN transportation.passengers p ON b.passenger_id = p.passenger_id WHERE b.status != 'Pending Payment' GROUP BY p.passenger_id, p.first_name, p.last_name ORDER BY total_fare DESC LIMIT 5;"}, {"role": "user", "content": "Also include the passenger's email in the result."}, {"role": "assistant", "content": "SELECT p.passenger_id, p.first_name || ' ' || p.last_name AS full_name, p.email, SUM(b.fare) AS total_fare FROM transportation.bookings b JOIN transportation.passengers p ON b.passenger_id = p.passenger_id WHERE b.status != 'Pending Payment' GROUP BY p.passenger_id, p.first_name, p.last_name, p.email ORDER BY total_fare DESC LIMIT 5;"}, {"role": "user", "content": "Actually, sort the results in ascending order of total_fare."}, {"role": "assistant", "content": "SELECT p.passenger_id, p.first_name || ' ' || p.last_name AS full_name, p.email, SUM(b.fare) AS total_fare FROM transportation.bookings b JOIN transportation.passengers p ON b.passenger_id = p.passenger_id WHERE b.status != 'Pending Payment' GROUP BY p.passenger_id, p.first_name, p.last_name, p.email ORDER BY total_fare ASC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, top_3_coins text, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, market_cap double precision, volume_24h double precision, trend_rank bigint, token_num bigint )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )\nCREATE TABLE 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_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": "Which projects had fundraising rounds named 'Series A' in 2022, and what are their token symbols and current token prices from DEX pools?"}, {"role": "assistant", "content": "SELECT p.project_name, p.rounds_name, d.token_symbol, d.price\nFROM project_fundraising_record p\nJOIN token_dexpool_info d ON LOWER(p.project_name) = LOWER(d.token_name)\nWHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%';"}, {"role": "user", "content": "Can you also include the chain of each token and order the results by token price descending?"}, {"role": "assistant", "content": "SELECT p.project_name, p.rounds_name, d.token_symbol, d.chain, d.price\nFROM project_fundraising_record p\nJOIN token_dexpool_info d ON LOWER(p.project_name) = LOWER(d.token_name)\nWHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%'\nORDER BY d.price DESC;"}, {"role": "user", "content": "I only want to see projects where the fundraising amount exceeded $10,000,000."}, {"role": "assistant", "content": "SELECT p.project_name, p.rounds_name, d.token_symbol, d.chain, d.price\nFROM project_fundraising_record p\nJOIN token_dexpool_info d ON LOWER(p.project_name) = LOWER(d.token_name)\nWHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%'\n AND p.investment_value > 10000000\nORDER BY d.price DESC;"}, {"role": "user", "content": "I got empty results, maybe the join with project_name and token_name is too strict. Can you try joining where either project_name equals token_name or project_name is contained in token_name, in a case-insensitive way?"}, {"role": "assistant", "content": "SELECT p.project_name, p.rounds_name, d.token_symbol, d.chain, d.price\nFROM project_fundraising_record p\nJOIN token_dexpool_info d\n ON LOWER(p.project_name) = LOWER(d.token_name)\n OR LOWER(d.token_name) LIKE CONCAT('%', LOWER(p.project_name), '%')\nWHERE p.rounds_name = 'Series A' AND p.investment_date LIKE '2022%'\n AND p.investment_value > 10000000\nORDER BY d.price DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n", "conversations": [{"role": "user", "content": "How many distinct tokens did smart money buy on the 'BSC' chain in 2023?"}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT token_address) AS distinct_tokens_bought\nFROM smart_money_token_inflow\nWHERE type = 1\n AND chain = 'BSC'\n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') >= '2023-01-01'\n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') <= '2023-12-31';"}, {"role": "user", "content": "Can you break this down by narrative and show the count per narrative?"}, {"role": "assistant", "content": "SELECT narrative, COUNT(DISTINCT token_address) AS distinct_tokens_bought\nFROM smart_money_token_inflow\nWHERE type = 1\n AND chain = 'BSC'\n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') >= '2023-01-01'\n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') <= '2023-12-31'\nGROUP BY narrative\nORDER BY distinct_tokens_bought DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\n", "conversations": [{"role": "user", "content": "Provide the count of transfers for each token_id."}, {"role": "assistant", "content": "SELECT token_id,\n COUNT(*) AS transfer_count\nFROM web3.token_transfers\nGROUP BY token_id;"}, {"role": "user", "content": "Actually, also include the total transferred value for each token_id."}, {"role": "assistant", "content": "SELECT token_id,\n COUNT(*) AS transfer_count,\n SUM(value) AS total_transferred_value\nFROM web3.token_transfers\nGROUP BY token_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.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.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\nCREATE TABLE government_services.employees ( employee_id.text, agency_id.text, first_name.text, last_name.text, job_title.text, department.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, access_level.text, manager_employee_id.text )\nCREATE TABLE government_services.service_locations ( location_id.text, agency_id.text, location_name.text, address.text, city.text, state.text, postal_code.text, latitude.numeric, longitude.numeric, operating_hours.text, contact_phone.text, is_accessible.boolean )\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": "How many applications are currently in 'Processing' status? Return the total count."}, {"role": "assistant", "content": "SELECT COUNT(*) AS processing_applications_count\nFROM government_services.applications\nWHERE status = 'Processing';"}]} -{"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 healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.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": "For each patient, count the total number of medical records they have in the system, and show patient_id along with record_count."}, {"role": "assistant", "content": "SELECT patient_id,\n COUNT(*) AS record_count\nFROM healthcare.medical_records\nGROUP BY patient_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Show me, for each game, the achievement that has been unlocked by the most players. Include the game title, achievement name, and the number of players who unlocked it."}, {"role": "assistant", "content": "WITH RankedAchievements AS ( SELECT pa.achievement_id, COUNT(pa.player_id) AS unlock_count, ROW_NUMBER() OVER(PARTITION BY a.game_id ORDER BY COUNT(pa.player_id) DESC) as rn FROM player_achievements pa JOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id GROUP BY pa.achievement_id, a.game_id ) SELECT g.title AS game_title, a.name AS achievement_name, ra.unlock_count FROM RankedAchievements ra JOIN gaming_technology.achievements a ON ra.achievement_id = a.achievement_id JOIN games g ON a.game_id = g.game_id WHERE ra.rn = 1;"}, {"role": "user", "content": "Can you refine this to only show games where the top achievement has been unlocked by at least 50 players?"}]} -{"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 legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "I want to find all pairs of invoices belonging to the same client. Show me the client_id, the invoice_number for the earlier invoice and the invoice_number for the later invoice."}, {"role": "assistant", "content": "SELECT i1.client_id,\n i1.invoice_number AS earlier_invoice,\n i2.invoice_number AS later_invoice\nFROM legal_services.invoices i1\nJOIN legal_services.invoices i2\n ON i1.client_id = i2.client_id\n AND i1.issue_date < i2.issue_date;"}, {"role": "user", "content": "Actually, only include pairs where the difference between the two issue dates is no more than 7 days."}, {"role": "assistant", "content": "SELECT i1.client_id,\n i1.invoice_number AS earlier_invoice,\n i2.invoice_number AS later_invoice\nFROM legal_services.invoices i1\nJOIN legal_services.invoices i2\n ON i1.client_id = i2.client_id\n AND i1.issue_date < i2.issue_date\n AND i2.issue_date - i1.issue_date <= INTERVAL '7 days';"}, {"role": "user", "content": "Also, only keep pairs where both invoices are unpaid (amount_paid < total_amount)."}, {"role": "assistant", "content": "SELECT i1.client_id,\n i1.invoice_number AS earlier_invoice,\n i2.invoice_number AS later_invoice\nFROM legal_services.invoices i1\nJOIN legal_services.invoices i2\n ON i1.client_id = i2.client_id\n AND i1.issue_date < i2.issue_date\n AND i2.issue_date - i1.issue_date <= INTERVAL '7 days'\nWHERE i1.amount_paid < i1.total_amount\n AND i2.amount_paid < i2.total_amount;"}]} -{"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 healthcare.appointments ( appointment_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, appointment_time timestamp with time zone NOT NULL, duration_minutes integer NOT NULL, reason text, status character varying(32) NOT NULL, location_id character varying(64), notes text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Show the total number of appointments created in 2024 for each doctor and each status."}, {"role": "assistant", "content": "SELECT doctor_id, status, COUNT(*) AS appointment_count FROM healthcare.appointments WHERE EXTRACT(YEAR FROM created_at) = 2024 GROUP BY doctor_id, status;"}, {"role": "user", "content": "Only include combinations where the count is greater than 5."}, {"role": "assistant", "content": "SELECT doctor_id, status, COUNT(*) AS appointment_count FROM healthcare.appointments WHERE EXTRACT(YEAR FROM created_at) = 2024 GROUP BY doctor_id, status HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Sort the results by doctor ID ascending and then by appointment count descending."}, {"role": "assistant", "content": "SELECT doctor_id, status, COUNT(*) AS appointment_count FROM healthcare.appointments WHERE EXTRACT(YEAR FROM created_at) = 2024 GROUP BY doctor_id, status HAVING COUNT(*) > 5 ORDER BY doctor_id ASC, appointment_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "List token symbols on any chain that have both a realized ratio above 0.8 and an ROI greater than 5. Show their symbol, chain, realized ratio, and ROI."}, {"role": "assistant", "content": "SELECT token_symbol, chain, realized_ratio, roi FROM smart_money_token_performance WHERE realized_ratio > 0.8 AND roi > 5"}, {"role": "user", "content": "Can you also include their PNL and Net Flow in the result?"}, {"role": "assistant", "content": "SELECT token_symbol, chain, realized_ratio, roi, pnl, net_flow FROM smart_money_token_performance WHERE realized_ratio > 0.8 AND roi > 5"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List the usernames of users that are being followed by user 'U123'."}, {"role": "assistant", "content": "SELECT T2.username FROM social_media.follows AS T1 JOIN social_media.users AS T2 ON T1.following_user_id = T2.user_id WHERE T1.follower_user_id = 'U123'"}, {"role": "user", "content": "Could you also include their email addresses?"}, {"role": "assistant", "content": "SELECT T2.username, T2.email FROM social_media.follows AS T1 JOIN social_media.users AS T2 ON T1.following_user_id = T2.user_id WHERE T1.follower_user_id = 'U123'"}, {"role": "user", "content": "Only show those users who are verified."}, {"role": "assistant", "content": "SELECT T2.username, T2.email FROM social_media.follows AS T1 JOIN social_media.users AS T2 ON T1.following_user_id = T2.user_id WHERE T1.follower_user_id = 'U123' AND T2.is_verified = true"}, {"role": "user", "content": "Order the results alphabetically by username."}, {"role": "assistant", "content": "SELECT T2.username, T2.email FROM social_media.follows AS T1 JOIN social_media.users AS T2 ON T1.following_user_id = T2.user_id WHERE T1.follower_user_id = 'U123' AND T2.is_verified = true ORDER BY T2.username ASC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\n", "conversations": [{"role": "user", "content": "Which cities are listed as primary_address for citizens who have a verified account? Can you show the city names and the number of verified citizens in each city?"}, {"role": "assistant", "content": "SELECT SPLIT_PART(primary_address, ',', 1) AS city, COUNT(*) AS verified_citizen_count FROM government_services.citizens WHERE is_verified = true GROUP BY city;"}, {"role": "user", "content": "Actually, could you only include cities with more than 10 verified citizens? And order them by the number of verified citizens in descending order."}, {"role": "assistant", "content": "SELECT SPLIT_PART(primary_address, ',', 1) AS city, COUNT(*) AS verified_citizen_count FROM government_services.citizens WHERE is_verified = true GROUP BY city HAVING COUNT(*) > 10 ORDER BY verified_citizen_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.appointments ( appointment_id text PRIMARY KEY, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes int, reason text, status text, location_id text, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each patient, find the next appointment after each one. Return patient_id, appointment_id, next_appointment_id, and the waiting time in minutes between them."}, {"role": "assistant", "content": "SELECT A.patient_id,\n A.appointment_id AS current_id,\n B.appointment_id AS next_id,\n EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 AS wait_minutes\nFROM healthcare.appointments A\nJOIN healthcare.appointments B\n ON A.patient_id = B.patient_id\n AND B.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = A.patient_id\n AND appointment_time > A.appointment_time\n );"}, {"role": "user", "content": "Now include only the pairs where the waiting time is less than 30 minutes."}, {"role": "assistant", "content": "SELECT A.patient_id,\n A.appointment_id AS current_id,\n B.appointment_id AS next_id,\n EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 AS wait_minutes\nFROM healthcare.appointments A\nJOIN healthcare.appointments B\n ON A.patient_id = B.patient_id\n AND B.appointment_time = (\n SELECT MIN(appointment_time)\n FROM healthcare.appointments\n WHERE patient_id = A.patient_id\n AND appointment_time > A.appointment_time\n )\nWHERE EXTRACT(EPOCH FROM (B.appointment_time - A.appointment_time)) / 60 < 30;"}]} -{"system": "You are an 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 hospitality_technology.reviews (\n review_id character varying(64) NOT NULL, -- unique identifier for the review\n property_id character varying(64) NOT NULL, -- FK to properties table\n reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good)\n guest_id character varying(64) NOT NULL, -- FK to guests table\n rating_overall integer, -- overall score (e.g., 1-5 or 1-10)\n rating_cleanliness integer,\n rating_service integer,\n rating_location integer,\n rating_value integer,\n comment text, -- guest's written feedback\n review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com\n review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted\n is_public boolean DEFAULT true, -- whether the review is publicly visible\n staff_response text, -- official response from the property\n response_staff_id character varying(64), -- FK to staff (who responded)\n response_date timestamp with time zone, -- when the response was posted\n PRIMARY KEY (review_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id)\n)\n", "conversations": [{"role": "user", "content": "How many reviews were posted by each guest? Show the guest ID and the count of reviews."}, {"role": "assistant", "content": "SELECT guest_id, COUNT(*) AS review_count\nFROM hospitality_technology.reviews\nGROUP BY guest_id;"}, {"role": "user", "content": "Filter to only include guests who have posted at least 3 reviews."}, {"role": "assistant", "content": "SELECT guest_id, COUNT(*) AS review_count\nFROM hospitality_technology.reviews\nGROUP BY guest_id\nHAVING COUNT(*) >= 3;"}, {"role": "user", "content": "Also, for these guests, list their most recent review date."}, {"role": "assistant", "content": "SELECT guest_id, COUNT(*) AS review_count, MAX(review_date) AS latest_review_date\nFROM hospitality_technology.reviews\nGROUP BY guest_id\nHAVING COUNT(*) >= 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Could you list all unique item types available in the system and the number of items that belong to each type?"}, {"role": "assistant", "content": "SELECT item_type, COUNT(item_id) AS item_count\nFROM gaming_technology.in_game_items\nGROUP BY item_type;"}, {"role": "user", "content": "Please also include the total number of players from the players table for each item type."}, {"role": "assistant", "content": "SELECT i.item_type, COUNT(i.item_id) AS item_count, (\n SELECT COUNT(*) FROM gaming_technology.players\n) AS total_players\nFROM gaming_technology.in_game_items i\nGROUP BY i.item_type;"}, {"role": "user", "content": "Now, show only item types that have more than 2 items."}, {"role": "assistant", "content": "SELECT i.item_type, COUNT(i.item_id) AS item_count, (\n SELECT COUNT(*) FROM gaming_technology.players\n) AS total_players\nFROM gaming_technology.in_game_items i\nGROUP BY i.item_type\nHAVING COUNT(i.item_id) > 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\n", "conversations": [{"role": "user", "content": "List all achievements with points greater than 100, showing achievement_id, name, and points."}, {"role": "assistant", "content": "SELECT achievement_id, name, points\nFROM gaming_technology.achievements\nWHERE points > 100;"}, {"role": "user", "content": "Filter further to only include visible achievements and also return the description."}, {"role": "assistant", "content": "SELECT achievement_id, name, description, points\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = FALSE;"}, {"role": "user", "content": "Now group by game_id to find how many such high-point visible achievements each game has."}, {"role": "assistant", "content": "SELECT game_id,\n COUNT(*) AS high_point_visible_count\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = FALSE\nGROUP BY game_id;"}, {"role": "user", "content": "Only include games with at least 2 of these achievements and order by that count descending."}, {"role": "assistant", "content": "SELECT game_id,\n COUNT(*) AS high_point_visible_count\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = FALSE\nGROUP BY game_id\nHAVING COUNT(*) >= 2\nORDER BY high_point_visible_count DESC;"}]} -{"system": "You are an 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 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.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text 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.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": "For each reservation, show the reservation ID and the total number of payments made for that reservation."}, {"role": "assistant", "content": "SELECT\n r.reservation_id,\n COUNT(p.payment_id) AS payment_count\nFROM hospitality_technology.reservations AS r\nJOIN hospitality_technology.payments AS p\n ON r.reservation_id = p.reservation_id\nGROUP BY\n r.reservation_id;"}, {"role": "user", "content": "Only include reservations that have at least 2 payments and show the total amount paid across all payments for each."}, {"role": "assistant", "content": "SELECT\n r.reservation_id,\n COUNT(p.payment_id) AS payment_count,\n SUM(p.amount) AS total_amount_paid\nFROM hospitality_technology.reservations AS r\nJOIN hospitality_technology.payments AS p\n ON r.reservation_id = p.reservation_id\nGROUP BY\n r.reservation_id\nHAVING\n COUNT(p.payment_id) >= 2;"}, {"role": "user", "content": "Actually, show me the reservation ID, property ID, and check-in date for all reservations that have not received any payments."}, {"role": "assistant", "content": "SELECT\n r.reservation_id,\n r.property_id,\n r.check_in_date\nFROM hospitality_technology.reservations AS r\nLEFT JOIN hospitality_technology.payments AS p\n ON r.reservation_id = p.reservation_id\nWHERE\n p.payment_id IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Find pairs of prescriptions for the same patient with overlapping periods. Show p1.prescription_id, p2.prescription_id, patient_id, and the overlap duration in days where the overlap is greater than 15 days."}, {"role": "assistant", "content": "SELECT p1.prescription_id AS prescription_id_1,\n p2.prescription_id AS prescription_id_2,\n p1.patient_id,\n (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days\nFROM healthcare.prescriptions p1\nJOIN healthcare.prescriptions p2\n ON p1.patient_id = p2.patient_id\n AND p1.prescription_id < p2.prescription_id\nWHERE LEAST(p1.end_date, p2.end_date) >= GREATEST(p1.start_date, p2.start_date)\n AND (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) > 15;"}, {"role": "user", "content": "Actually, only consider pairs where both prescriptions allow refills."}, {"role": "assistant", "content": "SELECT p1.prescription_id AS prescription_id_1,\n p2.prescription_id AS prescription_id_2,\n p1.patient_id,\n (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days\nFROM healthcare.prescriptions p1\nJOIN healthcare.prescriptions p2\n ON p1.patient_id = p2.patient_id\n AND p1.prescription_id < p2.prescription_id\nWHERE LEAST(p1.end_date, p2.end_date) >= GREATEST(p1.start_date, p2.start_date)\n AND (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) > 15\n AND p1.refills_allowed > 0\n AND p2.refills_allowed > 0;"}, {"role": "user", "content": "Also, limit the results to overlaps that start in 2024 and order by overlap_days descending."}, {"role": "assistant", "content": "SELECT p1.prescription_id AS prescription_id_1,\n p2.prescription_id AS prescription_id_2,\n p1.patient_id,\n (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days\nFROM healthcare.prescriptions p1\nJOIN healthcare.prescriptions p2\n ON p1.patient_id = p2.patient_id\n AND p1.prescription_id < p2.prescription_id\nWHERE LEAST(p1.end_date, p2.end_date) >= GREATEST(p1.start_date, p2.start_date)\n AND (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) > 15\n AND p1.refills_allowed > 0\n AND p2.refills_allowed > 0\n AND GREATEST(p1.start_date, p2.start_date) >= '2024-01-01'\nORDER BY overlap_days DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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.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 full name and firm name for all lawyers who are not partners."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM legal_services.lawyers AS T1 JOIN legal_services.law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.is_partner = FALSE"}, {"role": "user", "content": "Now, only show those non-partner lawyers whose specialization is 'Litigation'."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM legal_services.lawyers AS T1 JOIN legal_services.law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.is_partner = FALSE AND T1.specialization = 'Litigation'"}, {"role": "user", "content": "Filter this list to only include those hired after 2021-01-01 and order by hire date."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM legal_services.lawyers AS T1 JOIN legal_services.law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.is_partner = FALSE AND T1.specialization = 'Litigation' AND T1.hire_date > '2021-01-01' ORDER BY T1.hire_date"}]} -{"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 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": "Find customers who have accounts in more than one currency. List their customer_id and the count of distinct currencies they hold accounts in."}, {"role": "assistant", "content": "SELECT customer_id, COUNT(DISTINCT currency) AS distinct_currency_count FROM financial_services.accounts GROUP BY customer_id HAVING COUNT(DISTINCT currency) > 1"}, {"role": "user", "content": "For these customers, also list the average balance across all their accounts."}, {"role": "assistant", "content": "SELECT customer_id, COUNT(DISTINCT currency) AS distinct_currency_count, AVG(balance) AS average_balance FROM financial_services.accounts GROUP BY customer_id HAVING COUNT(DISTINCT currency) > 1"}, {"role": "user", "content": "Sort the results by the number of distinct currencies in descending order."}, {"role": "assistant", "content": "SELECT customer_id, COUNT(DISTINCT currency) AS distinct_currency_count, AVG(balance) AS average_balance FROM financial_services.accounts GROUP BY customer_id HAVING COUNT(DISTINCT currency) > 1 ORDER BY distinct_currency_count DESC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\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": "How many claims were reported in the last 90 days?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM claims WHERE reported_date >= CURRENT_DATE - INTERVAL '90 days'"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\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 ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the total number of hours worked by each lawyer for each case."}, {"role": "assistant", "content": "SELECT t.lawyer_id, t.case_id, SUM(t.hours_spent) AS total_hours\nFROM legal_services.time_entries t\nGROUP BY t.lawyer_id, t.case_id;"}, {"role": "user", "content": "Can you include the case name in the results as well?"}, {"role": "assistant", "content": "SELECT t.lawyer_id, t.case_id, cs.case_name, SUM(t.hours_spent) AS total_hours\nFROM legal_services.time_entries t\nJOIN legal_services.cases cs ON t.case_id = cs.case_id\nGROUP BY t.lawyer_id, t.case_id, cs.case_name;"}, {"role": "user", "content": "Now only show cases where the total hours is greater than 20, and sort by total hours descending."}, {"role": "assistant", "content": "SELECT t.lawyer_id, t.case_id, cs.case_name, SUM(t.hours_spent) AS total_hours\nFROM legal_services.time_entries t\nJOIN legal_services.cases cs ON t.case_id = cs.case_id\nGROUP BY t.lawyer_id, t.case_id, cs.case_name\nHAVING SUM(t.hours_spent) > 20\nORDER BY total_hours DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCollection 'assembly_steps'. Document structure: { _id: , step_id: String, line_id: String (reference), step_number: NumberInt, step_name: String, description: String, standard_duration_hours: Decimal128, required_skill_level: String, workstation: String }. Required: step_id, line_id, step_number, step_name. Index on line_id, step_number.\nCollection 'employees'. Document structure: { _id: , employee_id: String, first_name: String, last_name: String, job_title: String, skill_certifications: [String], hire_date: ISODate, assigned_line_id: String (reference, optional), employment_status: String, supervisor_employee_id: String (reference, optional) }. Required: employee_id, first_name, last_name, job_title, hire_date, employment_status.\n", "conversations": [{"role": "user", "content": "\u7279\u5b9a\u306e\u8077\u7a2e\u306e\u5f93\u696d\u54e1\u60c5\u5831\u3092\u53d6\u5f97\u3057\u305f\u3044\u3067\u3059\u3002\u5f93\u696d\u54e1ID\u3001\u540d\u524d\u3001\u8077\u7a2e\u3001\u96c7\u7528\u65e5\u3092\u8868\u793a\u3057\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "db.employees.find(\n { job_title: '' },\n { employee_id: 1, first_name: 1, last_name: 1, job_title: 1, hire_date: 1, _id: 0 }\n).sort({ hire_date: -1 })"}, {"role": "user", "content": "\u96c7\u7528\u65e5\u304c2020\u5e741\u67081\u65e5\u4ee5\u964d\u306e\u5f93\u696d\u54e1\u3060\u3051\u306b\u7d5e\u308a\u8fbc\u3080\u3053\u3068\u306f\u3067\u304d\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "db.employees.find(\n { \n job_title: '',\n hire_date: { $gte: ISODate('2020-01-01') }\n },\n { employee_id: 1, first_name: 1, last_name: 1, job_title: 1, hire_date: 1, _id: 0 }\n).sort({ hire_date: -1 })"}, {"role": "user", "content": "\u96c7\u7528\u30b9\u30c6\u30fc\u30bf\u30b9\u304c\u300cActive\u300d\u306e\u5f93\u696d\u54e1\u3060\u3051\u3092\u3055\u3089\u306b\u6761\u4ef6\u306b\u52a0\u3048\u3089\u308c\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "db.employees.find(\n { \n job_title: '',\n hire_date: { $gte: ISODate('2020-01-01') },\n employment_status: 'Active'\n },\n { employee_id: 1, first_name: 1, last_name: 1, job_title: 1, hire_date: 1, _id: 0 }\n).sort({ hire_date: -1 })"}, {"role": "user", "content": "\u30b9\u30ad\u30eb\u8a8d\u5b9a\u60c5\u5831\u3082\u7d50\u679c\u306b\u542b\u3081\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "db.employees.find(\n { \n job_title: '',\n hire_date: { $gte: ISODate('2020-01-01') },\n employment_status: 'Active'\n },\n { employee_id: 1, first_name: 1, last_name: 1, job_title: 1, hire_date: 1, skill_certifications: 1, _id: 0 }\n).sort({ hire_date: -1 })"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\n", "conversations": [{"role": "user", "content": "I need a list of pairs of vehicles that share the same type but have different fuel_types, showing both vehicle IDs and their fuel types."}, {"role": "assistant", "content": "SELECT v1.vehicle_id,\n v1.fuel_type,\n v2.vehicle_id AS other_vehicle_id,\n v2.fuel_type AS other_fuel_type\nFROM transportation.vehicles v1\nJOIN transportation.vehicles v2\n ON v1.type = v2.type\n AND v1.fuel_type <> v2.fuel_type\n AND v1.vehicle_id < v2.vehicle_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n", "conversations": [{"role": "user", "content": "For each chain in the smart money token inflow data, calculate the total number of addresses involved in buy transactions and the total number of addresses involved in sell transactions. Display the chain, total buy addresses, and total sell addresses."}, {"role": "assistant", "content": "SELECT chain, SUM(CASE WHEN type = 1 THEN address_amount ELSE 0 END) AS total_buy_addresses, SUM(CASE WHEN type = 2 THEN address_amount ELSE 0 END) AS total_sell_addresses FROM smart_money_token_inflow WHERE type IN (1, 2) GROUP BY chain;"}]} -{"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 legal_services.clients (\n client_id character varying(64) NOT NULL, -- unique identifier for the client\n first_name character varying(100) NOT NULL, -- client's first name\n last_name character varying(100) NOT NULL, -- client's last name\n company_name character varying(200), -- company name if applicable\n email character varying(128) UNIQUE NOT NULL, -- client's primary email\n phone character varying(32), -- client's contact phone number\n address text, -- client's full address\n date_registered timestamp NOT NULL, -- when the client was first registered\n status character varying(32) NOT NULL, -- client status (e.g., active, inactive, prospect)\n PRIMARY KEY (client_id)\n)\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\n", "conversations": [{"role": "user", "content": "List each law firm name and the count of clients whose company_name matches that firm."}, {"role": "assistant", "content": "SELECT f.firm_id, f.firm_name, COUNT(c.client_id) AS client_count\nFROM legal_services.law_firms AS f\nLEFT JOIN legal_services.clients AS c\n ON c.company_name = f.firm_name\nGROUP BY f.firm_id, f.firm_name;"}, {"role": "user", "content": "Now only include firms with at least 2 such clients and sort by client_count descending."}, {"role": "assistant", "content": "SELECT f.firm_id, f.firm_name, COUNT(c.client_id) AS client_count\nFROM legal_services.law_firms AS f\nLEFT JOIN legal_services.clients AS c\n ON c.company_name = f.firm_name\nGROUP BY f.firm_id, f.firm_name\nHAVING COUNT(c.client_id) >= 2\nORDER BY client_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\n", "conversations": [{"role": "user", "content": "How many employees were hired in each year?"}, {"role": "assistant", "content": "SELECT EXTRACT(YEAR FROM hire_date) AS hire_year , COUNT(*) AS employee_count FROM employees GROUP BY hire_year"}, {"role": "user", "content": "Show only the years where more than 50 employees were hired."}, {"role": "assistant", "content": "SELECT EXTRACT(YEAR FROM hire_date) AS hire_year , COUNT(*) AS employee_count FROM employees GROUP BY hire_year HAVING COUNT(*) > 50"}, {"role": "user", "content": "For these years, also show the number of employees with 'Admin' access level."}, {"role": "assistant", "content": "SELECT EXTRACT(YEAR FROM hire_date) AS hire_year , COUNT(*) AS employee_count , COUNT(CASE WHEN access_level = 'Admin' THEN 1 ELSE NULL END) AS admin_count FROM employees GROUP BY hire_year HAVING COUNT(*) > 50"}, {"role": "user", "content": "Order the results by the total number of employees hired in the year, descending."}, {"role": "assistant", "content": "SELECT EXTRACT(YEAR FROM hire_date) AS hire_year , COUNT(*) AS employee_count , COUNT(CASE WHEN access_level = 'Admin' THEN 1 ELSE NULL END) AS admin_count FROM employees GROUP BY hire_year HAVING COUNT(*) > 50 ORDER BY employee_count DESC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "List user IDs and the creation timestamp of likes made by users who have email notifications enabled."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true;"}, {"role": "user", "content": "Only show likes created in the year 2024."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01';"}, {"role": "user", "content": "Filter to only include users whose profile is not private."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01' AND T2.private_profile = false;"}]} -{"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 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.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n", "conversations": [{"role": "user", "content": "List all services along with the count of service orders for each service and the corresponding property name."}, {"role": "assistant", "content": "SELECT s.service_id, s.service_name, p.property_name, COUNT(so.order_id) AS order_count\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nLEFT JOIN hospitality_technology.service_orders so ON so.service_id = s.service_id\nGROUP BY s.service_id, s.service_name, p.property_name;"}, {"role": "user", "content": "Can you filter to only show services with at least 2 orders and order the result by order_count descending?"}, {"role": "assistant", "content": "SELECT s.service_id, s.service_name, p.property_name, COUNT(so.order_id) AS order_count\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nLEFT JOIN hospitality_technology.service_orders so ON so.service_id = s.service_id\nGROUP BY s.service_id, s.service_name, p.property_name\nHAVING COUNT(so.order_id) >= 2\nORDER BY order_count DESC;"}, {"role": "user", "content": "I also want the average total_price for each service included in the results."}, {"role": "assistant", "content": "SELECT s.service_id, s.service_name, p.property_name, COUNT(so.order_id) AS order_count, AVG(so.total_price) AS avg_total_price\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nLEFT JOIN hospitality_technology.service_orders so ON so.service_id = s.service_id\nGROUP BY s.service_id, s.service_name, p.property_name\nHAVING COUNT(so.order_id) >= 2\nORDER BY order_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.maintenance_logs ( log_id text, vehicle_id text, service_date date, odometer_reading integer, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\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 the total number of maintenance logs for each vehicle along with the vehicle's make and model."}, {"role": "assistant", "content": "SELECT v.vehicle_id, v.make, v.model, COUNT(m.log_id) AS maintenance_count\nFROM transportation.vehicles v\nLEFT JOIN transportation.maintenance_logs m ON v.vehicle_id = m.vehicle_id\nGROUP BY v.vehicle_id, v.make, v.model;"}]} -{"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 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.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.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": "List all staff members who are not managers, including their first name, last name, position, and the name of the property they work at."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.position, T2.property_name FROM hospitality_technology.staff AS T1 INNER JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id WHERE T1.staff_id NOT IN (SELECT DISTINCT manager_id FROM hospitality_technology.staff WHERE manager_id IS NOT NULL);"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n// Node Label: :Station\n// Properties:\n// station_id: String (Constraint: UNIQUE)\n// station_name: String\n// city: String (Index recommended)\n// state_province: String\n// country_code: String\n// address: String\n// timezone: String\n// number_of_platforms: Integer\n// created_at: DateTime\n// last_updated_at: DateTime\n// Example Cypher CREATE:\n// CREATE (:Station {station_id: 'station_xyz', station_name: 'Grand Central Terminal', city: 'New York', ...})\n// Node Label: :Platform\n// Properties:\n// platform_id: String (Constraint: UNIQUE)\n// platform_number: String\n// track_number: String\n// status: String\n// length_meters: Float\n// accessible: Boolean\n// Relationship: (:Platform)-[:LOCATED_AT]->(:Station)\n// Example Cypher CREATE:\n// MATCH (s:Station {station_id: 'station_xyz'})\n// CREATE (p:Platform {platform_id: 'plat_123', ...})-[:LOCATED_AT]->(s)\n// Node Label: :Train\n// Properties:\n// train_id: String (Constraint: UNIQUE)\n// train_number: String (Constraint: UNIQUE)\n// model: String\n// manufacturer: String\n// year_manufactured: Integer\n// capacity: Integer\n// status: String\n// last_maintenance_date: Date\n// next_maintenance_date: Date\n// Example Cypher CREATE:\n// CREATE (:Train {train_id: 'train_789', train_number: 'Acela 2151', ...})\n// Node Label: :TrainCar\n// Properties:\n// car_id: String (Constraint: UNIQUE)\n// car_number: String\n// car_type: String\n// class: String\n// capacity: Integer\n// features: String (Or List if driver supports)\n// Relationship: (:TrainCar)-[:PART_OF_TRAIN]->(:Train)\n// Example Cypher CREATE:\n// MATCH (t:Train {train_id: 'train_789'})\n// CREATE (c:TrainCar {car_id: 'car_abc', ...})-[:PART_OF_TRAIN]->(t)\n// 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": "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\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": "For each maintenance log, find the upcoming scheduled service by joining on next_service_due_date matching another log's service_date. Show l1.log_id, l1.vehicle_id, l1.service_date, l2.log_id AS upcoming_log_id, and l2.service_date AS upcoming_service_date."}, {"role": "assistant", "content": "SELECT\n l1.log_id,\n l1.vehicle_id,\n l1.service_date,\n l2.log_id AS upcoming_log_id,\n l2.service_date AS upcoming_service_date\nFROM transportation.maintenance_logs l1\nLEFT JOIN transportation.maintenance_logs l2\n ON l1.vehicle_id = l2.vehicle_id\n AND l1.next_service_due_date = l2.service_date;"}, {"role": "user", "content": "Actually, also include the upcoming mechanic name."}, {"role": "assistant", "content": "SELECT\n l1.log_id,\n l1.vehicle_id,\n l1.service_date,\n l2.log_id AS upcoming_log_id,\n l2.service_date AS upcoming_service_date,\n l2.mechanic_name AS upcoming_mechanic\nFROM transportation.maintenance_logs l1\nLEFT JOIN transportation.maintenance_logs l2\n ON l1.vehicle_id = l2.vehicle_id\n AND l1.next_service_due_date = l2.service_date;"}, {"role": "user", "content": "Finally, filter out entries where there is no upcoming log (upcoming_log_id is null)."}, {"role": "assistant", "content": "SELECT\n l1.log_id,\n l1.vehicle_id,\n l1.service_date,\n l2.log_id AS upcoming_log_id,\n l2.service_date AS upcoming_service_date,\n l2.mechanic_name AS upcoming_mechanic\nFROM transportation.maintenance_logs l1\nJOIN transportation.maintenance_logs l2\n ON l1.vehicle_id = l2.vehicle_id\n AND l1.next_service_due_date = l2.service_date;"}]} -{"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 financial_services.securities (\n security_id character varying(64) NOT NULL, -- unique identifier for the security\n ticker_symbol character varying(20) NOT NULL UNIQUE, -- stock ticker or fund symbol\n isin_code character varying(12) UNIQUE, -- International Securities Identification Number\n cusip_code character varying(9) UNIQUE, -- CUSIP number\n security_name text NOT NULL, -- full name of the security\n security_type character varying(50) NOT NULL, -- e.g., Stock, Bond, ETF, Mutual Fund, Option, Future\n exchange character varying(50), -- primary exchange where traded (e.g., NYSE, NASDAQ)\n currency character varying(3) NOT NULL, -- currency the security is denominated in\n issuer_name character varying(255), -- name of the issuing entity\n sector character varying(100), -- industry sector\n last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (security_id)\n)\n", "conversations": [{"role": "user", "content": "For each sector, retrieve the ticker symbol and last_updated timestamp of the earliest and latest updated securities, labeling them as earliest_ticker, earliest_updated, latest_ticker, and latest_updated."}, {"role": "assistant", "content": "WITH sector_stats AS (\n SELECT\n sector,\n MIN(last_updated) AS earliest_updated,\n MAX(last_updated) AS latest_updated\n FROM financial_services.securities\n GROUP BY sector\n)\nSELECT\n ss.sector,\n s_min.ticker_symbol AS earliest_ticker,\n ss.earliest_updated,\n s_max.ticker_symbol AS latest_ticker,\n ss.latest_updated\nFROM sector_stats ss\nLEFT JOIN financial_services.securities s_min\n ON s_min.sector = ss.sector\n AND s_min.last_updated = ss.earliest_updated\nLEFT JOIN financial_services.securities s_max\n ON s_max.sector = ss.sector\n AND s_max.last_updated = ss.latest_updated;"}, {"role": "user", "content": "Actually, only include sectors where the time span between latest_updated and earliest_updated exceeds 30 days."}, {"role": "assistant", "content": "WITH sector_stats AS (\n SELECT\n sector,\n MIN(last_updated) AS earliest_updated,\n MAX(last_updated) AS latest_updated\n FROM financial_services.securities\n GROUP BY sector\n HAVING MAX(last_updated) - MIN(last_updated) > INTERVAL '30 days'\n)\nSELECT\n ss.sector,\n s_min.ticker_symbol AS earliest_ticker,\n ss.earliest_updated,\n s_max.ticker_symbol AS latest_ticker,\n ss.latest_updated\nFROM sector_stats ss\nLEFT JOIN financial_services.securities s_min\n ON s_min.sector = ss.sector\n AND s_min.last_updated = ss.earliest_updated\nLEFT JOIN financial_services.securities s_max\n ON s_max.sector = ss.sector\n AND s_max.last_updated = ss.latest_updated;"}, {"role": "user", "content": "Now order the results by the time span descending."}, {"role": "assistant", "content": "WITH sector_stats AS (\n SELECT\n sector,\n MIN(last_updated) AS earliest_updated,\n MAX(last_updated) AS latest_updated\n FROM financial_services.securities\n GROUP BY sector\n HAVING MAX(last_updated) - MIN(last_updated) > INTERVAL '30 days'\n)\nSELECT\n ss.sector,\n s_min.ticker_symbol AS earliest_ticker,\n ss.earliest_updated,\n s_max.ticker_symbol AS latest_ticker,\n ss.latest_updated,\n ss.latest_updated - ss.earliest_updated AS time_span\nFROM sector_stats ss\nLEFT JOIN financial_services.securities s_min\n ON s_min.sector = ss.sector\n AND s_min.last_updated = ss.earliest_updated\nLEFT JOIN financial_services.securities s_max\n ON s_max.sector = ss.sector\n AND s_max.last_updated = ss.latest_updated\nORDER BY time_span DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text PRIMARY KEY, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial PRIMARY KEY, security_id text, data_timestamp timestamp, open_price numeric, high_price numeric, low_price numeric, close_price numeric, adjusted_close_price numeric, volume bigint, source text )\nCREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "What is the total commission earned from all trades executed in the 'NYSE' venue by employees in the 'Investment' department?"}, {"role": "assistant", "content": "SELECT SUM(t.commission) AS total_commission FROM financial_services.trades t JOIN financial_services.employees e ON t.account_id = e.employee_id WHERE t.execution_venue = 'NYSE' AND e.department = 'Investment';"}]} -{"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 government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\n", "conversations": [{"role": "user", "content": "What is the average and maximum standard fee for services in each category?"}, {"role": "assistant", "content": "SELECT category, AVG(standard_fee) AS avg_standard_fee, MAX(standard_fee) AS max_standard_fee FROM government_services.services GROUP BY category;"}]} -{"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 healthcare.patients ( patient_id.text, first_name.text, last_name.text, date_of_birth.date, gender.text, address.text, phone_number.text, email.text, emergency_contact_name.text, emergency_contact_phone.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve the patient_id, first_name, last_name, and email for all patients who do not have an emergency contact phone number."}, {"role": "assistant", "content": "SELECT patient_id, first_name, last_name, email\nFROM healthcare.patients\nWHERE emergency_contact_phone IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "Provide a list of properties and the total number of reservations made at each property."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(r.reservation_id) AS total_reservations FROM hospitality_technology.properties p JOIN hospitality_technology.reservations r ON p.property_id = r.property_id GROUP BY p.property_name;"}, {"role": "user", "content": "Now, filter this list to only include properties with a star rating of 4 or higher."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(r.reservation_id) AS total_reservations FROM hospitality_technology.properties p JOIN hospitality_technology.reservations r ON p.property_id = r.property_id WHERE p.star_rating >= 4 GROUP BY p.property_name;"}, {"role": "user", "content": "Only show those properties that have more than 100 reservations and order them by the number of reservations in descending order."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(r.reservation_id) AS total_reservations FROM hospitality_technology.properties p JOIN hospitality_technology.reservations r ON p.property_id = r.property_id WHERE p.star_rating >= 4 GROUP BY p.property_name HAVING COUNT(r.reservation_id) > 100 ORDER BY total_reservations DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\n", "conversations": [{"role": "user", "content": "Show the number of law firms founded each year, with the founding year and the count of firms, ordered by year in descending order."}, {"role": "assistant", "content": "SELECT EXTRACT(YEAR FROM founded_date) AS founding_year, COUNT(*) AS firm_count FROM legal_services.law_firms GROUP BY founding_year ORDER BY founding_year DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n", "conversations": [{"role": "user", "content": "What is the average USD value per address for each narrative across all chains?"}, {"role": "assistant", "content": "SELECT\n narrative,\n AVG(usd_value / NULLIF(address_amount, 0)) AS avg_usd_per_address\nFROM smart_money_token_inflow\nGROUP BY narrative;"}]} -{"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 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) )\n", "conversations": [{"role": "user", "content": "List all asset types in the platform along with the count of assets for each type."}, {"role": "assistant", "content": "SELECT type, COUNT(*) as asset_count FROM trading_platform.assets GROUP BY type;"}, {"role": "user", "content": "Now show only asset types that have more than 10 assets."}, {"role": "assistant", "content": "SELECT type, COUNT(*) as asset_count FROM trading_platform.assets GROUP BY type HAVING COUNT(*) > 10;"}, {"role": "user", "content": "Can you modify the query to order the results by asset_count descending?"}, {"role": "assistant", "content": "SELECT type, COUNT(*) as asset_count FROM trading_platform.assets GROUP BY type HAVING COUNT(*) > 10 ORDER BY asset_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Get the count of unread messages for each participant in each group chat, showing conversation_id, group_name, user_id, and unread_count."}, {"role": "assistant", "content": "SELECT cp.conversation_id, conv.group_name, cp.user_id, COUNT(m.message_id) AS unread_count\nFROM social_media.conversation_participants cp\nJOIN social_media.conversations conv ON cp.conversation_id = conv.conversation_id\nLEFT JOIN social_media.messages m ON m.conversation_id = cp.conversation_id\n AND m.read_at IS NULL\n AND (cp.last_read_at IS NULL OR m.sent_at > cp.last_read_at)\nWHERE conv.is_group_chat = TRUE\nGROUP BY cp.conversation_id, conv.group_name, cp.user_id;"}, {"role": "user", "content": "Filter to only include counts greater than 5 and order by unread_count descending."}, {"role": "assistant", "content": "SELECT cp.conversation_id, conv.group_name, cp.user_id, COUNT(m.message_id) AS unread_count\nFROM social_media.conversation_participants cp\nJOIN social_media.conversations conv ON cp.conversation_id = conv.conversation_id\nLEFT JOIN social_media.messages m ON m.conversation_id = cp.conversation_id\n AND m.read_at IS NULL\n AND (cp.last_read_at IS NULL OR m.sent_at > cp.last_read_at)\nWHERE conv.is_group_chat = TRUE\nGROUP BY cp.conversation_id, conv.group_name, cp.user_id\nHAVING COUNT(m.message_id) > 5\nORDER BY unread_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory (\n inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry\n player_id uuid NOT NULL, -- FK linking to the player owning the item\n item_id uuid NOT NULL, -- FK linking to the item definition\n quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)\n acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired\n instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)\n PRIMARY KEY (inventory_id),\n -- Optional unique constraint if items are non-stackable or unique instances\n -- UNIQUE (player_id, item_id) -- Use if quantity is always 1\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)\n)\n", "conversations": [{"role": "user", "content": "For each game, show the game title, the total duration of all sessions in seconds, and the average score."}, {"role": "assistant", "content": "SELECT g.title, SUM(gs.duration_seconds) AS total_duration_seconds, AVG(gs.score) AS average_score FROM gaming_technology.games g JOIN gaming_technology.game_sessions gs ON g.game_id = gs.game_id GROUP BY g.game_id, g.title;"}, {"role": "user", "content": "Could you also show the total number of sessions for each game?"}, {"role": "assistant", "content": "SELECT g.title, COUNT(gs.session_id) AS total_sessions, SUM(gs.duration_seconds) AS total_duration_seconds, AVG(gs.score) AS average_score FROM gaming_technology.games g JOIN gaming_technology.game_sessions gs ON g.game_id = gs.game_id GROUP BY g.game_id, g.title;"}, {"role": "user", "content": "Filter the results to only include games with more than 100 sessions."}, {"role": "assistant", "content": "SELECT g.title, COUNT(gs.session_id) AS total_sessions, SUM(gs.duration_seconds) AS total_duration_seconds, AVG(gs.score) AS average_score FROM gaming_technology.games g JOIN gaming_technology.game_sessions gs ON g.game_id = gs.game_id GROUP BY g.game_id, g.title HAVING COUNT(gs.session_id) > 100;"}]} -{"system": "You are an 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 gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\n", "conversations": [{"role": "user", "content": "I need a list of genres and pairs of game titles in the same genre."}, {"role": "assistant", "content": "SELECT g1.genre, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.genre = g2.genre;"}, {"role": "user", "content": "Please avoid duplicate pairs by ensuring each pair appears only once."}, {"role": "assistant", "content": "SELECT g1.genre, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.genre = g2.genre\nWHERE g1.title < g2.title;"}, {"role": "user", "content": "Only include genres that have at least three games."}, {"role": "assistant", "content": "SELECT g1.genre, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.genre = g2.genre\nWHERE g1.title < g2.title\n AND g1.genre IN (\n SELECT genre\n FROM gaming_technology.games\n GROUP BY genre\n HAVING COUNT(*) >= 3\n );"}, {"role": "user", "content": "Also sort the output by genre ascending and game1 ascending."}, {"role": "assistant", "content": "SELECT g1.genre, g1.title AS game1, g2.title AS game2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.genre = g2.genre\nWHERE g1.title < g2.title\n AND g1.genre IN (\n SELECT genre\n FROM gaming_technology.games\n GROUP BY genre\n HAVING COUNT(*) >= 3\n )\nORDER BY g1.genre ASC, g1.title ASC;"}]} -{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.trains ( train_id text, train_number text, model text, manufacturer text, year_manufactured integer, capacity integer, status text, last_maintenance_date date, next_maintenance_date date )\n", "conversations": [{"role": "user", "content": "What is the detailed repair history for train number T5678?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide the detailed repair history for train number T5678 as this information is not available in the current database table. The table only includes basic information such as train ID, model, manufacturer, capacity, status, and maintenance dates. For repair history, you may need to consult a different database or department."}]} -{"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 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 nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number / 7200))\n)\nCREATE TABLE sui_nfts ( object_id varchar NOT NULL, status varchar NOT NULL, collection_type varchar NOT NULL, package_id varchar NOT NULL, previous_transaction varchar NOT NULL, display varchar NOT NULL, owner varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar NOT NULL, -- mint | transfer | burn\n tick varchar NOT NULL, -- Token tick\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Mint amount\n from_address varchar(42) NOT NULL, -- Address sending the inscription (matches from_address in transactions table)\n to_address varchar(42) NOT NULL -- Address receiving the inscription (match to_address in transactions table)\n)\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_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 NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\n", "conversations": [{"role": "user", "content": "List all wallet addresses holding NFTs for contract_address '0xABC123...' along with the token name from metadata."}, {"role": "assistant", "content": "SELECT h.wallet_address, h.token_id, m.name AS token_name\nFROM nft_holders h\nJOIN nft_metadata m ON h.contract_address = m.contract_address AND h.token_id = m.token_id\nWHERE h.contract_address = '0xABC123...';"}, {"role": "user", "content": "Actually, I only want holders who hold more than 1 token of each token_id and include the rarity_score."}, {"role": "assistant", "content": "SELECT h.wallet_address, h.token_id, m.name AS token_name, m.rarity_score\nFROM nft_holders h\nJOIN nft_metadata m ON h.contract_address = m.contract_address AND h.token_id = m.token_id\nWHERE h.contract_address = '0xABC123...'\n AND CAST(h.amount AS BIGINT) > 1;"}, {"role": "user", "content": "Also filter tokens minted in the last 30 days."}, {"role": "assistant", "content": "SELECT h.wallet_address, h.token_id, m.name AS token_name, m.rarity_score\nFROM nft_holders h\nJOIN nft_metadata m ON h.contract_address = m.contract_address AND h.token_id = m.token_id\nWHERE h.contract_address = '0xABC123...'\n AND CAST(h.amount AS BIGINT) > 1\n AND m.mint_time >= (EXTRACT(EPOCH FROM now()) * 1000 - 30 * 24 * 60 * 60 * 1000);"}, {"role": "user", "content": "Please sort by rarity_score descending and limit to top 10."}, {"role": "assistant", "content": "SELECT h.wallet_address, h.token_id, m.name AS token_name, m.rarity_score\nFROM nft_holders h\nJOIN nft_metadata m ON h.contract_address = m.contract_address AND h.token_id = m.token_id\nWHERE h.contract_address = '0xABC123...'\n AND CAST(h.amount AS BIGINT) > 1\n AND m.mint_time >= (EXTRACT(EPOCH FROM now()) * 1000 - 30 * 24 * 60 * 60 * 1000)\nORDER BY m.rarity_score DESC\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\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all conversation participants along with post_hashtag details where the participant's user_id matches the hashtag_id."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id;"}, {"role": "user", "content": "Only include participants who joined after '2024-01-01'."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id\nWHERE cp.joined_at > '2024-01-01';"}, {"role": "user", "content": "Also, order the results by joined_at descending."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id\nWHERE cp.joined_at > '2024-01-01'\nORDER BY cp.joined_at DESC;"}, {"role": "user", "content": "Finally, limit the output to the first 10 rows."}, {"role": "assistant", "content": "SELECT cp.conversation_id, cp.user_id, ph.post_id, ph.hashtag_id\nFROM social_media.conversation_participants cp\nINNER JOIN social_media.post_hashtags ph\n ON cp.user_id = ph.hashtag_id\nWHERE cp.joined_at > '2024-01-01'\nORDER BY cp.joined_at DESC\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\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List the usernames of users who liked the post with ID 'P123'."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id WHERE T2.post_id = 'P123';"}, {"role": "user", "content": "Also, only include those users who have enabled email notifications."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id JOIN social_media.user_settings AS T3 ON T1.user_id = T3.user_id WHERE T2.post_id = 'P123' AND T3.email_notifications_enabled = TRUE;"}, {"role": "user", "content": "Further filter the list to only show users with a public profile."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id JOIN social_media.user_settings AS T3 ON T1.user_id = T3.user_id WHERE T2.post_id = 'P123' AND T3.email_notifications_enabled = TRUE AND T3.private_profile = FALSE;"}, {"role": "user", "content": "Please order the results by username alphabetically."}, {"role": "assistant", "content": "SELECT DISTINCT T1.username FROM social_media.users AS T1 JOIN social_media.likes AS T2 ON T1.user_id = T2.user_id JOIN social_media.user_settings AS T3 ON T1.user_id = T3.user_id WHERE T2.post_id = 'P123' AND T3.email_notifications_enabled = TRUE AND T3.private_profile = FALSE ORDER BY T1.username ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all users who have participated in group conversations created in April 2024, showing their username, conversation ID, and the group name."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.conversation_id, c.group_name\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true\n AND c.created_at >= '2024-04-01' AND c.created_at < '2024-05-01';"}, {"role": "user", "content": "Instead of all users, show only those who joined the group conversation after it was created."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.conversation_id, c.group_name\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true\n AND c.created_at >= '2024-04-01' AND c.created_at < '2024-05-01'\n AND cp.joined_at > c.created_at;"}, {"role": "user", "content": "I only care about group conversations where the group name contains the word 'Study'."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.conversation_id, c.group_name\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true\n AND c.created_at >= '2024-04-01' AND c.created_at < '2024-05-01'\n AND cp.joined_at > c.created_at\n AND c.group_name ILIKE '%Study%';"}]} +{"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 social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.follows ( follow_id.text, follower_user_id.text, following_user_id.text, created_at.timestamp )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "I want to get the list of users and their total number of public posts made in the last month, including user_id and post_count."}, {"role": "assistant", "content": "SELECT user_id, COUNT(*) AS post_count\nFROM social_media.posts\nWHERE visibility = 'public'\n AND created_at >= CURRENT_DATE - INTERVAL '1 month'\nGROUP BY user_id;"}, {"role": "user", "content": "Actually, include only users whose email_notifications_enabled is true."}, {"role": "assistant", "content": "SELECT p.user_id, COUNT(*) AS post_count\nFROM social_media.posts p\nJOIN social_media.user_settings u\n ON p.user_id = u.user_id\nWHERE p.visibility = 'public'\n AND p.created_at >= CURRENT_DATE - INTERVAL '1 month'\n AND u.email_notifications_enabled = true\nGROUP BY p.user_id;"}, {"role": "user", "content": "Also only consider posts that have media_type 'image'."}, {"role": "assistant", "content": "SELECT p.user_id, COUNT(*) AS post_count\nFROM social_media.posts p\nJOIN social_media.user_settings u\n ON p.user_id = u.user_id\nWHERE p.visibility = 'public'\n AND p.created_at >= CURRENT_DATE - INTERVAL '1 month'\n AND u.email_notifications_enabled = true\n AND p.media_type = 'image'\nGROUP BY p.user_id;"}, {"role": "user", "content": "Order the results by post_count descending and limit to the top 10."}, {"role": "assistant", "content": "SELECT p.user_id, COUNT(*) AS post_count\nFROM social_media.posts p\nJOIN social_media.user_settings u\n ON p.user_id = u.user_id\nWHERE p.visibility = 'public'\n AND p.created_at >= CURRENT_DATE - INTERVAL '1 month'\n AND u.email_notifications_enabled = true\n AND p.media_type = 'image'\nGROUP BY p.user_id\nORDER BY post_count DESC\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\nCREATE TABLE social_media.messages ( message_id.text, conversation_id.text, sender_user_id.text, content.text, media_url.text, media_type.text, sent_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.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": "List all messages that haven’t triggered any notification; show message_id, sender_user_id, and sent_at."}, {"role": "assistant", "content": "SELECT m.message_id, m.sender_user_id, m.sent_at\nFROM social_media.messages AS m\nLEFT JOIN social_media.notifications AS n\n ON n.target_entity_type = 'message'\n AND n.target_entity_id = m.message_id\nWHERE n.notification_id IS NULL;"}, {"role": "user", "content": "Actually, only include those sent before '2024-06-01'."}, {"role": "assistant", "content": "SELECT m.message_id, m.sender_user_id, m.sent_at\nFROM social_media.messages AS m\nLEFT JOIN social_media.notifications AS n\n ON n.target_entity_type = 'message'\n AND n.target_entity_id = m.message_id\nWHERE n.notification_id IS NULL\n AND m.sent_at < '2024-06-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n", "conversations": [{"role": "user", "content": "Show the post ID and hashtags for all posts containing the word 'conference' in their content."}, {"role": "assistant", "content": "SELECT p.post_id, h.hashtag_id, h.tag_name\nFROM social_media.posts p\nJOIN social_media.post_hashtags ph ON p.post_id = ph.post_id\nJOIN social_media.hashtags h ON ph.hashtag_id = h.hashtag_id\nWHERE p.content ILIKE '%conference%';"}]} +{"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 social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Count how many follow relationships were created in June 2024."}, {"role": "assistant", "content": "SELECT COUNT(follow_id) FROM social_media.follows WHERE created_at >= '2024-06-01' AND created_at < '2024-07-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "I want to know the usernames of users who have followed more than three different people, along with the date they created their accounts."}, {"role": "assistant", "content": "SELECT u.username, u.created_at, COUNT(DISTINCT f.following_user_id) AS following_count\nFROM social_media.users u\nJOIN social_media.follows f ON u.user_id = f.follower_user_id\nGROUP BY u.user_id, u.username, u.created_at\nHAVING COUNT(DISTINCT f.following_user_id) > 3;"}, {"role": "user", "content": "Also include the usernames of up to two users they are following for each user in the result."}, {"role": "assistant", "content": "SELECT u.username AS follower_username, u.created_at, uf.username AS following_username\nFROM social_media.users u\nJOIN social_media.follows f ON u.user_id = f.follower_user_id\nJOIN social_media.users uf ON f.following_user_id = uf.user_id\nWHERE u.user_id IN (\n SELECT f1.follower_user_id\n FROM social_media.follows f1\n GROUP BY f1.follower_user_id\n HAVING COUNT(DISTINCT f1.following_user_id) > 3\n)\nORDER BY u.username, f.created_at\nLIMIT 2;"}, {"role": "user", "content": "Can you instead provide all usernames they follow, not just two, and include the follow creation date as well?"}, {"role": "assistant", "content": "SELECT u.username AS follower_username, u.created_at AS follower_created_at, uf.username AS following_username, f.created_at AS follow_created_at\nFROM social_media.users u\nJOIN social_media.follows f ON u.user_id = f.follower_user_id\nJOIN social_media.users uf ON f.following_user_id = uf.user_id\nWHERE u.user_id IN (\n SELECT f1.follower_user_id\n FROM social_media.follows f1\n GROUP BY f1.follower_user_id\n HAVING COUNT(DISTINCT f1.following_user_id) > 3\n)\nORDER BY u.username, f.created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text, tag_name text, created_at timestamp )\nCREATE TABLE social_media.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )\nCREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List all comments on a given post along with the commenter’s username and the comment time."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content, u.username, c.created_at\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nWHERE c.post_id = '';"}, {"role": "user", "content": "Please also indicate if the comment is a reply by showing the parent_comment_id as well."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content, u.username, c.created_at, c.parent_comment_id\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nWHERE c.post_id = '';"}, {"role": "user", "content": "Filter to only show the top-level comments (those without a parent_comment_id)."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content, u.username, c.created_at, c.parent_comment_id\nFROM social_media.comments c\nJOIN social_media.users u ON c.user_id = u.user_id\nWHERE c.post_id = ''\n AND c.parent_comment_id IS NULL;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\n", "conversations": [{"role": "user", "content": "How many group conversations are there?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.conversations WHERE is_group_chat = TRUE;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\nCREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\nCREATE TABLE web3.tokens (\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.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each block, get the count of failed transactions and the total gas used by these failed transactions. Show block_number, failed_tx_count, and total_failed_gas."}, {"role": "assistant", "content": "SELECT block_number,\n COUNT(*) FILTER (WHERE status = 'failed') AS failed_tx_count,\n SUM(gas_used) FILTER (WHERE status = 'failed') AS total_failed_gas\nFROM web3.transactions\nGROUP BY block_number;"}, {"role": "user", "content": "Actually, I need only blocks with failed_tx_count greater than 10."}, {"role": "assistant", "content": "SELECT block_number,\n COUNT(*) FILTER (WHERE status = 'failed') AS failed_tx_count,\n SUM(gas_used) FILTER (WHERE status = 'failed') AS total_failed_gas\nFROM web3.transactions\nGROUP BY block_number\nHAVING COUNT(*) FILTER (WHERE status = 'failed') > 10;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.maintenance_records ( record_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, asset_type character varying(32) NOT NULL, maintenance_type character varying(128) NOT NULL, staff_id character varying(64), start_datetime timestamp NOT NULL, end_datetime timestamp, description text NOT NULL, cost numeric(12, 2), status character varying(32) NOT NULL DEFAULT 'Completed', PRIMARY KEY (record_id), FOREIGN KEY (staff_id) REFERENCES train_station_management.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "What is the reason behind the cost variation for maintenance of asset_id 'ASSET456' over the past year?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information on the reasons behind cost variations for maintenance. The data in the maintenance_records table includes only the cost amount and other basic details of each maintenance record, but it does not contain explanations or factors influencing cost changes."}]} +{"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 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) )\n", "conversations": [{"role": "user", "content": "Find all guests who live in the same city and list each guest's name along with the name of another guest in that city."}, {"role": "assistant", "content": "SELECT g1.first_name || ' ' || g1.last_name AS guest_name,\n g2.first_name || ' ' || g2.last_name AS other_guest_name,\n g1.city\nFROM guests g1\nJOIN guests g2\n ON g1.city = g2.city\n AND g1.guest_id <> g2.guest_id;"}, {"role": "user", "content": "Now restrict to only cities with more than two guests and order by city ascending."}, {"role": "assistant", "content": "SELECT pairs.city,\n pairs.guest_name,\n pairs.other_guest_name\nFROM (\n SELECT g1.first_name || ' ' || g1.last_name AS guest_name,\n g2.first_name || ' ' || g2.last_name AS other_guest_name,\n g1.city\n FROM guests g1\n JOIN guests g2\n ON g1.city = g2.city\n AND g1.guest_id <> g2.guest_id\n) AS pairs\nJOIN (\n SELECT city\n FROM guests\n GROUP BY city\n HAVING COUNT(*) > 2\n) AS multi\n ON pairs.city = multi.city\nORDER BY pairs.city ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\n", "conversations": [{"role": "user", "content": "I want to see pairs of fundraising rounds for projects that have at least two rounds. Please list project_name, earlier_round, earlier_investment, later_round, and later_investment."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date;"}, {"role": "user", "content": "Only include pairs where later_investment is greater than earlier_investment."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date\nWHERE later.investment_value > earlier.investment_value;"}, {"role": "user", "content": "Also calculate the valuation change between the two rounds as valuation_diff."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment,\n (later.valuation - earlier.valuation) AS valuation_diff\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date\nWHERE later.investment_value > earlier.investment_value;"}, {"role": "user", "content": "Order by the investment increase descending and limit to top 5."}, {"role": "assistant", "content": "SELECT\n earlier.project_name,\n earlier.rounds_name AS earlier_round,\n earlier.investment_value AS earlier_investment,\n later.rounds_name AS later_round,\n later.investment_value AS later_investment,\n (later.valuation - earlier.valuation) AS valuation_diff\nFROM project_fundraising_record AS earlier\nJOIN project_fundraising_record AS later\n ON earlier.project_id = later.project_id\n AND earlier.investment_date < later.investment_date\nWHERE later.investment_value > earlier.investment_value\nORDER BY (later.investment_value - earlier.investment_value) DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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) )\n", "conversations": [{"role": "user", "content": "Show me all assets whose symbol starts with 'BTC' or 'ETH', along with their full names and types."}, {"role": "assistant", "content": "SELECT asset_id, name, symbol, type FROM trading_platform.assets WHERE symbol LIKE 'BTC%' OR symbol LIKE 'ETH%';"}]} +{"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 transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\n", "conversations": [{"role": "user", "content": "List all pairs of vehicles with the same make and model but different manufacture years. Include each vehicle's ID, make, model, and both years."}, {"role": "assistant", "content": "SELECT v1.vehicle_id AS vehicle1_id, v2.vehicle_id AS vehicle2_id, v1.make, v1.model, v1.year AS year1, v2.year AS year2\nFROM transportation.vehicles v1\nJOIN transportation.vehicles v2\n ON v1.make = v2.make\n AND v1.model = v2.model\n AND v1.year <> v2.year\n AND v1.vehicle_id < v2.vehicle_id\nORDER BY v1.make, v1.model, v1.year;"}]} +{"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 trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\n", "conversations": [{"role": "user", "content": "List all trades for asset 'BTC' where the trade quantity is greater than 5."}, {"role": "assistant", "content": "SELECT trade_id, order_id, buyer_id, seller_id, quantity, price, traded_at FROM trading_platform.trades WHERE asset_id = 'BTC' AND quantity > 5;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "Provide a count of contracts for each unique combination of network ID and status."}, {"role": "assistant", "content": "SELECT network_id, status, COUNT(*) FROM web3.contracts GROUP BY network_id, status;"}, {"role": "user", "content": "Now, only show the network IDs from the previous result that have contracts in more than one distinct status."}, {"role": "assistant", "content": "SELECT network_id FROM web3.contracts GROUP BY network_id HAVING COUNT(DISTINCT status) > 1;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id.text, national_id_number.text, first_name.text, last_name.text, date_of_birth.date, gender.text, primary_address.text, contact_email.text, contact_phone.text, registration_date.timestamp, is_verified.boolean )\nCREATE TABLE government_services.payments ( payment_id.text, application_id.text, citizen_id.text, service_id.text, amount.numeric, currency.text, payment_method.text, payment_provider_reference.text, payment_timestamp.timestamp, status.text, notes.text )\nCREATE TABLE government_services.appointments ( appointment_id.text, citizen_id.text, employee_id.text, location_id.text, service_id.text, scheduled_start_time.timestamp, scheduled_end_time.timestamp, purpose.text, status.text, booking_method.text, created_at.timestamp, notes.text )\n", "conversations": [{"role": "user", "content": "Which citizens have scheduled any appointments? Show their first and last name."}, {"role": "assistant", "content": "SELECT DISTINCT T1.first_name , T1.last_name FROM government_services.citizens AS T1 JOIN government_services.appointments AS T2 ON T1.citizen_id = T2.citizen_id"}, {"role": "user", "content": "Also include the total number of appointments for each of these citizens."}, {"role": "assistant", "content": "SELECT T1.first_name , T1.last_name , COUNT(T2.appointment_id) FROM government_services.citizens AS T1 JOIN government_services.appointments AS T2 ON T1.citizen_id = T2.citizen_id GROUP BY T1.citizen_id , T1.first_name , T1.last_name"}, {"role": "user", "content": "Only include citizens with more than 3 appointments."}, {"role": "assistant", "content": "SELECT T1.first_name , T1.last_name , COUNT(T2.appointment_id) FROM government_services.citizens AS T1 JOIN government_services.appointments AS T2 ON T1.citizen_id = T2.citizen_id GROUP BY T1.citizen_id , T1.first_name , T1.last_name HAVING COUNT(T2.appointment_id) > 3"}, {"role": "user", "content": "And filter the appointments to only include those with status 'Completed'."}, {"role": "assistant", "content": "SELECT T1.first_name , T1.last_name , COUNT(T2.appointment_id) FROM government_services.citizens AS T1 JOIN government_services.appointments AS T2 ON T1.citizen_id = T2.citizen_id WHERE T2.status = 'Completed' GROUP BY T1.citizen_id , T1.first_name , T1.last_name HAVING COUNT(T2.appointment_id) > 3"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid PRIMARY KEY, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\n", "conversations": [{"role": "user", "content": "Can you show me the total number of items and the average cost amount for each item type and rarity combination?"}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS total_items, AVG(cost_amount) AS avg_cost_amount\nFROM gaming_technology.in_game_items\nGROUP BY item_type, rarity;"}, {"role": "user", "content": "Could you filter the results to only include item_type and rarity groups where there are more than 2 items?"}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS total_items, AVG(cost_amount) AS avg_cost_amount\nFROM gaming_technology.in_game_items\nGROUP BY item_type, rarity\nHAVING COUNT(*) > 2;"}, {"role": "user", "content": "Now only show results where the average cost amount is greater than 100."}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS total_items, AVG(cost_amount) AS avg_cost_amount\nFROM gaming_technology.in_game_items\nGROUP BY item_type, rarity\nHAVING COUNT(*) > 2 AND AVG(cost_amount) > 100;"}, {"role": "user", "content": "Can you order the results by avg_cost_amount descending?"}, {"role": "assistant", "content": "SELECT item_type, rarity, COUNT(*) AS total_items, AVG(cost_amount) AS avg_cost_amount\nFROM gaming_technology.in_game_items\nGROUP BY item_type, rarity\nHAVING COUNT(*) > 2 AND AVG(cost_amount) > 100\nORDER BY avg_cost_amount DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n", "conversations": [{"role": "user", "content": "Show me all users who have been notified by the system (i.e. notifications where the sender_user_id is NULL). Please include their username and the type of each notification."}, {"role": "assistant", "content": "SELECT u.username, n.notification_type, n.notification_id\nFROM social_media.users u\nJOIN social_media.notifications n ON u.user_id = n.recipient_user_id\nWHERE n.sender_user_id IS NULL;"}, {"role": "user", "content": "I'd like to know which of these users have private profiles. Please add that column to the results."}, {"role": "assistant", "content": "SELECT u.username, n.notification_type, n.notification_id, us.private_profile\nFROM social_media.users u\nJOIN social_media.notifications n ON u.user_id = n.recipient_user_id\nJOIN social_media.user_settings us ON u.user_id = us.user_id\nWHERE n.sender_user_id IS NULL;"}, {"role": "user", "content": "Now, restrict the list to only show system notifications sent after June 1, 2024."}, {"role": "assistant", "content": "SELECT u.username, n.notification_type, n.notification_id, us.private_profile\nFROM social_media.users u\nJOIN social_media.notifications n ON u.user_id = n.recipient_user_id\nJOIN social_media.user_settings us ON u.user_id = us.user_id\nWHERE n.sender_user_id IS NULL AND n.created_at > '2024-06-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve pairs of likes where the same user liked two different posts. For each pair, show user_id, p1.post_id AS first_post_id, p2.post_id AS second_post_id, and the time difference in minutes between the two likes."}, {"role": "assistant", "content": "SELECT p1.user_id,\n p1.post_id AS first_post_id,\n p2.post_id AS second_post_id,\n ABS(EXTRACT(EPOCH FROM (p1.created_at - p2.created_at)))/60 AS minutes_diff\nFROM social_media.likes p1\nJOIN social_media.likes p2\n ON p1.user_id = p2.user_id\n AND p1.post_id <> p2.post_id;"}, {"role": "user", "content": "Only include pairs where the time difference is less than 30 minutes."}, {"role": "assistant", "content": "SELECT p1.user_id,\n p1.post_id AS first_post_id,\n p2.post_id AS second_post_id,\n ABS(EXTRACT(EPOCH FROM (p1.created_at - p2.created_at)))/60 AS minutes_diff\nFROM social_media.likes p1\nJOIN social_media.likes p2\n ON p1.user_id = p2.user_id\n AND p1.post_id <> p2.post_id\nWHERE ABS(EXTRACT(EPOCH FROM (p1.created_at - p2.created_at)))/60 < 30;"}]} -{"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 legal_services.lawyers ( lawyer_id text PRIMARY KEY, first_name text, last_name text, bar_number text UNIQUE, firm_id text, email text UNIQUE, phone text, specialization text, hire_date timestamp, is_partner bool )\n", "conversations": [{"role": "user", "content": "Find all pairs of lawyers from the same firm who have the same specialization."}, {"role": "assistant", "content": "SELECT a.lawyer_id AS lawyer_id_1, a.first_name AS first_name_1, a.last_name AS last_name_1, b.lawyer_id AS lawyer_id_2, b.first_name AS first_name_2, b.last_name AS last_name_2, a.specialization FROM legal_services.lawyers a JOIN legal_services.lawyers b ON a.firm_id = b.firm_id AND a.specialization = b.specialization AND a.lawyer_id < b.lawyer_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 )\n", "conversations": [{"role": "user", "content": "Can you give me all locations in Los Angeles?"}, {"role": "assistant", "content": "SELECT location_id, name, type, address_line1, city, state_province, postal_code, country, latitude, longitude, timezone\nFROM transportation.locations\nWHERE city = 'Los Angeles';"}, {"role": "user", "content": "I want to see only locations of type 'Depot' in Los Angeles."}, {"role": "assistant", "content": "SELECT location_id, name, type, address_line1, city, state_province, postal_code, country, latitude, longitude, timezone\nFROM transportation.locations\nWHERE city = 'Los Angeles' AND type = 'Depot';"}, {"role": "user", "content": "Can you show me their postal codes and sort them by name in ascending order?"}, {"role": "assistant", "content": "SELECT location_id, name, postal_code\nFROM transportation.locations\nWHERE city = 'Los Angeles' AND type = 'Depot'\nORDER BY name ASC;"}, {"role": "user", "content": "Actually, I also want to see the state_province in the output."}, {"role": "assistant", "content": "SELECT location_id, name, postal_code, state_province\nFROM transportation.locations\nWHERE city = 'Los Angeles' AND type = 'Depot'\nORDER BY name ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\n", "conversations": [{"role": "user", "content": "Show the count of citizens grouped by their verification status."}, {"role": "assistant", "content": "SELECT is_verified, COUNT(*) FROM government_services.citizens GROUP BY is_verified;"}, {"role": "user", "content": "Now, only include citizens who registered after January 1, 2023."}, {"role": "assistant", "content": "SELECT is_verified, COUNT(*) FROM government_services.citizens WHERE registration_date >= '2023-01-01' GROUP BY is_verified;"}]} -{"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 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": "List all accounts for customers who have at least one account with a balance over 10000 and another account with a balance under 1000. Show customer_id, account_id, account_type, balance, and currency."}, {"role": "assistant", "content": "SELECT account_id , customer_id , account_type , balance , currency FROM financial_services.accounts WHERE customer_id IN ( SELECT T1.customer_id FROM financial_services.accounts AS T1 JOIN financial_services.accounts AS T2 ON T1.customer_id = T2.customer_id WHERE T1.balance > 10000 AND T2.balance < 1000 )"}, {"role": "user", "content": "Actually, I only want to see the accounts that meet the specific balance criteria (over 10k or under 1k), not all accounts for those customers. And only include accounts where the status is 'Open'."}, {"role": "assistant", "content": "SELECT account_id , customer_id , account_type , balance , currency FROM financial_services.accounts WHERE customer_id IN ( SELECT T1.customer_id FROM financial_services.accounts AS T1 JOIN financial_services.accounts AS T2 ON T1.customer_id = T2.customer_id WHERE T1.balance > 10000 AND T2.balance < 1000 ) AND (balance > 10000 OR balance < 1000) AND status = 'Open'"}, {"role": "user", "content": "Could you also include the opened_date and sort the results by customer_id, then by balance descending?"}, {"role": "assistant", "content": "SELECT account_id , customer_id , account_type , balance , currency , opened_date FROM financial_services.accounts WHERE customer_id IN ( SELECT T1.customer_id FROM financial_services.accounts AS T1 JOIN financial_services.accounts AS T2 ON T1.customer_id = T2.customer_id WHERE T1.balance > 10000 AND T2.balance < 1000 ) AND (balance > 10000 OR balance < 1000) AND status = 'Open' ORDER BY customer_id ASC , balance DESC"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List the top 5 largest unspent UTXOs by amount, showing utxo_id, address, and amount, ordered descending."}, {"role": "assistant", "content": "SELECT utxo_id, address, amount FROM trading_platform.utxos WHERE spent = false ORDER BY amount DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.trips ( trip_id text, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count integer, cargo_manifest_id text )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs ( log_id text, vehicle_id text, service_date date, odometer_reading integer, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me all trips along with the city name of their origin and the scheduled departure time."}, {"role": "assistant", "content": "SELECT t.trip_id, l.name AS origin_city, t.scheduled_departure\nFROM transportation.trips t\nJOIN transportation.locations l ON t.origin_location_id = l.location_id;"}, {"role": "user", "content": "Can you add the destination city name as well?"}, {"role": "assistant", "content": "SELECT t.trip_id, l1.name AS origin_city, l2.name AS destination_city, t.scheduled_departure\nFROM transportation.trips t\nJOIN transportation.locations l1 ON t.origin_location_id = l1.location_id\nJOIN transportation.locations l2 ON t.destination_location_id = l2.location_id;"}, {"role": "user", "content": "Only show trips where the origin city is different from the destination city."}, {"role": "assistant", "content": "SELECT t.trip_id, l1.name AS origin_city, l2.name AS destination_city, t.scheduled_departure\nFROM transportation.trips t\nJOIN transportation.locations l1 ON t.origin_location_id = l1.location_id\nJOIN transportation.locations l2 ON t.destination_location_id = l2.location_id\nWHERE l1.city <> l2.city;"}, {"role": "user", "content": "Instead of city names, show the actual full addresses for both origin and destination."}, {"role": "assistant", "content": "SELECT t.trip_id, l1.address_line1 AS origin_address, l2.address_line1 AS destination_address, t.scheduled_departure\nFROM transportation.trips t\nJOIN transportation.locations l1 ON t.origin_location_id = l1.location_id\nJOIN transportation.locations l2 ON t.destination_location_id = l2.location_id\nWHERE l1.city <> l2.city;"}]} -{"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 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 NOT NULL DEFAULT gen_random_uuid(), title character varying(200) NOT NULL, developer_id uuid NOT NULL, publisher_id uuid, genre character varying(100), release_date date, description text, platform character varying(50) NOT NULL, engine character varying(100), website character varying(255), PRIMARY KEY (game_id) )\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.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )\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": "Show me a list of players and, for each, list all the different games where they have acquired items. Also include the number of unique item types they've acquired per game."}, {"role": "assistant", "content": "SELECT p.player_id, p.username, g.title AS game_title, COUNT(DISTINCT i.item_type) AS unique_item_types \nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.players p ON pi.player_id = p.player_id\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nGROUP BY p.player_id, p.username, g.title;"}, {"role": "user", "content": "Can you show only the player/game combinations where at least 2 unique item types were acquired?"}, {"role": "assistant", "content": "SELECT p.player_id, p.username, g.title AS game_title, COUNT(DISTINCT i.item_type) AS unique_item_types \nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.players p ON pi.player_id = p.player_id\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nGROUP BY p.player_id, p.username, g.title\nHAVING COUNT(DISTINCT i.item_type) >= 2;"}, {"role": "user", "content": "I got too many results. Can you list only players who registered after January 1, 2023?"}, {"role": "assistant", "content": "SELECT p.player_id, p.username, g.title AS game_title, COUNT(DISTINCT i.item_type) AS unique_item_types \nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.players p ON pi.player_id = p.player_id\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE p.registration_date > '2023-01-01'\nGROUP BY p.player_id, p.username, g.title\nHAVING COUNT(DISTINCT i.item_type) >= 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\n", "conversations": [{"role": "user", "content": "Show me all cases that are associated with the court jurisdiction 'Federal Court'."}, {"role": "assistant", "content": "SELECT * FROM legal_services.cases WHERE court_jurisdiction = 'Federal Court';"}, {"role": "user", "content": "From these cases, only list those that have a status of 'Pending'."}, {"role": "assistant", "content": "SELECT * FROM legal_services.cases WHERE court_jurisdiction = 'Federal Court' AND status = 'Pending';"}, {"role": "user", "content": "For these pending cases in Federal Court, just show the case name, status, and lead lawyer ID."}, {"role": "assistant", "content": "SELECT case_name, status, lead_lawyer_id FROM legal_services.cases WHERE court_jurisdiction = 'Federal Court' AND status = 'Pending';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\n", "conversations": [{"role": "user", "content": "Which developers founded after 2010 have published games using the 'Unreal Engine'? List the developer's name, country, game title, and the release year."}, {"role": "assistant", "content": "SELECT d.name AS developer_name, d.country, g.title AS game_title, EXTRACT(YEAR FROM g.release_date) AS release_year\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g\n ON d.developer_id = g.developer_id\nWHERE d.founded_year > 2010 AND g.engine = 'Unreal Engine';"}, {"role": "user", "content": "Show only games released in or after 2022."}, {"role": "assistant", "content": "SELECT d.name AS developer_name, d.country, g.title AS game_title, EXTRACT(YEAR FROM g.release_date) AS release_year\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g\n ON d.developer_id = g.developer_id\nWHERE d.founded_year > 2010 AND g.engine = 'Unreal Engine' AND g.release_date >= '2022-01-01';"}, {"role": "user", "content": "Include the developer's website and the full release date for each game."}, {"role": "assistant", "content": "SELECT d.name AS developer_name, d.country, d.website AS developer_website, g.title AS game_title, g.release_date\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g\n ON d.developer_id = g.developer_id\nWHERE d.founded_year > 2010 AND g.engine = 'Unreal Engine' AND g.release_date >= '2022-01-01';"}, {"role": "user", "content": "Now, limit the results to developers located in 'Canada'."}, {"role": "assistant", "content": "SELECT d.name AS developer_name, d.country, d.website AS developer_website, g.title AS game_title, g.release_date\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g\n ON d.developer_id = g.developer_id\nWHERE d.founded_year > 2010 AND g.engine = 'Unreal Engine' AND g.release_date >= '2022-01-01' AND d.country = 'Canada';"}]} -{"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 web3.contracts ( contract_id.text, address.text, abi.text, bytecode.text, deployer_address.text, deployed_at.timestamp, network_id.text, status.text )\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\nCREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Count the number of tokens for each contract address."}, {"role": "assistant", "content": "SELECT contract_address, COUNT(*) AS token_count FROM web3.tokens GROUP BY contract_address;"}, {"role": "user", "content": "Only show contracts that have more than 5 tokens."}, {"role": "assistant", "content": "SELECT contract_address, COUNT(*) AS token_count FROM web3.tokens GROUP BY contract_address HAVING COUNT(*) > 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\n", "conversations": [{"role": "user", "content": "Can you narrow this down to only show cases where the case type is 'Criminal'?"}, {"role": "assistant", "content": "SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE lead_lawyer_id = 'lawyer_abc' AND status = 'Open' AND case_type = 'Criminal';"}]} -{"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 healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "Find all pairs of different insurance records that share the same group_number, and show group_number, the patient_insurance_id of both records, and their corresponding patient_ids."}, {"role": "assistant", "content": "SELECT a.group_number,\n a.patient_insurance_id AS pi_id1,\n a.patient_id AS patient1_id,\n b.patient_insurance_id AS pi_id2,\n b.patient_id AS patient2_id\nFROM healthcare.patient_insurance a\nJOIN healthcare.patient_insurance b\n ON a.group_number = b.group_number\n AND a.patient_insurance_id < b.patient_insurance_id\nWHERE a.group_number IS NOT NULL;"}]} -{"system": "You are an 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 government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.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.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\nCREATE TABLE government_services.employees ( employee_id.text, agency_id.text, first_name.text, last_name.text, job_title.text, department.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, access_level.text, manager_employee_id.text )\nCREATE TABLE government_services.service_locations ( location_id.text, agency_id.text, location_name.text, address.text, city.text, state.text, postal_code.text, latitude.numeric, longitude.numeric, operating_hours.text, contact_phone.text, is_accessible.boolean )\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": "Find all service locations that currently have no appointments scheduled. Display the location name and contact phone number."}, {"role": "assistant", "content": "SELECT sl.location_name,\n sl.contact_phone\nFROM government_services.service_locations sl\nLEFT JOIN government_services.appointments ap ON sl.location_id = ap.location_id\nWHERE ap.appointment_id IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )\nCREATE TABLE financial_services.accounts ( account_id.text, customer_id.text, account_number.text, account_type.text, balance.numeric, currency.text, opened_date.date, status.text, interest_rate.numeric, last_updated_at.timestamp )\nCREATE TABLE financial_services.transactions ( 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.trades ( trade_id.text, account_id.text, security_id.text, order_id.text, trade_type.text, quantity.numeric, price_per_unit.numeric, total_amount.numeric, commission.numeric, trade_timestamp.timestamp, settlement_date.date, status.text, execution_venue.text )\nCREATE TABLE financial_services.employees ( employee_id.text, first_name.text, last_name.text, job_title.text, department.text, branch_id.text, email.text, phone_extension.text, hire_date.date, termination_date.date, manager_id.text, status.text )\n", "conversations": [{"role": "user", "content": "List all employees who were hired in the last two years along with their department and status."}, {"role": "assistant", "content": "SELECT employee_id, first_name, last_name, department, status FROM financial_services.employees WHERE hire_date >= (CURRENT_DATE - INTERVAL '2 years');"}, {"role": "user", "content": "Now also include their manager's full name in the output."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name, e.last_name, e.department, e.status, m.first_name || ' ' || m.last_name AS manager_full_name FROM financial_services.employees e LEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id WHERE e.hire_date >= (CURRENT_DATE - INTERVAL '2 years');"}, {"role": "user", "content": "Only include employees whose status is 'Active' and whose manager is also currently 'Active'."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name, e.last_name, e.department, e.status, m.first_name || ' ' || m.last_name AS manager_full_name FROM financial_services.employees e LEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id WHERE e.hire_date >= (CURRENT_DATE - INTERVAL '2 years') AND e.status = 'Active' AND m.status = 'Active';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.locations ( location_id character varying(64) NOT NULL, name character varying(255) NOT NULL, type character varying(64) NOT NULL, address_line1 character varying(255), city character varying(128), state_province character varying(128), postal_code character varying(32), country character varying(64) NOT NULL, latitude numeric(9, 6), longitude numeric(9, 6), timezone character varying(64), PRIMARY KEY (location_id) )\n", "conversations": [{"role": "user", "content": "Get all pairs of locations in the same city, showing both location IDs, names, and the shared city."}, {"role": "assistant", "content": "SELECT l1.location_id AS location1_id, l1.name AS location1_name,\n l2.location_id AS location2_id, l2.name AS location2_name,\n l1.city\nFROM transportation.locations l1\nJOIN transportation.locations l2\n ON l1.city = l2.city\n AND l1.location_id < l2.location_id;"}]} -{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.trains (\n train_id character varying(64) NOT NULL, -- Unique identifier for the train set\n train_number character varying(32) NOT NULL, -- Operational number of the train (e.g., 'Acela 2151')\n model character varying(128), -- Model of the train (e.g., 'Siemens Velaro')\n manufacturer character varying(128), -- Manufacturer of the train\n year_manufactured integer, -- Year the train was built\n capacity integer NOT NULL, -- Total passenger capacity\n status character varying(32) NOT NULL DEFAULT 'Active', -- e.g., Active, Maintenance, Retired\n last_maintenance_date date, -- Date of last scheduled maintenance\n next_maintenance_date date, -- Date of next scheduled maintenance\n PRIMARY KEY (train_id),\n UNIQUE (train_number)\n)\n", "conversations": [{"role": "user", "content": "What is the current location of train number Acela 2151?"}, {"role": "assistant", "content": "I'm sorry, but I don't have access to real-time location data for trains. The database only contains static information such as train ID, model, capacity, and maintenance schedules. For current location updates, please check with the train operator or a tracking service."}]} -{"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 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.developers (\n developer_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the developer studio\n name character varying(150) NOT NULL UNIQUE, -- name of the development studio\n country character varying(100), -- country where the studio is based\n founded_year integer, -- year the studio was founded\n website character varying(255), -- developer's official website\n created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (developer_id)\n)\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\n", "conversations": [{"role": "user", "content": "Can you show me the count of players from each country who have unlocked at least one achievement developed by studios based in France?"}, {"role": "assistant", "content": "SELECT p.country_code, COUNT(DISTINCT p.player_id) AS player_count\nFROM gaming_technology.players p\nJOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id\nJOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id\nJOIN gaming_technology.games g ON a.game_id = g.game_id\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nWHERE d.country = 'France'\nGROUP BY p.country_code;"}, {"role": "user", "content": "Actually, can you only include countries where more than 10 such players exist?"}, {"role": "assistant", "content": "SELECT p.country_code, COUNT(DISTINCT p.player_id) AS player_count\nFROM gaming_technology.players p\nJOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id\nJOIN gaming_technology.achievements a ON pa.achievement_id = a.achievement_id\nJOIN gaming_technology.games g ON a.game_id = g.game_id\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nWHERE d.country = 'France'\nGROUP BY p.country_code\nHAVING COUNT(DISTINCT p.player_id) > 10;"}, {"role": "user", "content": "I got an error because the 'achievements' table doesn't exist. Can you modify the query to only show the count of players per country who appeared in the player_achievements table and whose achievements link with any developer from France?"}, {"role": "assistant", "content": "SELECT p.country_code, COUNT(DISTINCT p.player_id) AS player_count\nFROM gaming_technology.players p\nJOIN gaming_technology.player_achievements pa ON p.player_id = pa.player_id\nJOIN gaming_technology.games g ON pa.achievement_id = g.game_id -- achievement_id as game_id fallback\nJOIN gaming_technology.developers d ON g.developer_id = d.developer_id\nWHERE d.country = 'France'\nGROUP BY p.country_code\nHAVING COUNT(DISTINCT p.player_id) > 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\n", "conversations": [{"role": "user", "content": "Provide a count of transactions grouped by their status."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM web3.transactions GROUP BY status;"}, {"role": "user", "content": "Now, only show the statuses that have more than 50 transactions."}, {"role": "assistant", "content": "SELECT status, COUNT(*) FROM web3.transactions GROUP BY status HAVING COUNT(*) > 50;"}]} +{"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 web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\n", "conversations": [{"role": "user", "content": "For each event, display its event_id, the event_id of the previous event in the same transaction (if any), and the log_index of both events."}, {"role": "assistant", "content": "SELECT curr.event_id AS current_event_id,\n prev.event_id AS previous_event_id,\n curr.log_index AS current_log_index,\n prev.log_index AS previous_log_index,\n curr.transaction_id\nFROM web3.events curr\nLEFT JOIN web3.events prev\n ON curr.transaction_id = prev.transaction_id\n AND curr.log_index = prev.log_index + 1;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars ( car_id character varying(64) NOT NULL, train_id character varying(64) NOT NULL, car_number character varying(10) NOT NULL, car_type character varying(64) NOT NULL, class character varying(32), capacity integer, features text, PRIMARY KEY (car_id), FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id) )\n", "conversations": [{"role": "user", "content": "What is the maintenance schedule for the train car with car_id 'CAR456'?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information about the maintenance schedule for train cars as it is not included in the data available in the train_cars table."}]} +{"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 web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\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.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 web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n", "conversations": [{"role": "user", "content": "List the username, registration date, and the creation date of the first wallet created by each user who owns at least one wallet."}, {"role": "assistant", "content": "SELECT u.username, u.created_at AS registration_date, MIN(w.created_at) AS first_wallet_creation_date FROM web3.users AS u JOIN web3.wallets AS w ON u.user_id = w.user_id GROUP BY u.user_id, u.username, u.created_at;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars (\n car_id character varying(64) NOT NULL, -- Unique identifier for the train car\n train_id character varying(64) NOT NULL, -- Foreign key referencing trains\n car_number character varying(10) NOT NULL, -- Identifier of the car within the train set\n car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage\n class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars)\n capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars)\n features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom')\n PRIMARY KEY (car_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id)\n)\n", "conversations": [{"role": "user", "content": "What is the current location of a specific train car with car_id 'TC123'?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide the current location of a specific train car as this information is not stored in the database table. The table only contains static details about train cars such as car type, capacity, and features. For real-time location data, please refer to the train tracking system or contact the relevant department."}]} +{"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 transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\n", "conversations": [{"role": "user", "content": "Show all fuel logs for vehicle_id 'VH123', including the timestamp, fuel type, quantity, and the location_id. Sort the list by timestamp descending."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "Can you also include the odometer reading and total cost for each fuel log in the result?"}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "I only want to see records where the total_cost is above 100."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\n AND total_cost > 100\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "Actually, please limit the results to just the 5 most recent logs."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\n AND total_cost > 100\nORDER BY log_timestamp DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies (\n policy_id character varying(64) NOT NULL, -- unique identifier for the policy\n customer_id character varying(64) NOT NULL, -- identifier for the policyholder (FK to customers)\n product_id character varying(64) NOT NULL, -- identifier for the insurance product (FK to insurance_products)\n agent_id character varying(64), -- identifier for the agent who sold the policy (FK to agents)\n policy_number character varying(100) NOT NULL UNIQUE, -- customer-facing policy number\n start_date date NOT NULL, -- date the policy coverage begins\n end_date date NOT NULL, -- date the policy coverage ends\n premium_amount numeric(12, 2) NOT NULL, -- total premium for the policy term\n coverage_limit numeric(15, 2) NOT NULL, -- maximum amount covered\n deductible numeric(10, 2) NOT NULL, -- amount customer pays before coverage kicks in\n status character varying(30) NOT NULL, -- e.g., Active, Expired, Cancelled, Pending\n issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the policy was issued\n cancellation_date date,\n cancellation_reason text,\n PRIMARY KEY (policy_id)\n)\n", "conversations": [{"role": "user", "content": "Show me a list of all policy numbers that have a deductible exactly equal to 0."}, {"role": "assistant", "content": "SELECT policy_number\nFROM insurance.policies\nWHERE deductible = 0;"}]} +{"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 project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, token_symbol character varying(100), token_amount numeric(38,2), usd_value numeric(38,2), avg_price numeric(38,6), type int, address_amount integer, narrative character varying(100), chain character varying(100) )\n", "conversations": [{"role": "user", "content": "Show me the top 5 projects by total investment value, along with their latest fundraising round name and valuation."}, {"role": "assistant", "content": "SELECT project_name, rounds_name, valuation, SUM(investment_value) AS total_investment_value FROM project_fundraising_record GROUP BY project_name, rounds_name, valuation ORDER BY total_investment_value DESC LIMIT 5;"}, {"role": "user", "content": "Can you also include the investment date for these projects?"}, {"role": "assistant", "content": "SELECT project_name, rounds_name, valuation, investment_date, SUM(investment_value) AS total_investment_value FROM project_fundraising_record GROUP BY project_name, rounds_name, valuation, investment_date ORDER BY total_investment_value DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "Count the number of contracts for each network_id."}, {"role": "assistant", "content": "SELECT network_id, COUNT(*) FROM web3.contracts GROUP BY network_id;"}, {"role": "user", "content": "Now, only show networks with more than 100 contracts."}, {"role": "assistant", "content": "SELECT network_id, COUNT(*) FROM web3.contracts GROUP BY network_id HAVING COUNT(*) > 100;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.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": "For each claim, count the number of beneficiaries associated with its policy. Show claim_id and beneficiary_count, only for claims with more than 2 beneficiaries."}, {"role": "assistant", "content": "SELECT c.claim_id, COUNT(pb.beneficiary_id) AS beneficiary_count\nFROM insurance.claims c\nJOIN insurance.policy_beneficiaries pb ON c.policy_id = pb.policy_id\nGROUP BY c.claim_id\nHAVING COUNT(pb.beneficiary_id) > 2;"}, {"role": "user", "content": "Now restrict the result to claims reported in 2023."}, {"role": "assistant", "content": "SELECT c.claim_id, COUNT(pb.beneficiary_id) AS beneficiary_count\nFROM insurance.claims c\nJOIN insurance.policy_beneficiaries pb ON c.policy_id = pb.policy_id\nWHERE c.reported_date >= '2023-01-01' AND c.reported_date < '2024-01-01'\nGROUP BY c.claim_id\nHAVING COUNT(pb.beneficiary_id) > 2;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\n", "conversations": [{"role": "user", "content": "Show me all drivers and the vehicles they are assigned for trips that have status 'Delayed'. Include driver first_name, driver last_name, vehicle license_plate, trip_id, and actual_departure."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, v.license_plate, t.trip_id, t.actual_departure\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nWHERE t.status = 'Delayed';"}, {"role": "user", "content": "Now limit to delays where the actual_departure is more than 15 minutes after scheduled_departure and order by the delay duration in descending order."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, v.license_plate, t.trip_id, t.actual_departure,\n EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))/60 AS delay_minutes\nFROM transportation.trips t\nJOIN transportation.drivers d ON t.driver_id = d.driver_id\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nWHERE t.status = 'Delayed'\n AND (t.actual_departure - t.scheduled_departure) > INTERVAL '15 minutes'\nORDER BY delay_minutes DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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)\n", "conversations": [{"role": "user", "content": "Show the most recent maintenance service for each vehicle, including the vehicle's make and model."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n);"}, {"role": "user", "content": "Can you also add the mechanic's name and the maintenance cost in the result?"}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading, m.mechanic_name, m.cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n);"}, {"role": "user", "content": "Actually, only include records where the maintenance cost is above 200."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading, m.mechanic_name, m.cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n)\nAND m.cost > 200;"}, {"role": "user", "content": "Please order the result by maintenance cost in descending order."}, {"role": "assistant", "content": "SELECT m.vehicle_id, v.make, v.model, m.service_date, m.service_type, m.odometer_reading, m.mechanic_name, m.cost\nFROM transportation.maintenance_logs m\nJOIN transportation.vehicles v ON m.vehicle_id = v.vehicle_id\nWHERE m.service_date = (\n SELECT MAX(m2.service_date)\n FROM transportation.maintenance_logs m2\n WHERE m2.vehicle_id = m.vehicle_id\n)\nAND m.cost > 200\nORDER BY m.cost DESC;"}]} +{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.stations ( station_id character varying(64) NOT NULL, station_name character varying(128) NOT NULL, city character varying(100) NOT NULL, state_province character varying(100), country_code character varying(3) NOT NULL, address text, timezone character varying(64) NOT NULL, number_of_platforms integer NOT NULL DEFAULT 0, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (station_id) )\n", "conversations": [{"role": "user", "content": "What are the ticket prices for trains departing from the station with ID 'ST456'?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information on ticket prices as this data is not included in the station management database. For ticket pricing, please refer to the ticketing system or contact customer service."}]} +{"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 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": "Show me all vehicles that are due for their next service before the end of this month, along with their last service type and date."}, {"role": "assistant", "content": "SELECT vehicle_id, service_type, service_date FROM transportation.maintenance_logs WHERE next_service_due_date <= DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month' - INTERVAL '1 day';"}, {"role": "user", "content": "Can you include the mechanic who performed the last service and order by how soon the next service is due?"}, {"role": "assistant", "content": "SELECT vehicle_id, service_type, service_date, mechanic_name, next_service_due_date FROM transportation.maintenance_logs WHERE next_service_due_date <= DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month' - INTERVAL '1 day' ORDER BY next_service_due_date ASC;"}, {"role": "user", "content": "There seems to be a typo in your SQL - it should be 'INTERVAL' not 'INTERVAL'. Also, can you include the cost of the last service?"}, {"role": "assistant", "content": "SELECT vehicle_id, service_type, service_date, mechanic_name, next_service_due_date, cost FROM transportation.maintenance_logs WHERE next_service_due_date <= DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month' - INTERVAL '1 day' ORDER BY next_service_due_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\n", "conversations": [{"role": "user", "content": "List all token transfers between two distinct addresses, showing transfer_id, from_address, to_address, value, and transaction_id."}, {"role": "assistant", "content": "SELECT transfer_id, from_address, to_address, value, transaction_id\nFROM web3.token_transfers\nWHERE from_address <> to_address;"}, {"role": "user", "content": "Actually, I only want to see transfers where the value transferred is greater than 1000 tokens."}, {"role": "assistant", "content": "SELECT transfer_id, from_address, to_address, value, transaction_id\nFROM web3.token_transfers\nWHERE from_address <> to_address AND value > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n", "conversations": [{"role": "user", "content": "Provide a list of passengers including their passenger_id, first_name, last_name, phone_number, and the total number of bookings they have made. Sort the result by booking count in descending order."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n p.phone_number,\n COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name,\n p.phone_number\nORDER BY booking_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.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.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 web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n", "conversations": [{"role": "user", "content": "Show all token transfers including the token symbol and the address of the contract that created each token. List the transfer id, token id, value, transaction id, the contract address, and the token symbol."}, {"role": "assistant", "content": "SELECT tt.transfer_id, tt.token_id, tt.value, tt.transaction_id, t.contract_id AS contract_address, t.token_symbol\nFROM web3.token_transfers tt\nJOIN web3.tokens t ON tt.token_id = t.token_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(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) )\nCREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )\n", "conversations": [{"role": "user", "content": "Show the average close price and total volume for market data, grouped by source."}, {"role": "assistant", "content": "SELECT source, AVG(close_price), SUM(volume) FROM financial_services.market_data GROUP BY source;"}, {"role": "user", "content": "Only include data points with volume greater than 100000 and exclude sources where the total volume is less than 10000000."}]} +{"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 healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "I want to see pairs of medications that share the same manufacturer. Show each medication's name and its peer's medication_name along with the manufacturer."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer;"}, {"role": "user", "content": "Exclude any rows where a medication is paired with itself."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer AND t1.medication_id <> t2.medication_id;"}, {"role": "user", "content": "Now only include manufacturers 'Pfizer' or 'Moderna'."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer AND t1.medication_id <> t2.medication_id WHERE t1.manufacturer IN ('Pfizer','Moderna');"}, {"role": "user", "content": "I’m seeing duplicate pairs for reversed order. Remove reversed duplicates."}, {"role": "assistant", "content": "SELECT t1.medication_name AS med1_name, t2.medication_name AS med2_name, t1.manufacturer FROM healthcare.medications t1 JOIN healthcare.medications t2 ON t1.manufacturer = t2.manufacturer AND t1.medication_id < t2.medication_id WHERE t1.manufacturer IN ('Pfizer','Moderna');"}]} +{"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 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.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each vehicle that appears in both the maintenance logs and fuel logs tables, calculate the total maintenance cost and the total fuel cost. Display the vehicle ID and these two total costs."}, {"role": "assistant", "content": "SELECT T1.vehicle_id , SUM(T1.cost) AS total_maintenance_cost , SUM(T2.total_cost) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.vehicle_id"}, {"role": "user", "content": "Now, only include vehicles where the total maintenance cost exceeds 5000."}, {"role": "assistant", "content": "SELECT T1.vehicle_id , SUM(T1.cost) AS total_maintenance_cost , SUM(T2.total_cost) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.vehicle_id HAVING SUM(T1.cost) > 5000"}, {"role": "user", "content": "Also, only consider fuel log entries from the year 2023 for the fuel cost calculation."}, {"role": "assistant", "content": "SELECT T1.vehicle_id , SUM(T1.cost) AS total_maintenance_cost , SUM(CASE WHEN STRFTIME('%Y', T2.log_timestamp) = '2023' THEN T2.total_cost ELSE 0 END) AS total_fuel_cost FROM transportation.maintenance_logs AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.vehicle_id HAVING SUM(T1.cost) > 5000"}]} +{"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 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.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\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": "Show the game title and the count of hidden achievements for each game."}, {"role": "assistant", "content": "SELECT T1.title , COUNT(T2.achievement_id) FROM games AS T1 JOIN achievements AS T2 ON T1.game_id = T2.game_id WHERE T2.hidden = TRUE GROUP BY T1.title"}, {"role": "user", "content": "Filter the results to only include games that have at least one hidden achievement."}, {"role": "assistant", "content": "SELECT T1.title , COUNT(T2.achievement_id) FROM games AS T1 JOIN achievements AS T2 ON T1.game_id = T2.game_id WHERE T2.hidden = TRUE GROUP BY T1.title HAVING COUNT(T2.achievement_id) >= 1"}, {"role": "user", "content": "Order the results by the count of hidden achievements descending."}, {"role": "assistant", "content": "SELECT T1.title , COUNT(T2.achievement_id) FROM games AS T1 JOIN achievements AS T2 ON T1.game_id = T2.game_id WHERE T2.hidden = TRUE GROUP BY T1.title HAVING COUNT(T2.achievement_id) >= 1 ORDER BY COUNT(T2.achievement_id) DESC"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n", "conversations": [{"role": "user", "content": "List the names of all open cases, the name of the client for each case, and the name of the lead lawyer, but only for cases where the lead lawyer specializes in 'Family Law'."}, {"role": "assistant", "content": "SELECT T1.case_name , T2.first_name , T2.last_name , T3.first_name , T3.last_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id JOIN legal_services.lawyers AS T3 ON T1.lead_lawyer_id = T3.lawyer_id WHERE T1.status = 'Open' AND T3.specialization = 'Family Law'"}, {"role": "user", "content": "Actually, could you change the specialization filter to 'Criminal Law' and include the case number? Also, please sort the results by the client's last name."}, {"role": "assistant", "content": "SELECT T1.case_number , T1.case_name , T2.first_name , T2.last_name , T3.first_name , T3.last_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id JOIN legal_services.lawyers AS T3 ON T1.lead_lawyer_id = T3.lawyer_id WHERE T1.status = 'Open' AND T3.specialization = 'Criminal Law' ORDER BY T2.last_name"}, {"role": "user", "content": "Okay, now just show the cases that were opened after '2023-07-01'."}, {"role": "assistant", "content": "SELECT T1.case_number , T1.case_name , T2.first_name , T2.last_name , T3.first_name , T3.last_name FROM legal_services.cases AS T1 JOIN legal_services.clients AS T2 ON T1.client_id = T2.client_id JOIN legal_services.lawyers AS T3 ON T1.lead_lawyer_id = T3.lawyer_id WHERE T1.status = 'Open' AND T3.specialization = 'Criminal Law' AND T1.date_opened > '2023-07-01' ORDER BY T2.last_name"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n", "conversations": [{"role": "user", "content": "Which two tokens on each chain have the greatest difference in their 24h price change percentage? Show token_symbol A, token_symbol B, chain, and the absolute difference."}, {"role": "assistant", "content": "SELECT DISTINCT ON (t1.chain)\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h\nFROM token_dexpool_info t1\nJOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\nORDER BY t1.chain, diff_24h DESC;"}, {"role": "user", "content": "Actually, I want only the chains where this top difference is at least 15% and show the top 2 pairs per chain."}, {"role": "assistant", "content": "SELECT symbol_a, symbol_b, chain, diff_24h\nFROM (\n SELECT\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h,\n ROW_NUMBER() OVER(\n PARTITION BY t1.chain\n ORDER BY ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) DESC\n ) AS rn\n FROM token_dexpool_info t1\n JOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\n WHERE ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) >= 15\n) sub\nWHERE rn <= 2\nORDER BY chain, diff_24h DESC;"}, {"role": "user", "content": "Also sort the overall result by diff_24h descending and limit to the top 5 records."}, {"role": "assistant", "content": "SELECT *\nFROM (\n SELECT symbol_a, symbol_b, chain, diff_24h\n FROM (\n SELECT\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h,\n ROW_NUMBER() OVER(\n PARTITION BY t1.chain\n ORDER BY ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) DESC\n ) AS rn\n FROM token_dexpool_info t1\n JOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\n WHERE ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) >= 15\n ) sub1\n WHERE rn <= 2\n) sub2\nORDER BY diff_24h DESC\nLIMIT 5;"}, {"role": "user", "content": "Could you include the current price of both tokens in the output as well?"}, {"role": "assistant", "content": "SELECT symbol_a, symbol_b, chain, price_a, price_b, diff_24h\nFROM (\n SELECT\n t1.token_symbol AS symbol_a,\n t2.token_symbol AS symbol_b,\n t1.chain,\n t1.price AS price_a,\n t2.price AS price_b,\n ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) AS diff_24h,\n ROW_NUMBER() OVER(\n PARTITION BY t1.chain\n ORDER BY ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) DESC\n ) AS rn\n FROM token_dexpool_info t1\n JOIN token_dexpool_info t2\n ON t1.chain = t2.chain\n AND t1.token_symbol < t2.token_symbol\n WHERE ABS(t1.price_change_percentage_24h - t2.price_change_percentage_24h) >= 15\n) sub\nWHERE rn <= 2\nORDER BY diff_24h DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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)\n", "conversations": [{"role": "user", "content": "Can you show me all pairs of trips that use the same vehicle but have different drivers? Please include both trip IDs, vehicle_id, and the driver_id for each trip."}, {"role": "assistant", "content": "SELECT t1.trip_id AS trip_id_1, t2.trip_id AS trip_id_2, t1.vehicle_id, t1.driver_id AS driver_id_1, t2.driver_id AS driver_id_2\nFROM transportation.trips t1\nJOIN transportation.trips t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id\n AND t1.driver_id <> t2.driver_id;"}, {"role": "user", "content": "Actually, I also want to see only those pairs where both trips have a status of 'Completed'."}, {"role": "assistant", "content": "SELECT t1.trip_id AS trip_id_1, t2.trip_id AS trip_id_2, t1.vehicle_id, t1.driver_id AS driver_id_1, t2.driver_id AS driver_id_2\nFROM transportation.trips t1\nJOIN transportation.trips t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id\n AND t1.driver_id <> t2.driver_id\nWHERE t1.status = 'Completed' AND t2.status = 'Completed';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.nodes (\n node_id character varying(64) NOT NULL, -- unique identifier for the node\n ip_address character varying(15) NOT NULL, -- IP address of the node\n port integer NOT NULL, -- port number of the node\n last_seen timestamp NOT NULL, -- last time the node was active\n PRIMARY KEY (node_id)\n)\nCREATE TABLE blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )\nCREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE blockchain.smart_contracts ( contract_id character varying(64) NOT NULL, creator_address character varying(128) NOT NULL, code text NOT NULL, timestamp timestamp NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "Retrieve all users and their associated wallet identifiers."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id"}, {"role": "user", "content": "Only show users whose username starts with 'J'."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%'"}, {"role": "user", "content": "Further filter to only include wallets where the address_id contains 'abc'."}, {"role": "assistant", "content": "SELECT T1.username , T2.wallet_id FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%' AND T2.address_id LIKE '%abc%'"}, {"role": "user", "content": "For the filtered users and wallets, count how many wallets each user has."}, {"role": "assistant", "content": "SELECT T1.username , COUNT(T2.wallet_id) FROM blockchain.users AS T1 JOIN blockchain.wallets AS T2 ON T1.user_id = T2.user_id WHERE T1.username LIKE 'J%' AND T2.address_id LIKE '%abc%' GROUP BY T1.username"}]} +{"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 web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\n", "conversations": [{"role": "user", "content": "List all pairs of token transfers occurring within the same transaction where one transferred value is greater than the other, showing both transfer IDs, the transaction ID, and both values."}, {"role": "assistant", "content": "SELECT t1.transaction_id,\n t1.transfer_id AS transfer_id_1,\n t2.transfer_id AS transfer_id_2,\n t1.value AS value_1,\n t2.value AS value_2\nFROM web3.token_transfers t1\nJOIN web3.token_transfers t2\n ON t1.transaction_id = t2.transaction_id\n AND t1.value > t2.value;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\n", "conversations": [{"role": "user", "content": "List group conversation names and the count of messages sent in each conversation after '2024-06-01'."}, {"role": "assistant", "content": "SELECT T1.group_name, COUNT(T2.message_id) FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE AND T2.sent_at > '2024-06-01' GROUP BY T1.conversation_id, T1.group_name;"}, {"role": "user", "content": "Only show conversations that have more than 5 messages sent after that date."}, {"role": "assistant", "content": "SELECT T1.group_name, COUNT(T2.message_id) FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE AND T2.sent_at > '2024-06-01' GROUP BY T1.conversation_id, T1.group_name HAVING COUNT(T2.message_id) > 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id.text, user_id.text, wallet_id.text, asset_id.text, order_type.text, quantity.numeric, price.numeric, status.text, created_at.timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n", "conversations": [{"role": "user", "content": "For each user, show their user_id, KYC status, and the total count of completed orders they've placed."}, {"role": "assistant", "content": "SELECT k.user_id, k.status, COUNT(o.order_id) AS completed_order_count\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nGROUP BY k.user_id, k.status;"}, {"role": "user", "content": "Only include users whose KYC status is 'approved'."}, {"role": "assistant", "content": "SELECT k.user_id, k.status, COUNT(o.order_id) AS completed_order_count\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nWHERE k.status = 'approved'\nGROUP BY k.user_id, k.status;"}, {"role": "user", "content": "Also calculate the total value of these completed orders as total_value."}, {"role": "assistant", "content": "SELECT k.user_id,\n k.status,\n COUNT(o.order_id) AS completed_order_count,\n SUM(o.quantity * o.price) AS total_value\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nWHERE k.status = 'approved'\nGROUP BY k.user_id, k.status;"}, {"role": "user", "content": "Finally, order the results by total_value descending and limit to 5."}, {"role": "assistant", "content": "SELECT k.user_id,\n k.status,\n COUNT(o.order_id) AS completed_order_count,\n SUM(o.quantity * o.price) AS total_value\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.orders o\n ON k.user_id = o.user_id\n AND o.status = 'completed'\nWHERE k.status = 'approved'\nGROUP BY k.user_id, k.status\nORDER BY total_value DESC\nLIMIT 5;"}]} -{"system": "You are an 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 insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )\nCREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE insurance.agents ( agent_id.text, first_name.text, last_name.text, agency_name.text, license_number.text, license_state.text, contact_email.text, contact_phone.text, hire_date.date, termination_date.date, status.text, commission_rate.numeric, manager_id.text )\nCREATE TABLE insurance.premium_payments ( payment_id.text, policy_id.text, customer_id.text, payment_date.timestamp, amount_paid.numeric, payment_method.text, transaction_reference.text, due_date.date, payment_period_start.date, payment_period_end.date, status.text )\nCREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )\n", "conversations": [{"role": "user", "content": "Show all claim documents uploaded in 2024 with their document_id, file_name, uploaded_at, and the claim_id."}, {"role": "assistant", "content": "SELECT document_id, file_name, uploaded_at, claim_id\nFROM insurance.claim_documents\nWHERE uploaded_at >= '2024-01-01' AND uploaded_at < '2025-01-01'"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.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.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\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 the medication name and manufacturer of all medications where the description contains the word 'extended'."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer\nFROM healthcare.medications\nWHERE description ILIKE '%extended%';"}, {"role": "user", "content": "Only include medications where the ndc_code is not null and has more than 8 characters."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer\nFROM healthcare.medications\nWHERE description ILIKE '%extended%'\n AND ndc_code IS NOT NULL\n AND length(ndc_code) > 8;"}]} -{"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 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 cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\nCREATE TABLE smart_money_profit ( address.text, rank.numeric, profit.numeric, roi.numeric, realized_ratio.numeric, most_profit_token.text, last_trade_time.text, chain.text )\nCREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n", "conversations": [{"role": "user", "content": "For each narrative, which token has the lowest price in the last 24 hours based on DEX pool data? Show narrative, token symbol, chain, and the lowest 24h price."}, {"role": "assistant", "content": "SELECT t.narrative, d.token_symbol, d.chain, d.lowest_price_24h\nFROM token_basic_info t\nJOIN token_dexpool_info d ON t.token_symbol = d.token_symbol AND t.chain = d.chain\nJOIN (\n SELECT narrative, MIN(lowest_price_24h) AS min_price\n FROM token_basic_info b\n JOIN token_dexpool_info dd ON b.token_symbol = dd.token_symbol AND b.chain = dd.chain\n GROUP BY narrative\n) m ON t.narrative = m.narrative AND d.lowest_price_24h = m.min_price"}, {"role": "user", "content": "I just want to see results for narratives with at least 2 tokens in them. Could you adjust the query?"}, {"role": "assistant", "content": "WITH narrative_token_counts AS (\n SELECT narrative, COUNT(*) AS token_count\n FROM token_basic_info\n GROUP BY narrative\n), \nlowest_tokens AS (\n SELECT t.narrative, d.token_symbol, d.chain, d.lowest_price_24h\n FROM token_basic_info t\n JOIN token_dexpool_info d ON t.token_symbol = d.token_symbol AND t.chain = d.chain\n JOIN (\n SELECT narrative, MIN(lowest_price_24h) AS min_price\n FROM token_basic_info b\n JOIN token_dexpool_info dd ON b.token_symbol = dd.token_symbol AND b.chain = dd.chain\n GROUP BY narrative\n ) m ON t.narrative = m.narrative AND d.lowest_price_24h = m.min_price\n)\nSELECT l.narrative, l.token_symbol, l.chain, l.lowest_price_24h\nFROM lowest_tokens l\nJOIN narrative_token_counts ntc ON l.narrative = ntc.narrative\nWHERE ntc.token_count >= 2"}, {"role": "user", "content": "Also display the current price of each token from DEX pool data."}, {"role": "assistant", "content": "WITH narrative_token_counts AS (\n SELECT narrative, COUNT(*) AS token_count\n FROM token_basic_info\n GROUP BY narrative\n), \nlowest_tokens AS (\n SELECT t.narrative, d.token_symbol, d.chain, d.lowest_price_24h, d.price\n FROM token_basic_info t\n JOIN token_dexpool_info d ON t.token_symbol = d.token_symbol AND t.chain = d.chain\n JOIN (\n SELECT narrative, MIN(lowest_price_24h) AS min_price\n FROM token_basic_info b\n JOIN token_dexpool_info dd ON b.token_symbol = dd.token_symbol AND b.chain = dd.chain\n GROUP BY narrative\n ) m ON t.narrative = m.narrative AND d.lowest_price_24h = m.min_price\n)\nSELECT l.narrative, l.token_symbol, l.chain, l.lowest_price_24h, l.price\nFROM lowest_tokens l\nJOIN narrative_token_counts ntc ON l.narrative = ntc.narrative\nWHERE ntc.token_count >= 2"}, {"role": "user", "content": "Sort the results by lowest 24h price ascending and only show the top 5."}, {"role": "assistant", "content": "WITH narrative_token_counts AS (\n SELECT narrative, COUNT(*) AS token_count\n FROM token_basic_info\n GROUP BY narrative\n), \nlowest_tokens AS (\n SELECT t.narrative, d.token_symbol, d.chain, d.lowest_price_24h, d.price\n FROM token_basic_info t\n JOIN token_dexpool_info d ON t.token_symbol = d.token_symbol AND t.chain = d.chain\n JOIN (\n SELECT narrative, MIN(lowest_price_24h) AS min_price\n FROM token_basic_info b\n JOIN token_dexpool_info dd ON b.token_symbol = dd.token_symbol AND b.chain = dd.chain\n GROUP BY narrative\n ) m ON t.narrative = m.narrative AND d.lowest_price_24h = m.min_price\n)\nSELECT l.narrative, l.token_symbol, l.chain, l.lowest_price_24h, l.price\nFROM lowest_tokens l\nJOIN narrative_token_counts ntc ON l.narrative = ntc.narrative\nWHERE ntc.token_count >= 2\nORDER BY l.lowest_price_24h ASC\nLIMIT 5"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n", "conversations": [{"role": "user", "content": "List all contracts with status 'active' and include their deployment timestamp and network ID."}, {"role": "assistant", "content": "SELECT address, deployed_at, network_id FROM web3.contracts WHERE status = 'active';"}, {"role": "user", "content": "Actually, I need to see only contracts deployed in the last 30 days."}, {"role": "assistant", "content": "SELECT address, deployed_at, network_id FROM web3.contracts WHERE status = 'active' AND deployed_at >= NOW() - INTERVAL '30 days';"}, {"role": "user", "content": "There's a typo in your SQL, it should be 'deployed_at' not 'deployed_at'. Also, sort the results by deployed_at in descending order."}, {"role": "assistant", "content": "SELECT address, deployed_at, network_id FROM web3.contracts WHERE status = 'active' AND deployed_at >= NOW() - INTERVAL '30 days' ORDER BY deployed_at DESC;"}, {"role": "user", "content": "Now filter to only show contracts on the 'polygon' network."}, {"role": "assistant", "content": "SELECT address, deployed_at, network_id FROM web3.contracts WHERE status = 'active' AND deployed_at >= NOW() - INTERVAL '30 days' AND network_id = 'polygon' ORDER BY deployed_at DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id character varying(64) NOT NULL, employee_id character varying(64) NOT NULL UNIQUE, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, license_number character varying(64) NOT NULL UNIQUE, license_expiry_date date NOT NULL, contact_number character varying(32), email character varying(128) UNIQUE, hire_date date NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (driver_id) )\nCREATE TABLE transportation.routes ( route_id character varying(64) NOT NULL, route_number character varying(32) NOT NULL UNIQUE, description text, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, distance_km numeric(10, 2), estimated_duration_minutes integer, type character varying(32) NOT NULL, PRIMARY KEY (route_id) )\nCREATE TABLE transportation.locations ( location_id character varying(64) NOT NULL, name character varying(255) NOT NULL, type character varying(64) NOT NULL, address_line1 character varying(255), city character varying(128), state_province character varying(128), postal_code character varying(32), country character varying(64) NOT NULL, latitude numeric(9, 6), longitude numeric(9, 6), timezone character varying(64), PRIMARY KEY (location_id) )\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\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": "For each booking, show the booking_id, seat_number, fare, and the city of the origin location for the trip that was booked."}, {"role": "assistant", "content": "SELECT b.booking_id, b.seat_number, b.fare, orig.city AS origin_city\nFROM transportation.bookings b\nJOIN transportation.trips t ON b.trip_id = t.trip_id\nJOIN transportation.routes r ON t.route_id = r.route_id\nJOIN transportation.locations orig ON r.origin_location_id = orig.location_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Show me the appointment ID, start time, and subject for all appointments scheduled with lawyer 'lawyer123'."}, {"role": "assistant", "content": "SELECT appointment_id, start_time, subject FROM legal_services.appointments WHERE lawyer_id = 'lawyer123';"}, {"role": "user", "content": "Only include those appointments where the status is 'Scheduled'."}, {"role": "assistant", "content": "SELECT appointment_id, start_time, subject FROM legal_services.appointments WHERE lawyer_id = 'lawyer123' AND status = 'Scheduled';"}, {"role": "user", "content": "Further filter to only show appointments starting after '2024-07-01'."}, {"role": "assistant", "content": "SELECT appointment_id, start_time, subject FROM legal_services.appointments WHERE lawyer_id = 'lawyer123' AND status = 'Scheduled' AND start_time > '2024-07-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n \"CREATE TABLE project_fundraising_record (\",\n \"id character varying(32) NOT NULL, -- fundraising record id\",\n \"project_id character varying(32) NOT NULL, -- the invested project's id\",\n \"project_name character varying(128) NOT NULL, -- name of the invested project\",\n \"rounds_name character varying(32), -- name of the fundraising round\",\n \"investment_value numeric(38,14), -- amount of the fundraising in USD\",\n \"investment_date character varying(128), -- the date of the investment happened\",\n \"introduction character varying(128), -- the introduction of the invested project\",\n \"valuation numeric(38,14), -- the valuation of the project in USD when invested\",\n\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n", "conversations": [{"role": "user", "content": "Show me the top 5 projects by valuation that completed fundraising rounds in the last 12 months, along with their token symbol and price from the token_basic_info table."}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= date_trunc('month', CURRENT_DATE - INTERVAL '12 months') ORDER BY pfr.valuation DESC LIMIT 5;"}, {"role": "user", "content": "Can you also include the 24-hour trading volume for these projects' tokens and filter to only include projects with valuation over $100 million?"}, {"role": "assistant", "content": "SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price, tbi.total_volume FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= date_trunc('month', CURRENT_DATE - INTERVAL '12 months') AND pfr.valuation > 100000000 ORDER BY pfr.valuation DESC LIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "List all pairs of vehicles in the same depot with different status. Include both vehicle IDs with their statuses and the depot_id."}, {"role": "assistant", "content": "SELECT v1.vehicle_id AS vehicle1_id,\n v1.status AS status1,\n v2.vehicle_id AS vehicle2_id,\n v2.status AS status2,\n v1.depot_id\nFROM transportation.vehicles v1\nJOIN transportation.vehicles v2\n ON v1.depot_id = v2.depot_id\n AND v1.vehicle_id < v2.vehicle_id\n AND v1.status <> v2.status;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_basic_info ( coin_id.text, token_name.text, token_symbol.text, token_address.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, highest_price_24h.numeric, lowest_price_24h.numeric, market_cap.numeric, market_cap_rank.numeric, market_cap_change_percentage_24h.text, total_volume.text, narrative.text, trend_rank.numeric )\n", "conversations": [{"role": "user", "content": "List the top 5 tokens by price_change_percentage_7d, showing token_symbol, narrative, and price_change_percentage_7d."}, {"role": "assistant", "content": "SELECT token_symbol, narrative, price_change_percentage_7d\nFROM token_basic_info\nORDER BY price_change_percentage_7d DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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 patients who have insurance plans with group numbers, showing their patient IDs and the count of such plans per patient."}, {"role": "assistant", "content": "SELECT patient_id, COUNT(*) AS plan_count FROM healthcare.patient_insurance WHERE group_number IS NOT NULL GROUP BY patient_id;"}, {"role": "user", "content": "Actually, I only need patients who have more than 2 such plans."}, {"role": "assistant", "content": "SELECT patient_id, COUNT(*) AS plan_count FROM healthcare.patient_insurance WHERE group_number IS NOT NULL GROUP BY patient_id HAVING COUNT(*) > 2;"}, {"role": "user", "content": "Can you also include the earliest effective date among these plans for each patient?"}, {"role": "assistant", "content": "SELECT patient_id, COUNT(*) AS plan_count, MIN(effective_date) AS earliest_effective_date FROM healthcare.patient_insurance WHERE group_number IS NOT NULL GROUP BY patient_id HAVING COUNT(*) > 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )\n", "conversations": [{"role": "user", "content": "Which agents, along with their managers' full names, are licensed in 'TX' and are currently active?"}, {"role": "assistant", "content": "SELECT a.agent_id, a.first_name AS agent_first_name, a.last_name AS agent_last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name\nFROM insurance.agents a\nLEFT JOIN insurance.agents m ON a.manager_id = m.agent_id\nWHERE a.license_state = 'TX' AND a.status = 'Active';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.loans (\n loan_id character varying(64) NOT NULL, -- unique identifier for the loan, could be same as account_id\n account_id character varying(64) NOT NULL UNIQUE, -- link to the general account record\n loan_type character varying(50) NOT NULL, -- e.g., Mortgage, Personal, Auto, Student\n principal_amount numeric(19, 4) NOT NULL, -- original loan amount\n current_principal_balance numeric(19, 4) NOT NULL, -- remaining principal\n interest_rate numeric(6, 4) NOT NULL, -- annual interest rate\n term_months integer NOT NULL, -- loan term in months\n origination_date date NOT NULL, -- date the loan was disbursed\n maturity_date date NOT NULL, -- date the loan is due to be fully repaid\n monthly_payment numeric(12, 4), -- scheduled monthly payment amount\n collateral_description text, -- description of collateral, if secured loan\n status character varying(32) NOT NULL, -- e.g., Active, Paid Off, Defaulted\n PRIMARY KEY (loan_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id)\n)\n", "conversations": [{"role": "user", "content": "Retrieve all pairs of loans for the same account where both loans are active and have different loan types. Show account_id, loan_id as loan_a, loan_type as type_a, loan_id as loan_b, and loan_type as type_b."}, {"role": "assistant", "content": "SELECT a.account_id,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type;"}, {"role": "user", "content": "Actually, only include pairs where loan_a has a higher principal_amount than loan_b."}, {"role": "assistant", "content": "SELECT a.account_id,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type\n AND a.principal_amount > b.principal_amount;"}, {"role": "user", "content": "Now restrict to accounts where the total number of active loans is at least 3."}, {"role": "assistant", "content": "SELECT a.account_id,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type\n AND a.principal_amount > b.principal_amount\n AND a.account_id IN (\n SELECT account_id\n FROM financial_services.loans\n WHERE status = 'Active'\n GROUP BY account_id\n HAVING COUNT(*) >= 3\n );"}, {"role": "user", "content": "Finally, also include the number of active loans for each account as loan_count."}, {"role": "assistant", "content": "WITH active_counts AS (\n SELECT account_id,\n COUNT(*) AS loan_count\n FROM financial_services.loans\n WHERE status = 'Active'\n GROUP BY account_id\n)\nSELECT a.account_id,\n ac.loan_count,\n a.loan_id AS loan_a,\n a.loan_type AS type_a,\n b.loan_id AS loan_b,\n b.loan_type AS type_b\nFROM financial_services.loans a\nJOIN financial_services.loans b\n ON a.account_id = b.account_id\n AND a.loan_id < b.loan_id\nJOIN active_counts ac\n ON a.account_id = ac.account_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\n AND a.loan_type <> b.loan_type\n AND a.principal_amount > b.principal_amount\n AND ac.loan_count >= 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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.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 each patient and the number of different insurance plans they have had. Include patient_id and plan_count."}, {"role": "assistant", "content": "SELECT patient_id, COUNT(DISTINCT plan_id) AS plan_count\nFROM healthcare.patient_insurance\nGROUP BY patient_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 fuel log IDs along with their vehicle IDs and odometer readings for logs where the quantity is below 10."}, {"role": "assistant", "content": "SELECT fuel_log_id, vehicle_id, odometer_reading\nFROM transportation.fuel_logs\nWHERE quantity < 10;"}, {"role": "user", "content": "I received a lot of results. Please show only those logs where the unit is 'gallon'."}, {"role": "assistant", "content": "SELECT fuel_log_id, vehicle_id, odometer_reading\nFROM transportation.fuel_logs\nWHERE quantity < 10 AND unit = 'gallon';"}, {"role": "user", "content": "Now, could you also display the cost_per_unit for each of these logs and sort the output by cost_per_unit in ascending order?"}, {"role": "assistant", "content": "SELECT fuel_log_id, vehicle_id, odometer_reading, cost_per_unit\nFROM transportation.fuel_logs\nWHERE quantity < 10 AND unit = 'gallon'\nORDER BY cost_per_unit ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id text, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.tokens ( token_id text, contract_address text, token_name text, token_symbol text, decimals integer, total_supply numeric )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all contracts and the number of different tokens associated with each contract address. Show contract_id, contract address, and token_count."}, {"role": "assistant", "content": "SELECT c.contract_id, c.address, COUNT(DISTINCT t.token_id) AS token_count\nFROM web3.contracts c\nLEFT JOIN web3.tokens t ON c.address = t.contract_address\nGROUP BY c.contract_id, c.address;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.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.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.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n", "conversations": [{"role": "user", "content": "Show me the first and last names of all customers and the agency name of the agent who sold their policy."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, a.agency_name\nFROM insurance.policies p\nJOIN insurance.customers c ON p.customer_id = c.customer_id\nLEFT JOIN insurance.agents a ON p.agent_id = a.agent_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\n", "conversations": [{"role": "user", "content": "Show me all documents along with the document name and type, together with both the upload_timestamp and the lawyer ID who uploaded them."}, {"role": "assistant", "content": "SELECT document_id, document_name, document_type, upload_timestamp, uploaded_by_lawyer_id FROM legal_services.documents;"}, {"role": "user", "content": "Can you filter the list to only include documents uploaded after March 1st, 2024?"}, {"role": "assistant", "content": "SELECT document_id, document_name, document_type, upload_timestamp, uploaded_by_lawyer_id FROM legal_services.documents WHERE upload_timestamp > '2024-03-01';"}, {"role": "user", "content": "Additionally, show only those documents where the document_type contains the word 'Report'."}, {"role": "assistant", "content": "SELECT document_id, document_name, document_type, upload_timestamp, uploaded_by_lawyer_id FROM legal_services.documents WHERE upload_timestamp > '2024-03-01' AND document_type ILIKE '%Report%';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\n", "conversations": [{"role": "user", "content": "Retrieve the first and last names and email addresses of all customers who registered after '2024-01-01'."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM insurance.customers WHERE created_at > '2024-01-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n", "conversations": [{"role": "user", "content": "List the names and contact phone numbers of all insurance plans whose website is not null."}, {"role": "assistant", "content": "SELECT plan_name, contact_phone\nFROM healthcare.insurance_plans\nWHERE website IS NOT NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\n", "conversations": [{"role": "user", "content": "Show all policies that started in 2024, including the policy_id, customer_id, and start_date. Order the results by start_date ascending."}, {"role": "assistant", "content": "SELECT policy_id, customer_id, start_date\nFROM insurance.policies\nWHERE start_date >= '2024-01-01' AND start_date < '2025-01-01'\nORDER BY start_date ASC;"}, {"role": "user", "content": "Also, include the status of each policy and only show those with premium_amount over 3000."}, {"role": "assistant", "content": "SELECT policy_id, customer_id, start_date, status\nFROM insurance.policies\nWHERE start_date >= '2024-01-01' AND start_date < '2025-01-01'\n AND premium_amount > 3000\nORDER BY start_date ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 )\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": "List the first name and last name of all policy beneficiaries, along with the name of the insurance product associated with their policy."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.product_name FROM insurance.policy_beneficiaries AS T1 JOIN insurance.insurance_products AS T2 ON T1.policy_id = T2.product_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n", "conversations": [{"role": "user", "content": "How many users have email_notifications_enabled set to false and private_profile set to true? Return the count."}, {"role": "assistant", "content": "SELECT COUNT(*) AS user_count\nFROM social_media.user_settings\nWHERE email_notifications_enabled = false\n AND private_profile = true;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE narrative_info ( narrative.text, top_3_coins.text, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, market_cap.numeric, volume_24h.numeric, trend_rank.numeric, token_num.numeric )\n", "conversations": [{"role": "user", "content": "List the top 10 narratives based on their market cap. Display the narrative name, market_cap, and token_num."}, {"role": "assistant", "content": "SELECT narrative, market_cap, token_num FROM narrative_info ORDER BY market_cap DESC LIMIT 10"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.in_game_items ( item_id.uuid, game_id.uuid, item_name.text, item_type.text, description.text, rarity.text, cost_currency.text, cost_amount.numeric, attributes.jsonb )\n", "conversations": [{"role": "user", "content": "List all items with rarity = 'Legendary', showing item_id, item_name, and cost_amount."}, {"role": "assistant", "content": "SELECT item_id,\n item_name,\n cost_amount\nFROM gaming_technology.in_game_items\nWHERE rarity = 'Legendary';"}, {"role": "user", "content": "Now find games where the average cost_amount of those legendary items exceeds 1000. Return game_id and the average cost."}, {"role": "assistant", "content": "SELECT game_id,\n AVG(cost_amount) AS avg_legendary_cost\nFROM gaming_technology.in_game_items\nWHERE rarity = 'Legendary'\nGROUP BY game_id\nHAVING AVG(cost_amount) > 1000;"}, {"role": "user", "content": "Show all the legendary items in those games alongside the computed average cost."}, {"role": "assistant", "content": "WITH high_avg AS (\n SELECT game_id,\n AVG(cost_amount) AS avg_cost\n FROM gaming_technology.in_game_items\n WHERE rarity = 'Legendary'\n GROUP BY game_id\n HAVING AVG(cost_amount) > 1000\n)\nSELECT i.game_id,\n i.item_id,\n i.item_name,\n i.cost_amount,\n h.avg_cost\nFROM gaming_technology.in_game_items i\nJOIN high_avg h\n ON i.game_id = h.game_id\nWHERE i.rarity = 'Legendary';"}, {"role": "user", "content": "Order the results by avg_cost descending and then by cost_amount ascending."}, {"role": "assistant", "content": "WITH high_avg AS (\n SELECT game_id,\n AVG(cost_amount) AS avg_cost\n FROM gaming_technology.in_game_items\n WHERE rarity = 'Legendary'\n GROUP BY game_id\n HAVING AVG(cost_amount) > 1000\n)\nSELECT i.game_id,\n i.item_id,\n i.item_name,\n i.cost_amount,\n h.avg_cost\nFROM gaming_technology.in_game_items i\nJOIN high_avg h\n ON i.game_id = h.game_id\nWHERE i.rarity = 'Legendary'\nORDER BY h.avg_cost DESC,\n i.cost_amount ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 character varying(64) NOT NULL, employee_id character varying(64) NOT NULL UNIQUE, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, license_number character varying(64) NOT NULL UNIQUE, license_expiry_date date NOT NULL, contact_number character varying(32), email character varying(128) UNIQUE, hire_date date NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (driver_id) )\nCREATE TABLE transportation.routes ( route_id.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 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.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": "I need a list of all routes and the number of trips made on each route."}, {"role": "assistant", "content": "SELECT route_id, COUNT(*) AS trip_count\nFROM transportation.trips\nGROUP BY route_id;"}, {"role": "user", "content": "Actually, show the route_number and description instead of route_id."}, {"role": "assistant", "content": "SELECT r.route_number,\n r.description,\n COUNT(t.trip_id) AS trip_count\nFROM transportation.trips t\nJOIN transportation.routes r ON t.route_id = r.route_id\nGROUP BY r.route_number, r.description;"}, {"role": "user", "content": "Also, only include routes with more than 20 trips and sort by trip_count descending."}, {"role": "assistant", "content": "SELECT r.route_number,\n r.description,\n COUNT(t.trip_id) AS trip_count\nFROM transportation.trips t\nJOIN transportation.routes r ON t.route_id = r.route_id\nGROUP BY r.route_number, r.description\nHAVING COUNT(t.trip_id) > 20\nORDER BY trip_count DESC;"}, {"role": "user", "content": "Finally, display the average passenger count per trip for each of these routes."}, {"role": "assistant", "content": "SELECT r.route_number,\n r.description,\n COUNT(t.trip_id) AS trip_count,\n AVG(t.passenger_count) AS avg_passengers\nFROM transportation.trips t\nJOIN transportation.routes r ON t.route_id = r.route_id\nGROUP BY r.route_number, r.description\nHAVING COUNT(t.trip_id) > 20\nORDER BY trip_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\n", "conversations": [{"role": "user", "content": "I need to retrieve asset IDs along with their category and website metadata values for assets that have both entries."}, {"role": "assistant", "content": "SELECT m_cat.asset_id,\n m_cat.value AS category,\n m_web.value AS website_url\nFROM trading_platform.metadata m_cat\nJOIN trading_platform.metadata m_web\n ON m_cat.asset_id = m_web.asset_id\nWHERE m_cat.key = 'category'\n AND m_web.key = 'website';"}, {"role": "user", "content": "Actually, filter to include only those assets where the category value is 'defi'."}, {"role": "assistant", "content": "SELECT m_cat.asset_id,\n m_cat.value AS category,\n m_web.value AS website_url\nFROM trading_platform.metadata m_cat\nJOIN trading_platform.metadata m_web\n ON m_cat.asset_id = m_web.asset_id\nWHERE m_cat.key = 'category'\n AND m_web.key = 'website'\n AND m_cat.value = 'defi';"}]} -{"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 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": "Could you list all pairs of active accounts for the same customer, showing customer_id, account_a, and account_b?"}, {"role": "assistant", "content": "SELECT a.customer_id, a.account_number AS account_a, b.account_number AS account_b FROM financial_services.accounts a JOIN financial_services.accounts b ON a.customer_id = b.customer_id AND a.account_id < b.account_id WHERE a.status = 'Active' AND b.status = 'Active';"}, {"role": "user", "content": "Please only include account pairs where both balances exceed 1000."}, {"role": "assistant", "content": "SELECT a.customer_id, a.account_number AS account_a, b.account_number AS account_b FROM financial_services.accounts a JOIN financial_services.accounts b ON a.customer_id = b.customer_id AND a.account_id < b.account_id WHERE a.status = 'Active' AND b.status = 'Active' AND a.balance > 1000 AND b.balance > 1000;"}, {"role": "user", "content": "Also, filter to accounts opened after 2022-01-01."}, {"role": "assistant", "content": "SELECT a.customer_id, a.account_number AS account_a, b.account_number AS account_b FROM financial_services.accounts a JOIN financial_services.accounts b ON a.customer_id = b.customer_id AND a.account_id < b.account_id WHERE a.status = 'Active' AND b.status = 'Active' AND a.balance > 1000 AND b.balance > 1000 AND a.opened_date > '2022-01-01' AND b.opened_date > '2022-01-01';"}, {"role": "user", "content": "Finally, order the output by customer_id and account_a."}, {"role": "assistant", "content": "SELECT a.customer_id, a.account_number AS account_a, b.account_number AS account_b FROM financial_services.accounts a JOIN financial_services.accounts b ON a.customer_id = b.customer_id AND a.account_id < b.account_id WHERE a.status = 'Active' AND b.status = 'Active' AND a.balance > 1000 AND b.balance > 1000 AND a.opened_date > '2022-01-01' AND b.opened_date > '2022-01-01' ORDER BY a.customer_id, a.account_number;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE narrative_info ( narrative.text, top_3_coins.text, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, market_cap.numeric, volume_24h.numeric, trend_rank.numeric, token_num.numeric )\n", "conversations": [{"role": "user", "content": "List all narratives with a trend rank better than 50, showing the narrative name and their listed 'Top 3 Coins'."}, {"role": "assistant", "content": "SELECT narrative, top_3_coins FROM narrative_info WHERE trend_rank < 50"}, {"role": "user", "content": "Could you also include the 24-hour trading volume for these narratives and only show those where the volume is greater than 10,000,000 USD?"}, {"role": "assistant", "content": "SELECT narrative, top_3_coins, volume_24h FROM narrative_info WHERE trend_rank < 50 AND volume_24h > 10000000"}, {"role": "user", "content": "Please order the results by 24-hour trading volume in descending order."}, {"role": "assistant", "content": "SELECT narrative, top_3_coins, volume_24h FROM narrative_info WHERE trend_rank < 50 AND volume_24h > 10000000 ORDER BY volume_24h DESC"}, {"role": "user", "content": "Finally, limit the output to the top 10 and add the total number of tokens for each narrative."}, {"role": "assistant", "content": "SELECT narrative, top_3_coins, volume_24h, token_num FROM narrative_info WHERE trend_rank < 50 AND volume_24h > 10000000 ORDER BY volume_24h DESC LIMIT 10"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\n", "conversations": [{"role": "user", "content": "List pairs of distinct routes that originate from the same location but go to different destinations. Show the route ID and route number for both routes and the common origin location ID."}, {"role": "assistant", "content": "SELECT\n r1.route_id AS route1_id,\n r1.route_number AS route1_number,\n r2.route_id AS route2_id,\n r2.route_number AS route2_number,\n r1.origin_location_id AS shared_origin_location_id\nFROM transportation.routes AS r1\nJOIN transportation.routes AS r2\n ON r1.origin_location_id = r2.origin_location_id\n AND r1.route_id < r2.route_id\nWHERE\n r1.destination_location_id != r2.destination_location_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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) )\n", "conversations": [{"role": "user", "content": "Find pairs of guests living in the same city, returning each pair\u2019s full names and the city."}, {"role": "assistant", "content": "SELECT g1.first_name || ' ' || g1.last_name AS guest1,\n g2.first_name || ' ' || g2.last_name AS guest2,\n g1.city\nFROM hospitality_technology.guests g1\nJOIN hospitality_technology.guests g2\n ON g1.city = g2.city\n AND g1.guest_id < g2.guest_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.events ( event_id text, contract_id text, event_name text, data text, emitted_at timestamp, transaction_id text, log_index integer )\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.tokens ( token_id text, contract_address text, token_name text, token_symbol text, decimals integer, total_supply numeric )\nCREATE TABLE web3.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all token transfers showing the transfer id, the symbol of the transferred token, and the contract address where the token was created."}, {"role": "assistant", "content": "SELECT tt.transfer_id, t.token_symbol, t.contract_address\nFROM web3.token_transfers tt\nJOIN web3.tokens t ON tt.token_id = t.token_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\n", "conversations": [{"role": "user", "content": "Can you show me all routes where the origin_location_id is the same as the destination_location_id? List their route_id, route_number, and type."}, {"role": "assistant", "content": "SELECT route_id, route_number, type\nFROM transportation.routes\nWHERE origin_location_id = destination_location_id;"}, {"role": "user", "content": "I'd also like to know the distance_km and estimated_duration_minutes for these routes."}, {"role": "assistant", "content": "SELECT route_id, route_number, type, distance_km, estimated_duration_minutes\nFROM transportation.routes\nWHERE origin_location_id = destination_location_id;"}, {"role": "user", "content": "Finally, only include those routes where estimated_duration_minutes is less than 30 and sort by distance_km descending."}, {"role": "assistant", "content": "SELECT route_id, route_number, type, distance_km, estimated_duration_minutes\nFROM transportation.routes\nWHERE origin_location_id = destination_location_id\n AND estimated_duration_minutes < 30\nORDER BY distance_km DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id text PRIMARY KEY, first_name text, last_name text, bar_number text UNIQUE, firm_id text, email text UNIQUE, phone text, specialization text, hire_date timestamp, is_partner bool )\nCREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.cases ( case_id text PRIMARY KEY, case_number text UNIQUE, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.time_entries ( entry_id text PRIMARY KEY, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable bool, is_billed bool, invoice_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "I need the case_number and case_name along with the total billing amount (hours_spent * billing_rate) for cases that are currently open."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, SUM(te.hours_spent * te.billing_rate) AS total_billing\nFROM legal_services.cases c\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nWHERE c.status = 'Open'\nGROUP BY c.case_number, c.case_name;"}, {"role": "user", "content": "Now order the results by total_billing in descending order and limit to the top 5."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, SUM(te.hours_spent * te.billing_rate) AS total_billing\nFROM legal_services.cases c\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nWHERE c.status = 'Open'\nGROUP BY c.case_number, c.case_name\nORDER BY total_billing DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Which 3 tokens across all chains have the highest realized_ratio and what are their avg_cost and roi?"}, {"role": "assistant", "content": "SELECT token_symbol, chain, realized_ratio, avg_cost, roi\nFROM smart_money_token_performance\nORDER BY realized_ratio DESC\nLIMIT 3;"}, {"role": "user", "content": "I get an error, could you also display their pnl in the result?"}, {"role": "assistant", "content": "SELECT token_symbol, chain, realized_ratio, avg_cost, roi, pnl\nFROM smart_money_token_performance\nORDER BY realized_ratio DESC\nLIMIT 3;"}, {"role": "user", "content": "Actually, I want tokens where realized_ratio is above 0.7 and net_flow is positive only."}, {"role": "assistant", "content": "SELECT token_symbol, chain, realized_ratio, avg_cost, roi, pnl\nFROM smart_money_token_performance\nWHERE realized_ratio > 0.7 AND net_flow > 0\nORDER BY realized_ratio DESC\nLIMIT 3;"}, {"role": "user", "content": "And can you order the result by pnl descending instead?"}, {"role": "assistant", "content": "SELECT token_symbol, chain, realized_ratio, avg_cost, roi, pnl\nFROM smart_money_token_performance\nWHERE realized_ratio > 0.7 AND net_flow > 0\nORDER BY pnl DESC\nLIMIT 3;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n", "conversations": [{"role": "user", "content": "List the plan ID, name, provider, and type for all insurance plans from 'Healthcare Partners' with a plan type of 'PPO'."}, {"role": "assistant", "content": "SELECT plan_id, plan_name, insurance_provider, plan_type FROM healthcare.insurance_plans WHERE insurance_provider = 'Healthcare Partners' AND plan_type = 'PPO';"}, {"role": "user", "content": "Now, only show those plans that also have a website listed."}, {"role": "assistant", "content": "SELECT plan_id, plan_name, insurance_provider, plan_type FROM healthcare.insurance_plans WHERE insurance_provider = 'Healthcare Partners' AND plan_type = 'PPO' AND website IS NOT NULL;"}, {"role": "user", "content": "Further refine the results to only include plans where the plan name contains the word 'Plus'."}, {"role": "assistant", "content": "SELECT plan_id, plan_name, insurance_provider, plan_type FROM healthcare.insurance_plans WHERE insurance_provider = 'Healthcare Partners' AND plan_type = 'PPO' AND website IS NOT NULL AND plan_name ILIKE '%Plus%';"}, {"role": "user", "content": "Finally, count how many such plans exist."}, {"role": "assistant", "content": "SELECT COUNT(*) FROM healthcare.insurance_plans WHERE insurance_provider = 'Healthcare Partners' AND plan_type = 'PPO' AND website IS NOT NULL AND plan_name ILIKE '%Plus%';"}]} -{"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 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.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.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": "Show a list of all asset names along with the current KYC status of each user, including the asset symbol. Join the assets and kyc_audit tables."}, {"role": "assistant", "content": "SELECT a.name AS asset_name, a.symbol, k.user_id, k.status AS kyc_status \nFROM trading_platform.assets a\nJOIN trading_platform.kyc_audit k ON 1=1"}, {"role": "user", "content": "I only want the result for users whose KYC status is 'approved' and for assets where the symbol is at least 3 characters long."}, {"role": "assistant", "content": "SELECT a.name AS asset_name, a.symbol, k.user_id, k.status AS kyc_status \nFROM trading_platform.assets a\nJOIN trading_platform.kyc_audit k ON 1=1\nWHERE k.status = 'approved' AND LENGTH(a.symbol) >= 3"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id text PRIMARY KEY, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.token_transfers ( transfer_id 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.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 web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n", "conversations": [{"role": "user", "content": "For each token transfer, show the transfer id, token symbol, and the username of the user who owns the sender address. Please order the result by transfer id."}, {"role": "assistant", "content": "SELECT tt.transfer_id, tk.token_symbol, u.username\nFROM web3.token_transfers tt\nJOIN web3.tokens tk ON tt.token_id = tk.token_id\nJOIN web3.wallets w ON tt.from_address = w.address\nJOIN web3.users u ON w.user_id = u.user_id\nORDER BY tt.transfer_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claims (\n claim_id character varying(64) NOT NULL, -- unique identifier for the claim\n policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers)\n incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim\n reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported\n description text NOT NULL, -- detailed description of the incident and claim\n estimated_loss numeric(15, 2), -- initial estimated cost of the loss\n status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled\n settlement_amount numeric(15, 2), -- final amount paid out\n settlement_date date,\n claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters)\n police_report_number character varying(100),\n PRIMARY KEY (claim_id)\n)\nCREATE TABLE insurance.insurance_products (\n product_id character varying(64) NOT NULL, -- unique identifier for the insurance product\n product_name character varying(150) NOT NULL, -- name of the insurance product (e.g., 'Comprehensive Auto Insurance')\n product_type character varying(50) NOT NULL, -- category like 'Auto', 'Home', 'Life', 'Health', 'Travel'\n description text, -- detailed description of the product\n base_premium numeric(10, 2) NOT NULL, -- starting premium before adjustments\n coverage_details text, -- details about what is covered (could be JSON or structured text)\n underwriting_rules text, -- rules used for assessing risk and eligibility\n is_active boolean NOT NULL DEFAULT true, -- whether the product is currently offered\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n updated_at timestamp,\n PRIMARY KEY (product_id)\n)\nCREATE TABLE insurance.premium_payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment\n policy_id character varying(64) NOT NULL, -- identifier of the policy the payment is for (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the customer making the payment (FK to customers)\n payment_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the payment was received\n amount_paid numeric(12, 2) NOT NULL, -- amount of the payment\n payment_method character varying(50), -- e.g., Credit Card, Bank Transfer, Check\n transaction_reference character varying(128) UNIQUE, -- reference from payment processor\n due_date date, -- due date for this payment installment\n payment_period_start date, -- start date of the period this payment covers\n payment_period_end date, -- end date of the period this payment covers\n status character varying(30) NOT NULL DEFAULT 'Completed', -- e.g., Completed, Pending, Failed, Refunded\n PRIMARY KEY (payment_id)\n)\nCREATE TABLE insurance.claim_documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n claim_id character varying(64) NOT NULL, -- identifier of the claim this document relates to (FK to claims)\n document_type character varying(50) NOT NULL, -- e.g., Police Report, Photo, Invoice, Medical Bill\n file_name character varying(255) NOT NULL, -- original name of the uploaded file\n file_path character varying(512) NOT NULL, -- storage path (e.g., S3 URL, network path)\n file_size_bytes integer, -- size of the file in bytes\n mime_type character varying(100), -- MIME type of the file (e.g., 'image/jpeg', 'application/pdf')\n uploaded_by character varying(64), -- identifier of the user/system who uploaded (FK to users/customers)\n uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- time of upload\n description text, -- optional description of the document\n PRIMARY KEY (document_id)\n)\n", "conversations": [{"role": "user", "content": "List all premium payments with the amount_paid exactly 1000, showing the payment_id and payment_date."}, {"role": "assistant", "content": "SELECT payment_id, payment_date\nFROM insurance.premium_payments\nWHERE amount_paid = 1000;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 the full names of all employees who are currently employed (i.e., have no termination date)."}, {"role": "assistant", "content": "SELECT first_name || ' ' || last_name AS full_name FROM government_services.employees WHERE termination_date IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\nCREATE TABLE trading_platform.trades ( trade_id.text, order_id.text, buyer_id.text, seller_id.text, asset_id.text, quantity.numeric, price.numeric, traded_at.timestamp )\nCREATE TABLE trading_platform.assets ( asset_id.text, name.text, symbol.text, type.text )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.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 )\n", "conversations": [{"role": "user", "content": "Find the address that has the highest total amount across all its UTXOs."}, {"role": "assistant", "content": "SELECT address FROM utxos GROUP BY address ORDER BY SUM(amount) DESC LIMIT 1;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_profit ( address.text, rank.numeric, profit.numeric, roi.numeric, realized_ratio.numeric, most_profit_token.text, last_trade_time.text, chain.text )\n", "conversations": [{"role": "user", "content": "List the top 3 addresses with the highest profit on the Arbitrum chain, including roi and most_profit_token."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}, {"role": "user", "content": "Please add the realized_ratio and last_trade_time for each result."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token, realized_ratio, last_trade_time FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}]} -{"system": "You are an 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 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 )\n", "conversations": [{"role": "user", "content": "List each property_name along with the count of rooms that are currently marked as 'Available'."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(r.room_id) AS available_room_count\nFROM hospitality_technology.properties p\nLEFT JOIN hospitality_technology.rooms r\n ON p.property_id = r.property_id AND r.status = 'Available'\nGROUP BY p.property_name;"}, {"role": "user", "content": "Only include properties with more than 10 available rooms and order by available_room_count descending."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(r.room_id) AS available_room_count\nFROM hospitality_technology.properties p\nLEFT JOIN hospitality_technology.rooms r\n ON p.property_id = r.property_id AND r.status = 'Available'\nGROUP BY p.property_name\nHAVING COUNT(r.room_id) > 10\nORDER BY available_room_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n", "conversations": [{"role": "user", "content": "Can you show me all pairs of customers living in the same city but with different last names? Show both customer IDs, both full names, and their city."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a, CONCAT(a.first_name, ' ', a.last_name) AS full_name_a, b.customer_id AS customer_id_b, CONCAT(b.first_name, ' ', b.last_name) AS full_name_b, a.city FROM financial_services.customers a JOIN financial_services.customers b ON a.city = b.city AND a.last_name <> b.last_name AND a.customer_id < b.customer_id;"}, {"role": "user", "content": "Add a filter to only include pairs where both customers are in the same state as well."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a, CONCAT(a.first_name, ' ', a.last_name) AS full_name_a, b.customer_id AS customer_id_b, CONCAT(b.first_name, ' ', b.last_name) AS full_name_b, a.city, a.state FROM financial_services.customers a JOIN financial_services.customers b ON a.city = b.city AND a.state = b.state AND a.last_name <> b.last_name AND a.customer_id < b.customer_id;"}, {"role": "user", "content": "Please further restrict results to only pairs where both customers have a status of 'Active'."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a, CONCAT(a.first_name, ' ', a.last_name) AS full_name_a, b.customer_id AS customer_id_b, CONCAT(b.first_name, ' ', b.last_name) AS full_name_b, a.city, a.state FROM financial_services.customers a JOIN financial_services.customers b ON a.city = b.city AND a.state = b.state AND a.last_name <> b.last_name AND a.status = 'Active' AND b.status = 'Active' AND a.customer_id < b.customer_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n// Use Hashes for ticket details. Key format: ticket:\n// HSET ticket:tkt_1a2b ticket_id \"tkt_1a2b\" booking_id \"book_zyx\" car_id \"car_abc\" seat_number \"12A\" ... is_checked_in 0 ...\n\n// To link tickets to bookings (optional):\n// SADD booking:book_zyx:tickets ticket:tkt_1a2b\n// Use Hashes for maintenance record details. Key format: maintenance_record:\n// HSET maintenance_record:maint_rec_001 record_id \"maint_rec_001\" asset_id \"train_789\" asset_type \"Train\" ... status \"Completed\"\n\n// To link records to assets (optional):\n// SADD train:train_789:maintenance maintenance_record:maint_rec_001\n// SADD platform:plat_123:maintenance maintenance_record:maint_rec_002\n", "conversations": [{"role": "user", "content": "\u7279\u5b9a\u306e\u4e88\u7d04ID 'book_zyx' \u306b\u95a2\u9023\u3059\u308b\u3059\u3079\u3066\u306e\u30c1\u30b1\u30c3\u30c8\u306e\u8a73\u7d30\u3092\u53d6\u5f97\u3059\u308b\u306e\u3092\u624b\u4f1d\u3063\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f\u307e\u305f\u3001\u95a2\u9023\u3059\u308b\u8eca\u4e21\u60c5\u5831\u3082\u542b\u3081\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGETALL ticket:\nHGETALL car:"}, {"role": "user", "content": "\u30c1\u30a7\u30c3\u30af\u30a4\u30f3\u6e08\u307f\u306e\u30c1\u30b1\u30c3\u30c8\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket: is_checked_in\nHGETALL ticket: (only if is_checked_in = 1)\nHGETALL car:"}, {"role": "user", "content": "\u5ea7\u5e2d\u756a\u53f7\u3082\u7d50\u679c\u306b\u542b\u3081\u3066\u3001\u5ea7\u5e2d\u756a\u53f7\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket: is_checked_in\nHGETALL ticket: (only if is_checked_in = 1)\nHGETALL car:\n(Sort results by seat_number in ascending order)"}, {"role": "user", "content": "\u8eca\u4e21ID\u3054\u3068\u306b\u30c1\u30b1\u30c3\u30c8\u306e\u7dcf\u6570\u3092\u8ffd\u52a0\u3057\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket: is_checked_in\nHGETALL ticket: (only if is_checked_in = 1)\nHGETALL car:\n(Group by car_id and count total tickets per car_id)\n(Sort results by seat_number in ascending order)"}]} -{"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 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 accounts (account_id, account_number, account_type, balance, currency) for customers whose status is 'VIP'."}, {"role": "assistant", "content": "SELECT a.account_id, a.account_number, a.account_type, a.balance, a.currency FROM financial_services.accounts AS a JOIN financial_services.customers AS c ON a.customer_id = c.customer_id WHERE c.status = 'VIP';"}, {"role": "user", "content": "Also include the customer's email and the date they were created."}, {"role": "assistant", "content": "SELECT a.account_id, a.account_number, a.account_type, a.balance, a.currency, c.email, c.created_at FROM financial_services.accounts AS a JOIN financial_services.customers AS c ON a.customer_id = c.customer_id WHERE c.status = 'VIP';"}, {"role": "user", "content": "Filter the results to only include accounts opened before 2023-01-01."}, {"role": "assistant", "content": "SELECT a.account_id, a.account_number, a.account_type, a.balance, a.currency, c.email, c.created_at FROM financial_services.accounts AS a JOIN financial_services.customers AS c ON a.customer_id = c.customer_id WHERE c.status = 'VIP' AND a.opened_date < '2023-01-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me all invoices where the notes field is not null. Display invoice number, client ID, and notes."}, {"role": "assistant", "content": "SELECT invoice_number, client_id, notes FROM legal_services.invoices WHERE notes IS NOT NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\nCREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "Show me the latest payment timestamp for each guest who has made a payment, along with their full name."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, max(T2.payment_timestamp) FROM hospitality_technology.guests AS T1 JOIN hospitality_technology.payments AS T2 ON T1.guest_id = T2.guest_id GROUP BY T1.guest_id, T1.first_name, T1.last_name;"}]} -{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.staff ( staff_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, role character varying(64) NOT NULL, primary_station_id character varying(64), employee_number character varying(32) UNIQUE NOT NULL, hire_date date NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), is_active boolean NOT NULL DEFAULT true, PRIMARY KEY (staff_id), FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id) )\n", "conversations": [{"role": "user", "content": "What is the salary or compensation package for a staff member with the role of Ticket Inspector?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information about salary or compensation packages as this data is not included in the staff table. For details on salaries, please refer to the HR department or relevant documentation."}]} -{"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 government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "I want to know the total number of appointments per location along with the location name for appointments scheduled in March 2024."}, {"role": "assistant", "content": "SELECT\n sl.location_name,\n COUNT(a.appointment_id) AS appointment_count\nFROM appointments a\nJOIN service_locations sl\n ON a.location_id = sl.location_id\nWHERE a.scheduled_start_time >= '2024-03-01'\n AND a.scheduled_start_time < '2024-04-01'\nGROUP BY sl.location_name;"}, {"role": "user", "content": "Actually, only include appointments with status 'Completed' and locations that are accessible."}, {"role": "assistant", "content": "SELECT\n sl.location_name,\n COUNT(a.appointment_id) AS completed_appointment_count\nFROM appointments a\nJOIN service_locations sl\n ON a.location_id = sl.location_id\nWHERE a.scheduled_start_time >= '2024-03-01'\n AND a.scheduled_start_time < '2024-04-01'\n AND a.status = 'Completed'\n AND sl.is_accessible = TRUE\nGROUP BY sl.location_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\n", "conversations": [{"role": "user", "content": "List the first name, last name, and the name of the law firm for all lawyers."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id"}, {"role": "user", "content": "Now, filter this list to only include lawyers who work for firms founded after the year 2010."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name FROM lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T2.founded_date > '2010-12-31'"}, {"role": "user", "content": "For these lawyers, also include the firm's phone number and sort the results alphabetically by firm name."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.firm_name, T2.phone FROM lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T2.founded_date > '2010-12-31' ORDER BY T2.firm_name"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "List user IDs and the creation timestamp of likes made by users who have email notifications enabled."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true;"}, {"role": "user", "content": "Only show likes created in the year 2024."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01';"}, {"role": "user", "content": "Filter to only include users whose profile is not private."}, {"role": "assistant", "content": "SELECT T1.user_id, T1.created_at FROM social_media.likes AS T1 JOIN social_media.user_settings AS T2 ON T1.user_id = T2.user_id WHERE T2.email_notifications_enabled = true AND T1.created_at >= '2024-01-01' AND T1.created_at < '2025-01-01' AND T2.private_profile = false;"}]} +{"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 legal_services.clients ( client_id.text, first_name.text, last_name.text, company_name.text, email.text, phone.text, address.text, date_registered.timestamp, status.text )\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.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\nCREATE TABLE legal_services.time_entries ( entry_id.text, 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 ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all documents along with the case number they are associated with, as well as the name and email of the lawyer who uploaded them."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id;"}, {"role": "user", "content": "Only include documents uploaded after April 1st, 2024."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01';"}, {"role": "user", "content": "Add the case name and make sure only documents with version greater than 1 are listed."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email FROM legal_services.documents d JOIN legal_services.cases c ON d.case_id = c.case_id JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01' AND d.version > 1;"}, {"role": "user", "content": "Order the results by upload_timestamp ascending."}, {"role": "assistant", "content": "SELECT d.document_name, d.document_type, d.case_id, c.case_name, l.first_name || ' ' || l.last_name AS lawyer_full_name, l.email, d.upload_timestamp FROM legal_services.documents d JOIN legal_services.cases c ON d.case_id = c.case_id JOIN legal_services.lawyers l ON d.uploaded_by_lawyer_id = l.lawyer_id WHERE d.upload_timestamp > '2024-04-01' AND d.version > 1 ORDER BY d.upload_timestamp ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me each invoice and the invoice_number of the next invoice for the same client, along with how many days apart their issue_dates are."}, {"role": "assistant", "content": "SELECT a.invoice_number AS invoice_number,\n b.invoice_number AS next_invoice_number,\n (b.issue_date - a.issue_date) AS days_between\n FROM legal_services.invoices a\n JOIN legal_services.invoices b\n ON a.client_id = b.client_id\n AND b.issue_date > a.issue_date;"}, {"role": "user", "content": "Please restrict to pairs where the days_between is greater than 30."}, {"role": "assistant", "content": "SELECT a.invoice_number AS invoice_number,\n b.invoice_number AS next_invoice_number,\n (b.issue_date - a.issue_date) AS days_between\n FROM legal_services.invoices a\n JOIN legal_services.invoices b\n ON a.client_id = b.client_id\n AND b.issue_date > a.issue_date\n WHERE (b.issue_date - a.issue_date) > 30;"}, {"role": "user", "content": "And only include pairs where both invoices have status 'Overdue'."}, {"role": "assistant", "content": "SELECT a.invoice_number AS invoice_number,\n b.invoice_number AS next_invoice_number,\n (b.issue_date - a.issue_date) AS days_between\n FROM legal_services.invoices a\n JOIN legal_services.invoices b\n ON a.client_id = b.client_id\n AND b.issue_date > a.issue_date\n WHERE (b.issue_date - a.issue_date) > 30\n AND a.status = 'Overdue'\n AND b.status = 'Overdue';"}]} +{"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 legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\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 character varying(64) NOT NULL, firm_name character varying(200) NOT NULL, address text NOT NULL, phone character varying(32), website character varying(255), founded_date date, managing_partner_id character varying(64), PRIMARY KEY (firm_id) )\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Which lawyers have handled cases in the 'Federal Court' jurisdiction? Return each lawyer's first and last name, the case number, and the court jurisdiction."}, {"role": "assistant", "content": "SELECT l.first_name, l.last_name, c.case_number, c.court_jurisdiction\nFROM legal_services.lawyers l\nJOIN legal_services.cases c ON l.lawyer_id = c.lead_lawyer_id\nWHERE c.court_jurisdiction = 'Federal Court';"}]} +{"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 legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "How many appointments were created in the month of July 2024?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS appointment_count\nFROM legal_services.appointments\nWHERE DATE_TRUNC('month', created_at) = DATE '2024-07-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Count the total number of invoices issued in each calendar year and month. Show the year, month, and the count, ordered chronologically."}, {"role": "assistant", "content": "SELECT EXTRACT(YEAR FROM issue_date) AS issue_year, EXTRACT(MONTH FROM issue_date) AS issue_month, COUNT(*) AS invoice_count FROM legal_services.invoices GROUP BY issue_year, issue_month ORDER BY issue_year, issue_month;"}]} +{"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 legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, 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 ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "I need a list of each case_number and case_name with the total hours spent on each case based on time_entries, but only include cases where the total hours is greater than 10."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, SUM(te.hours_spent) AS total_hours\nFROM legal_services.cases c\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nGROUP BY c.case_number, c.case_name\nHAVING SUM(te.hours_spent) > 10;"}, {"role": "user", "content": "Actually, tally only hours where is_billable is true."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, SUM(te.hours_spent) AS total_hours\nFROM legal_services.cases c\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nWHERE te.is_billable = TRUE\nGROUP BY c.case_number, c.case_name\nHAVING SUM(te.hours_spent) > 10;"}, {"role": "user", "content": "Also include the client's first_name and last_name for each case."}, {"role": "assistant", "content": "SELECT c.case_number, c.case_name, cl.first_name, cl.last_name, SUM(te.hours_spent) AS total_hours\nFROM legal_services.cases c\nJOIN legal_services.clients cl ON c.client_id = cl.client_id\nJOIN legal_services.time_entries te ON c.case_id = te.case_id\nWHERE te.is_billable = TRUE\nGROUP BY c.case_number, c.case_name, cl.first_name, cl.last_name\nHAVING SUM(te.hours_spent) > 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\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 )\n", "conversations": [{"role": "user", "content": "List all law firms that do not have a website registered, including their firm name and phone."}, {"role": "assistant", "content": "SELECT firm_name, phone\nFROM legal_services.law_firms\nWHERE website IS NULL OR website = '';"}]} +{"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 legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, 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 ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me all clients along with the total number of invoices they have and the sum of total_amount for those invoices."}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv ON cl.client_id = inv.client_id\nGROUP BY cl.client_id, cl.first_name, cl.last_name;"}, {"role": "user", "content": "Could you limit this to invoices issued after '2023-01-01'?"}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv\n ON cl.client_id = inv.client_id AND inv.issue_date > '2023-01-01'\nGROUP BY cl.client_id, cl.first_name, cl.last_name;"}, {"role": "user", "content": "Also exclude clients who haven't paid any invoice."}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv\n ON cl.client_id = inv.client_id AND inv.issue_date > '2023-01-01'\nGROUP BY cl.client_id, cl.first_name, cl.last_name\nHAVING SUM(inv.amount_paid) > 0;"}, {"role": "user", "content": "Sort the results by sum_total_amount descending."}, {"role": "assistant", "content": "SELECT cl.client_id, cl.first_name, cl.last_name, COUNT(inv.invoice_id) AS invoice_count, SUM(inv.total_amount) AS sum_total_amount\nFROM legal_services.clients cl\nLEFT JOIN legal_services.invoices inv\n ON cl.client_id = inv.client_id AND inv.issue_date > '2023-01-01'\nGROUP BY cl.client_id, cl.first_name, cl.last_name\nHAVING SUM(inv.amount_paid) > 0\nORDER BY sum_total_amount DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\n", "conversations": [{"role": "user", "content": "List the latest version of each document (identified by case_id and document_name), showing the version number and its upload_timestamp."}, {"role": "assistant", "content": "SELECT d.case_id,\n d.document_name,\n d.version AS latest_version,\n d.upload_timestamp\nFROM legal_services.documents d\nJOIN (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m ON d.case_id = m.case_id\n AND d.document_name = m.document_name\n AND d.version = m.max_version;"}, {"role": "user", "content": "Actually, I also want to see the upload_timestamp of the previous version for each document."}, {"role": "assistant", "content": "SELECT m.case_id,\n m.document_name,\n m.max_version AS latest_version,\n d_latest.upload_timestamp AS latest_timestamp,\n d_prev.upload_timestamp AS previous_timestamp\nFROM (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m\nJOIN legal_services.documents d_latest\n ON d_latest.case_id = m.case_id\n AND d_latest.document_name = m.document_name\n AND d_latest.version = m.max_version\nLEFT JOIN legal_services.documents d_prev\n ON d_prev.case_id = m.case_id\n AND d_prev.document_name = m.document_name\n AND d_prev.version = m.max_version - 1;"}, {"role": "user", "content": "Also, only include documents whose first version (version = 1) was uploaded in 2024."}, {"role": "assistant", "content": "SELECT m.case_id,\n m.document_name,\n m.max_version AS latest_version,\n d_latest.upload_timestamp AS latest_timestamp,\n d_prev.upload_timestamp AS previous_timestamp\nFROM (\n SELECT case_id, document_name, MAX(version) AS max_version\n FROM legal_services.documents\n GROUP BY case_id, document_name\n) m\nJOIN legal_services.documents d_first\n ON d_first.case_id = m.case_id\n AND d_first.document_name = m.document_name\n AND d_first.version = 1\n AND d_first.upload_timestamp >= '2024-01-01'\n AND d_first.upload_timestamp < '2025-01-01'\nJOIN legal_services.documents d_latest\n ON d_latest.case_id = m.case_id\n AND d_latest.document_name = m.document_name\n AND d_latest.version = m.max_version\nLEFT JOIN legal_services.documents d_prev\n ON d_prev.case_id = m.case_id\n AND d_prev.document_name = m.document_name\n AND d_prev.version = m.max_version - 1;"}]} +{"system": "You are an 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 legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "For each client, list their first and last invoice numbers along with the corresponding issue_dates."}, {"role": "assistant", "content": "SELECT first_inv.client_id,\n first_inv.invoice_number AS first_invoice,\n first_inv.issue_date AS first_date,\n last_inv.invoice_number AS last_invoice,\n last_inv.issue_date AS last_date\nFROM legal_services.invoices first_inv\nJOIN legal_services.invoices last_inv\n ON first_inv.client_id = last_inv.client_id\n AND first_inv.issue_date = (\n SELECT MIN(issue_date)\n FROM legal_services.invoices\n WHERE client_id = first_inv.client_id\n )\n AND last_inv.issue_date = (\n SELECT MAX(issue_date)\n FROM legal_services.invoices\n WHERE client_id = last_inv.client_id\n );"}, {"role": "user", "content": "Sort the output by client_id."}, {"role": "assistant", "content": "SELECT first_inv.client_id,\n first_inv.invoice_number AS first_invoice,\n first_inv.issue_date AS first_date,\n last_inv.invoice_number AS last_invoice,\n last_inv.issue_date AS last_date\nFROM legal_services.invoices first_inv\nJOIN legal_services.invoices last_inv\n ON first_inv.client_id = last_inv.client_id\n AND first_inv.issue_date = (\n SELECT MIN(issue_date)\n FROM legal_services.invoices\n WHERE client_id = first_inv.client_id\n )\n AND last_inv.issue_date = (\n SELECT MAX(issue_date)\n FROM legal_services.invoices\n WHERE client_id = last_inv.client_id\n )\nORDER BY first_inv.client_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.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 ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the invoice number and total amount for invoices, along with the case number and case name for the related case."}, {"role": "assistant", "content": "SELECT i.invoice_number, i.total_amount, c.case_number, c.case_name\nFROM legal_services.invoices i\nJOIN legal_services.cases c ON i.case_id = c.case_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holders (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- Number of held NFTs\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n name varchar NOT NULL, -- name fields for the functionType in contract\n symbol varchar NOT NULL, -- symbol fields for the functionType in contract\n deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract\n deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n description varchar NOT NULL, -- description fields for the functionType in contract\n slug varchar NOT NULL, -- slug fields for the functionType in contract\n media_info varchar NOT NULL, -- media_info fields for the functionType in contract\n image_url varchar NOT NULL, -- image_url fields for the functionType in contract\n banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n banner varchar NOT NULL, -- banner fields for the functionType in contract\n token_count bigint NOT NULL, -- token_count fields for the functionType in contract\n floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract\n floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract\n floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE 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 ( 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 varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\n", "conversations": [{"role": "user", "content": "Show me the total amount and number of unique holder wallets for each ERC20 token held on Ethereum. Please display contract address, sum of amounts, and holder count."}, {"role": "assistant", "content": "SELECT contract_address, SUM(amount::numeric) AS total_amount, COUNT(DISTINCT wallet_address) AS holder_count\nFROM erc20_balances\nGROUP BY contract_address;"}, {"role": "user", "content": "Add the token symbol and decimals for each contract by joining with token_prices_latest."}, {"role": "assistant", "content": "SELECT eb.contract_address, SUM(eb.amount::numeric) AS total_amount, COUNT(DISTINCT eb.wallet_address) AS holder_count, t.symbol, t.decimals\nFROM erc20_balances eb\nLEFT JOIN token_prices_latest t ON eb.contract_address = t.address AND t.blockchain = 'Ethereum'\nGROUP BY eb.contract_address, t.symbol, t.decimals;"}, {"role": "user", "content": "Filter to only include tokens with more than 300 holders and order by total amount descending."}, {"role": "assistant", "content": "SELECT eb.contract_address, SUM(eb.amount::numeric) AS total_amount, COUNT(DISTINCT eb.wallet_address) AS holder_count, t.symbol, t.decimals\nFROM erc20_balances eb\nLEFT JOIN token_prices_latest t ON eb.contract_address = t.address AND t.blockchain = 'Ethereum'\nGROUP BY eb.contract_address, t.symbol, t.decimals\nHAVING COUNT(DISTINCT eb.wallet_address) > 300\nORDER BY total_amount DESC;"}, {"role": "user", "content": "Limit the result to the top 10 tokens only."}, {"role": "assistant", "content": "SELECT eb.contract_address, SUM(eb.amount::numeric) AS total_amount, COUNT(DISTINCT eb.wallet_address) AS holder_count, t.symbol, t.decimals\nFROM erc20_balances eb\nLEFT JOIN token_prices_latest t ON eb.contract_address = t.address AND t.blockchain = 'Ethereum'\nGROUP BY eb.contract_address, t.symbol, t.decimals\nHAVING COUNT(DISTINCT eb.wallet_address) > 300\nORDER BY total_amount DESC\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\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n", "conversations": [{"role": "user", "content": "For each Bitcoin token tick, show me the creator address from the token_info_bitcoin table and the number of unique wallets currently holding that token."}, {"role": "assistant", "content": "SELECT ti.tick, ti.creator, COUNT(DISTINCT tb.wallet_address) AS unique_wallets FROM token_info_bitcoin ti JOIN token_balances_bitcoin tb ON ti.tick = tb.tick GROUP BY ti.tick, ti.creator;"}, {"role": "user", "content": "Now, only include ticks where there are more than 5 unique wallets, and order the result by the number of unique wallets descending."}, {"role": "assistant", "content": "SELECT ti.tick, ti.creator, COUNT(DISTINCT tb.wallet_address) AS unique_wallets FROM token_info_bitcoin ti JOIN token_balances_bitcoin tb ON ti.tick = tb.tick GROUP BY ti.tick, ti.creator HAVING COUNT(DISTINCT tb.wallet_address) > 5 ORDER BY unique_wallets DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner 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 sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\n", "conversations": [{"role": "user", "content": "For each ERC1155 NFT on Ethereum, can you show the contract address, token ID, and the total number of unique wallet holders?"}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, COUNT(DISTINCT nh.wallet_address) AS unique_holders\nFROM nft_holders nh\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id;"}, {"role": "user", "content": "Can you also include the total amount held for each NFT across all wallets?"}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, COUNT(DISTINCT nh.wallet_address) AS unique_holders, SUM(CAST(nh.amount AS BIGINT)) AS total_amount\nFROM nft_holders nh\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id;"}, {"role": "user", "content": "I want the result restricted to NFTs where the total amount held is more than 1000."}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, COUNT(DISTINCT nh.wallet_address) AS unique_holders, SUM(CAST(nh.amount AS BIGINT)) AS total_amount\nFROM nft_holders nh\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id\nHAVING SUM(CAST(nh.amount AS BIGINT)) > 1000;"}, {"role": "user", "content": "Please also add the name of each NFT from the nft_metadata table, if available."}, {"role": "assistant", "content": "SELECT nh.contract_address, nh.token_id, nm.name AS nft_name, COUNT(DISTINCT nh.wallet_address) AS unique_holders, SUM(CAST(nh.amount AS BIGINT)) AS total_amount\nFROM nft_holders nh\nLEFT JOIN nft_metadata nm ON nh.contract_address = nm.contract_address AND nh.token_id = nm.token_id AND nm.blockchain = 'Ethereum'\nWHERE nh.contract_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id, nm.name\nHAVING SUM(CAST(nh.amount AS BIGINT)) > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\n", "conversations": [{"role": "user", "content": "Show all SUI coins with 'exists' status and more than 8 decimal places. Display coin_type, symbol, name, and decimals."}, {"role": "assistant", "content": "SELECT coin_type, symbol, name, decimals\nFROM sui_coins_metadata\nWHERE status = 'exists' AND decimals > 8;"}, {"role": "user", "content": "Add the total balance for each coin_type by joining with sui_coins."}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, SUM(sc.balance::numeric) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND scm.decimals > 8\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals;"}, {"role": "user", "content": "Can you also include only coins where the total_balance is greater than 1,000,000 and show the description?"}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description, SUM(sc.balance::numeric) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND scm.decimals > 8\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description\nHAVING SUM(sc.balance::numeric) > 1000000;"}, {"role": "user", "content": "Actually, only show the top 5 coins with the highest total_balance."}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description, SUM(sc.balance::numeric) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND scm.decimals > 8\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals, scm.description\nHAVING SUM(sc.balance::numeric) > 1000000\nORDER BY total_balance DESC\nLIMIT 5;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE token_prices (\n uuid varchar(36) NOT NULL, -- uuid fields for the functionType in contract\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_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 varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n", "conversations": [{"role": "user", "content": "Show me the wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount, from the erc20_balances table."}, {"role": "assistant", "content": "SELECT e.wallet_address, t.symbol, e.amount FROM erc20_balances e JOIN token_prices_latest t ON e.contract_address = t.address WHERE CAST(e.amount AS decimal) > 1000;"}, {"role": "user", "content": "Can you also include the current price of each token from the token_prices_latest table and sort the results by amount in descending order?"}, {"role": "assistant", "content": "SELECT e.wallet_address, t.symbol, e.amount, t.price FROM erc20_balances e JOIN token_prices_latest t ON e.contract_address = t.address WHERE CAST(e.amount AS decimal) > 1000 ORDER BY CAST(e.amount AS decimal) DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.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.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\n", "conversations": [{"role": "user", "content": "How many notifications have been marked as read so far?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS read_notifications_count\nFROM social_media.notifications\nWHERE read_at IS NOT NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id.text, medication_name.text, generic_name.text, manufacturer.text, ndc_code.text, description.text )\n", "conversations": [{"role": "user", "content": "Find all medications whose generic_name matches the medication_name of another entry, displaying the brand medication_id, brand medication_name, generic medication_id, and generic medication_name."}, {"role": "assistant", "content": "SELECT b.medication_id AS brand_id, b.medication_name AS brand_name, g.medication_id AS generic_id, g.medication_name AS generic_name\nFROM healthcare.medications b\nJOIN healthcare.medications g\n ON b.generic_name = g.medication_name;"}, {"role": "user", "content": "Filter to include only those where the manufacturer of the brand differs from that of the generic match."}, {"role": "assistant", "content": "SELECT b.medication_id AS brand_id, b.medication_name AS brand_name, g.medication_id AS generic_id, g.medication_name AS generic_name\nFROM healthcare.medications b\nJOIN healthcare.medications g\n ON b.generic_name = g.medication_name\nWHERE b.manufacturer <> g.manufacturer;"}]} -{"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 gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )\n", "conversations": [{"role": "user", "content": "I need a report showing the count of servers grouped by their status."}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS server_count\nFROM gaming_technology.servers\nGROUP BY status;"}, {"role": "user", "content": "Actually, can you also compute each status\u2019s percentage share of the total servers?"}, {"role": "assistant", "content": "SELECT\n status,\n COUNT(*) AS server_count,\n ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) AS percentage\nFROM gaming_technology.servers\nGROUP BY status;"}, {"role": "user", "content": "Now filter out any statuses that represent less than 5% of all servers."}, {"role": "assistant", "content": "SELECT\n status,\n server_count,\n percentage\nFROM (\n SELECT\n status,\n COUNT(*) AS server_count,\n ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) AS percentage\n FROM gaming_technology.servers\n GROUP BY status\n) sub\nWHERE percentage >= 5;"}, {"role": "user", "content": "Finally, order the results by percentage in descending order."}, {"role": "assistant", "content": "SELECT\n status,\n server_count,\n percentage\nFROM (\n SELECT\n status,\n COUNT(*) AS server_count,\n ROUND(COUNT(*) * 100.0 / SUM(COUNT(*)) OVER (), 2) AS percentage\n FROM gaming_technology.servers\n GROUP BY status\n) sub\nWHERE percentage >= 5\nORDER BY percentage DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id character varying(64) NOT NULL, employee_id character varying(64) NOT NULL UNIQUE, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, license_number character varying(64) NOT NULL UNIQUE, license_expiry_date date NOT NULL, contact_number character varying(32), email character varying(128) UNIQUE, hire_date date NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (driver_id) )\nCREATE TABLE transportation.routes ( route_id.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 (\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 ( 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)\n", "conversations": [{"role": "user", "content": "How many routes start and end in the same city?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS same_city_routes\nFROM transportation.routes AS r\nJOIN transportation.locations AS o ON r.origin_location_id = o.location_id\nJOIN transportation.locations AS d ON r.destination_location_id = d.location_id\nWHERE o.city = d.city;"}, {"role": "user", "content": "Actually, I would like to see each route_number and the city instead of just the count."}, {"role": "assistant", "content": "SELECT r.route_number,\n o.city AS common_city\nFROM transportation.routes AS r\nJOIN transportation.locations AS o ON r.origin_location_id = o.location_id\nJOIN transportation.locations AS d ON r.destination_location_id = d.location_id\nWHERE o.city = d.city;"}, {"role": "user", "content": "Can you also restrict it to routes where distance_km is greater than 100?"}, {"role": "assistant", "content": "SELECT r.route_number,\n o.city AS common_city\nFROM transportation.routes AS r\nJOIN transportation.locations AS o ON r.origin_location_id = o.location_id\nJOIN transportation.locations AS d ON r.destination_location_id = d.location_id\nWHERE o.city = d.city\n AND r.distance_km > 100;"}, {"role": "user", "content": "Please sort the results by route_number in ascending order."}, {"role": "assistant", "content": "SELECT r.route_number,\n o.city AS common_city\nFROM transportation.routes AS r\nJOIN transportation.locations AS o ON r.origin_location_id = o.location_id\nJOIN transportation.locations AS d ON r.destination_location_id = d.location_id\nWHERE o.city = d.city\n AND r.distance_km > 100\nORDER BY r.route_number ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "For each vehicle and unit combination, show the total quantity of fuel refueled and the total cost."}, {"role": "assistant", "content": "SELECT vehicle_id, unit, SUM(quantity) AS total_quantity, SUM(total_cost) AS total_cost\nFROM transportation.fuel_logs\nGROUP BY vehicle_id, unit;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number / 7200))\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n", "conversations": [{"role": "user", "content": "List the ERC20 tokens (from token_metas) with exactly 6 decimals. Show their symbol, contract_address, and name."}, {"role": "assistant", "content": "SELECT symbol, contract_address, name FROM token_metas WHERE is_erc20 = 1 AND decimals = 6;"}, {"role": "user", "content": "Can you also include the total current supply for each token?"}, {"role": "assistant", "content": "SELECT symbol, contract_address, name, total_supply FROM token_metas WHERE is_erc20 = 1 AND decimals = 6;"}, {"role": "user", "content": "Now, join with token_prices_latest to also include the latest price for each token."}, {"role": "assistant", "content": "SELECT tm.symbol, tm.contract_address, tm.name, tm.total_supply, tpl.price AS latest_price\nFROM token_metas tm\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nWHERE tm.is_erc20 = 1 AND tm.decimals = 6;"}, {"role": "user", "content": "Only include tokens where the latest price is between 0.5 and 2.0 USD, and limit the result to the top 5 tokens by price descending."}, {"role": "assistant", "content": "SELECT tm.symbol, tm.contract_address, tm.name, tm.total_supply, tpl.price AS latest_price\nFROM token_metas tm\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nWHERE tm.is_erc20 = 1 AND tm.decimals = 6 AND tpl.price BETWEEN 0.5 AND 2.0\nORDER BY tpl.price DESC\nLIMIT 5;"}]} +{"system": "You are an 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 gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\n", "conversations": [{"role": "user", "content": "Find the date (calendar day) with the highest total number of game sessions. Show the date and the total session count."}, {"role": "assistant", "content": "SELECT CAST(start_time AS DATE) AS session_date, COUNT(*) AS total_sessions\nFROM gaming_technology.game_sessions\nGROUP BY session_date\nORDER BY total_sessions DESC\nLIMIT 1;"}, {"role": "user", "content": "Also include the day with the second highest session count."}, {"role": "assistant", "content": "SELECT session_date, total_sessions FROM (\n SELECT CAST(start_time AS DATE) AS session_date, COUNT(*) AS total_sessions,\n ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS rn\n FROM gaming_technology.game_sessions\n GROUP BY session_date\n) ranked\nWHERE rn <= 2\nORDER BY total_sessions DESC;"}, {"role": "user", "content": "Can you also add the total score across all sessions for each of those days?"}, {"role": "assistant", "content": "SELECT session_date, total_sessions, total_score FROM (\n SELECT CAST(start_time AS DATE) AS session_date,\n COUNT(*) AS total_sessions,\n SUM(score) AS total_score,\n ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS rn\n FROM gaming_technology.game_sessions\n GROUP BY session_date\n) ranked\nWHERE rn <= 2\nORDER BY total_sessions DESC;"}, {"role": "user", "content": "I got an error that session_date is not found, can you fix this SQL?"}, {"role": "assistant", "content": "SELECT sub.session_date, sub.total_sessions, sub.total_score FROM (\n SELECT CAST(start_time AS DATE) AS session_date,\n COUNT(*) AS total_sessions,\n SUM(score) AS total_score,\n ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS rn\n FROM gaming_technology.game_sessions\n GROUP BY CAST(start_time AS DATE)\n) AS sub\nWHERE sub.rn <= 2\nORDER BY sub.total_sessions DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.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 (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )\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": "Give me each server's name, the region, and the maximum number of players that have been connected at once."}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, MAX(s.current_players) AS max_players_seen\nFROM gaming_technology.servers s\nGROUP BY s.server_id, s.server_name, s.region;"}, {"role": "user", "content": "Could you also include the associated game title for each server?"}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, g.title AS game_title, MAX(s.current_players) AS max_players_seen\nFROM gaming_technology.servers s\nJOIN gaming_technology.games g ON s.game_id = g.game_id\nGROUP BY s.server_id, s.server_name, s.region, g.title;"}, {"role": "user", "content": "Now, can you show only servers where the max number of players ever connected exceeded 20?"}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, g.title AS game_title, MAX(s.current_players) AS max_players_seen\nFROM gaming_technology.servers s\nJOIN gaming_technology.games g ON s.game_id = g.game_id\nGROUP BY s.server_id, s.server_name, s.region, g.title\nHAVING MAX(s.current_players) > 20;"}]} +{"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 gaming_technology.players ( player_id.uuid, username.text, email.text, password_hash.text, registration_date.timestamptz, last_login.timestamptz, country_code.text, status.text, profile_data.jsonb )\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\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.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\nCREATE TABLE gaming_technology.in_game_items ( item_id.uuid, game_id.uuid, item_name.text, item_type.text, description.text, rarity.text, cost_currency.text, cost_amount.numeric, attributes.jsonb )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n", "conversations": [{"role": "user", "content": "List the usernames and registration dates for all players from 'Canada'."}, {"role": "assistant", "content": "SELECT username, registration_date FROM gaming_technology.players WHERE country_code = 'Canada';"}, {"role": "user", "content": "Now, only show players from Canada who registered after January 1st, 2023."}, {"role": "assistant", "content": "SELECT username, registration_date FROM gaming_technology.players WHERE country_code = 'Canada' AND registration_date > '2023-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.games ( game_id uuid NOT NULL DEFAULT gen_random_uuid(), title character varying(200) NOT NULL, developer_id uuid NOT NULL, publisher_id uuid, genre character varying(100), release_date date, description text, platform character varying(50) NOT NULL, engine character varying(100), website character varying(255), PRIMARY KEY (game_id) )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n", "conversations": [{"role": "user", "content": "Retrieve the title and release_date of all games on the 'PC' platform."}, {"role": "assistant", "content": "SELECT title, release_date\nFROM gaming_technology.games\nWHERE platform = 'PC';"}, {"role": "user", "content": "Now exclude any games released before 2018."}, {"role": "assistant", "content": "SELECT title, release_date\nFROM gaming_technology.games\nWHERE platform = 'PC'\n AND release_date >= '2018-01-01';"}, {"role": "user", "content": "Also sort the results by release_date in ascending order."}, {"role": "assistant", "content": "SELECT title, release_date\nFROM gaming_technology.games\nWHERE platform = 'PC'\n AND release_date >= '2018-01-01'\nORDER BY release_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) )\n", "conversations": [{"role": "user", "content": "I need to list all pairs of in-game items in the same game where one item is Epic and the other is Legendary, showing game_id, epic_item, and legendary_item."}, {"role": "assistant", "content": "SELECT a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary';"}, {"role": "user", "content": "Actually, only include pairs where both items have cost_amount greater than 100."}, {"role": "assistant", "content": "SELECT a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary'\n AND a.cost_amount > 100\n AND b.cost_amount > 100;"}, {"role": "user", "content": "Also, ensure each pair appears only once and avoid reversed duplicates."}, {"role": "assistant", "content": "SELECT DISTINCT\n LEAST(a.item_id::text, b.item_id::text) AS item1_id,\n GREATEST(a.item_id::text, b.item_id::text) AS item2_id,\n a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary'\n AND a.cost_amount > 100\n AND b.cost_amount > 100;"}, {"role": "user", "content": "Finally, order the results by game_id ascending."}, {"role": "assistant", "content": "SELECT DISTINCT\n LEAST(a.item_id::text, b.item_id::text) AS item1_id,\n GREATEST(a.item_id::text, b.item_id::text) AS item2_id,\n a.game_id,\n a.item_name AS epic_item,\n b.item_name AS legendary_item\nFROM gaming_technology.in_game_items a\nJOIN gaming_technology.in_game_items b\n ON a.game_id = b.game_id\nWHERE a.rarity = 'Epic'\n AND b.rarity = 'Legendary'\n AND a.cost_amount > 100\n AND b.cost_amount > 100\nORDER BY a.game_id ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n", "conversations": [{"role": "user", "content": "Could you list the title of each game and the total quantity of items acquired by players for that specific game?"}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id GROUP BY g.title;"}, {"role": "user", "content": "Now, I only want to include games where the total acquired quantity is more than 100."}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id GROUP BY g.title HAVING SUM(pi.quantity) > 100;"}, {"role": "user", "content": "Please filter the results further to include only games from the 'Action' genre."}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id WHERE g.genre = 'Action' GROUP BY g.title HAVING SUM(pi.quantity) > 100;"}, {"role": "user", "content": "Finally, order the results by the total acquired quantity in descending order."}, {"role": "assistant", "content": "SELECT g.title, SUM(pi.quantity) AS total_acquired_quantity FROM gaming_technology.games g JOIN gaming_technology.player_inventory pi ON g.game_id = pi.item_id WHERE g.genre = 'Action' GROUP BY g.title HAVING SUM(pi.quantity) > 100 ORDER BY total_acquired_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, name character varying(150) NOT NULL, description text NOT NULL, icon_url character varying(255), points integer DEFAULT 0, hidden boolean DEFAULT false, PRIMARY KEY (achievement_id) )\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": "List the name and points of all hidden achievements."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true;"}, {"role": "user", "content": "Only include those with points greater than 50."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true\n AND points > 50;"}, {"role": "user", "content": "Now order the results by points in ascending order."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true\n AND points > 50\nORDER BY points ASC;"}, {"role": "user", "content": "Finally, limit the output to the top 10 entries."}, {"role": "assistant", "content": "SELECT name, points\nFROM gaming_technology.achievements\nWHERE hidden = true\n AND points > 50\nORDER BY points 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\nCREATE TABLE gaming_technology.player_inventory (\n inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry\n player_id uuid NOT NULL, -- FK linking to the player owning the item\n item_id uuid NOT NULL, -- FK linking to the item definition\n quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)\n acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired\n instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)\n PRIMARY KEY (inventory_id),\n -- Optional unique constraint if items are non-stackable or unique instances\n -- UNIQUE (player_id, item_id) -- Use if quantity is always 1\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)\n)\n", "conversations": [{"role": "user", "content": "Can you show the total quantity of all in-game items held by each player?"}, {"role": "assistant", "content": "SELECT player_id, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id;"}, {"role": "user", "content": "I'd like to see only players whose total quantity is over 20."}, {"role": "assistant", "content": "SELECT player_id, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20;"}, {"role": "user", "content": "Also, can you include the number of different unique items each player owns?"}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT item_id) AS unique_items, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20;"}, {"role": "user", "content": "Order the final result by unique_items descending, then by total_quantity descending."}, {"role": "assistant", "content": "SELECT player_id, COUNT(DISTINCT item_id) AS unique_items, SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) > 20\nORDER BY unique_items DESC, total_quantity DESC;"}]} +{"system": "You are an 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 gaming_technology.servers ( server_id uuid, game_id uuid, server_name text, region text, ip_address text, port integer, current_players integer, max_players integer, status text, last_heartbeat timestamp with time zone )\n", "conversations": [{"role": "user", "content": "Show me all pairs of servers that are located in the same region, listing both server names and their region."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id;"}, {"role": "user", "content": "Filter this list to only include pairs where both servers are currently 'online'."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id WHERE s1.status = 'online' AND s2.status = 'online';"}, {"role": "user", "content": "For these pairs, also show the current_players for both servers."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region, s1.current_players AS server1_current_players, s2.current_players AS server2_current_players FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id WHERE s1.status = 'online' AND s2.status = 'online';"}, {"role": "user", "content": "Order the results by region ascending, then by the current players of the first server in the pair ascending."}, {"role": "assistant", "content": "SELECT s1.server_name AS server1_name, s2.server_name AS server2_name, s1.region, s1.current_players AS server1_current_players, s2.current_players AS server2_current_players FROM gaming_technology.servers s1 JOIN gaming_technology.servers s2 ON s1.region = s2.region AND s1.server_id < s2.server_id WHERE s1.status = 'online' AND s2.status = 'online' ORDER BY s1.region ASC, s1.current_players ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\nCREATE TABLE gaming_technology.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.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": "For each game, find the hidden achievement with the highest points and show the game title, achievement name, and points."}, {"role": "assistant", "content": "SELECT g.title AS game_title,\n a.name AS achievement_name,\n a.points\nFROM gaming_technology.achievements a\nJOIN gaming_technology.games g\n ON a.game_id = g.game_id\nWHERE a.hidden = true\n AND a.points = (\n SELECT MAX(points)\n FROM gaming_technology.achievements\n WHERE game_id = a.game_id\n AND hidden = true\n );"}, {"role": "user", "content": "Actually, exclude games that do not have any hidden achievements."}, {"role": "assistant", "content": "SELECT g.title AS game_title,\n a.name AS achievement_name,\n a.points\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a\n ON g.game_id = a.game_id\nWHERE a.hidden = true\n AND a.points = (\n SELECT MAX(points)\n FROM gaming_technology.achievements\n WHERE game_id = a.game_id\n AND hidden = true\n );"}, {"role": "user", "content": "Also, order the results by a.points descending."}, {"role": "assistant", "content": "SELECT g.title AS game_title,\n a.name AS achievement_name,\n a.points\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a\n ON g.game_id = a.game_id\nWHERE a.hidden = true\n AND a.points = (\n SELECT MAX(points)\n FROM gaming_technology.achievements\n WHERE game_id = a.game_id\n AND hidden = true\n )\nORDER BY a.points DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )\n", "conversations": [{"role": "user", "content": "List all achievements with more than 100 points."}, {"role": "assistant", "content": "SELECT *\nFROM gaming_technology.achievements\nWHERE points > 100;"}, {"role": "user", "content": "Now exclude any hidden achievements."}, {"role": "assistant", "content": "SELECT *\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = false;"}, {"role": "user", "content": "Only show the columns achievement_id, name, and points."}, {"role": "assistant", "content": "SELECT achievement_id, name, points\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = false;"}, {"role": "user", "content": "Order the output by points in descending order and limit to top 5."}, {"role": "assistant", "content": "SELECT achievement_id, name, points\nFROM gaming_technology.achievements\nWHERE points > 100\n AND hidden = false\nORDER BY points DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )\n", "conversations": [{"role": "user", "content": "List all servers that are currently online. Show their name, region, current player count, and maximum player capacity."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online';"}, {"role": "user", "content": "Filter the list to only include servers with a player utilization ratio (current_players / max_players) above 0.8."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online' AND max_players > 0 AND (CAST(current_players AS NUMERIC) / max_players) > 0.8;"}, {"role": "user", "content": "Also, exclude any servers where the maximum player capacity is less than 50."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online' AND max_players >= 50 AND (CAST(current_players AS NUMERIC) / max_players) > 0.8;"}, {"role": "user", "content": "Finally, order the results by player utilization ratio in descending order and limit the output to the top 10 servers."}, {"role": "assistant", "content": "SELECT server_name, region, current_players, max_players FROM gaming_technology.servers WHERE status = 'online' AND max_players >= 50 AND (CAST(current_players AS NUMERIC) / max_players) > 0.8 ORDER BY (CAST(current_players AS NUMERIC) / max_players) DESC LIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid, player_id uuid, game_id uuid, server_id uuid, start_time timestamp with time zone, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n", "conversations": [{"role": "user", "content": "For each player, show the total number of achievements they have unlocked and their total game session count."}, {"role": "assistant", "content": "SELECT p.player_id, COUNT(pa.achievement_id) AS total_achievements_unlocked, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.player_achievements pa\nFULL JOIN gaming_technology.game_sessions gs ON pa.player_id = gs.player_id\nRIGHT JOIN (\n SELECT DISTINCT player_id FROM gaming_technology.player_achievements\n UNION\n SELECT DISTINCT player_id FROM gaming_technology.game_sessions\n) p ON pa.player_id = p.player_id OR gs.player_id = p.player_id\nGROUP BY p.player_id;"}, {"role": "user", "content": "Can you modify it to only include players who have unlocked at least 3 achievements and played at least 2 sessions?"}, {"role": "assistant", "content": "SELECT p.player_id, COUNT(pa.achievement_id) AS total_achievements_unlocked, COUNT(gs.session_id) AS total_sessions\nFROM gaming_technology.player_achievements pa\nFULL JOIN gaming_technology.game_sessions gs ON pa.player_id = gs.player_id\nRIGHT JOIN (\n SELECT DISTINCT player_id FROM gaming_technology.player_achievements\n UNION\n SELECT DISTINCT player_id FROM gaming_technology.game_sessions\n) p ON pa.player_id = p.player_id OR gs.player_id = p.player_id\nGROUP BY p.player_id\nHAVING COUNT(pa.achievement_id) >= 3 AND COUNT(gs.session_id) >= 2;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\n", "conversations": [{"role": "user", "content": "List pairs of games that share the same publisher but belong to different genres, showing both titles and genres."}, {"role": "assistant", "content": "SELECT g1.game_id AS game1_id,\n g1.title AS title1,\n g1.genre AS genre1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.genre AS genre2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND g1.genre <> g2.genre;"}, {"role": "user", "content": "Exclude any pairs where the publisher_id is NULL."}, {"role": "assistant", "content": "SELECT g1.game_id AS game1_id,\n g1.title AS title1,\n g1.genre AS genre1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.genre AS genre2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND g1.genre <> g2.genre\nWHERE g1.publisher_id IS NOT NULL;"}, {"role": "user", "content": "Further restrict to game pairs released within one year of each other."}, {"role": "assistant", "content": "SELECT g1.game_id AS game1_id,\n g1.title AS title1,\n g1.release_date AS release1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.release_date AS release2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND ABS(EXTRACT(YEAR FROM AGE(g1.release_date, g2.release_date))) <= 1\nWHERE g1.publisher_id IS NOT NULL;"}, {"role": "user", "content": "Order the final result by publisher_id and then by the earliest release_date among each pair."}, {"role": "assistant", "content": "SELECT g1.publisher_id,\n g1.game_id AS game1_id,\n g1.title AS title1,\n g1.release_date AS release1,\n g2.game_id AS game2_id,\n g2.title AS title2,\n g2.release_date AS release2\nFROM gaming_technology.games g1\nJOIN gaming_technology.games g2\n ON g1.publisher_id = g2.publisher_id\n AND g1.game_id < g2.game_id\n AND ABS(EXTRACT(YEAR FROM AGE(g1.release_date, g2.release_date))) <= 1\nWHERE g1.publisher_id IS NOT NULL\nORDER BY g1.publisher_id,\n LEAST(g1.release_date, g2.release_date) ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\nCREATE TABLE gaming_technology.servers ( server_id uuid, game_id uuid, server_name text, region text, ip_address text, port integer, current_players integer, max_players integer, status text, last_heartbeat timestamp with time zone )\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( 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": "List all in-game items of type 'Consumable', showing for each item the item name, cost amount, and the total number of players who have that item in their inventory."}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount;"}, {"role": "user", "content": "Can you also show the total quantity held by all players for each item?"}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count, COALESCE(SUM(pi.quantity), 0) AS total_quantity\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount;"}, {"role": "user", "content": "Only include items where the total quantity is at least 10."}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count, COALESCE(SUM(pi.quantity), 0) AS total_quantity\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount\nHAVING COALESCE(SUM(pi.quantity), 0) >= 10;"}, {"role": "user", "content": "Sort the results by total_quantity in descending order."}, {"role": "assistant", "content": "SELECT i.item_name, i.cost_amount, COUNT(DISTINCT pi.player_id) AS player_count, COALESCE(SUM(pi.quantity), 0) AS total_quantity\nFROM gaming_technology.in_game_items i\nLEFT JOIN gaming_technology.player_inventory pi ON i.item_id = pi.item_id\nWHERE i.item_type = 'Consumable'\nGROUP BY i.item_id, i.item_name, i.cost_amount\nHAVING COALESCE(SUM(pi.quantity), 0) >= 10\nORDER BY total_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )\n", "conversations": [{"role": "user", "content": "List all game sessions that lasted longer than 30 minutes. Show the session_id, player_id, game_id, and duration_seconds."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800;"}, {"role": "user", "content": "Now, only include sessions that took place in the year 2023."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800 AND start_time >= '2023-01-01' AND start_time < '2024-01-01';"}, {"role": "user", "content": "Filter these sessions further to only show those with a score greater than 100."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800 AND start_time >= '2023-01-01' AND start_time < '2024-01-01' AND score > 100;"}, {"role": "user", "content": "Order the results by score in descending order and show only the top 5 entries."}, {"role": "assistant", "content": "SELECT session_id, player_id, game_id, duration_seconds FROM gaming_technology.game_sessions WHERE duration_seconds > 1800 AND start_time >= '2023-01-01' AND start_time < '2024-01-01' AND score > 100 ORDER BY score DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\n", "conversations": [{"role": "user", "content": "Show the number of achievements unlocked by each player per month. Display player_id, month (as YYYY-MM), and achievement_count."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM');"}, {"role": "user", "content": "Filter to months where players unlocked at least 5 achievements."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5;"}, {"role": "user", "content": "Sort the results by year_month ascending and then by achievement_count descending."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5\nORDER BY year_month ASC, achievement_count DESC;"}, {"role": "user", "content": "Limit the results to 10 rows."}, {"role": "assistant", "content": "SELECT player_id,\n TO_CHAR(unlocked_at, 'YYYY-MM') AS year_month,\n COUNT(*) AS achievement_count\nFROM gaming_technology.player_achievements\nGROUP BY player_id, TO_CHAR(unlocked_at, 'YYYY-MM')\nHAVING COUNT(*) >= 5\nORDER BY year_month ASC, achievement_count DESC\nLIMIT 10;"}]} +{"system": "You are an 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 gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\n", "conversations": [{"role": "user", "content": "Can you list for each player their most recent and second most recent achievements, showing columns player_id, recent_achievement_id, second_recent_achievement_id, and recent_unlocked_at?"}, {"role": "assistant", "content": "SELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n prev.achievement_id AS second_recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at\nFROM (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn\n FROM gaming_technology.player_achievements\n) recent\nJOIN (\n SELECT player_id, achievement_id,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn\n FROM gaming_technology.player_achievements\n) prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1 AND prev.rn = 2;"}, {"role": "user", "content": "Actually, please exclude any players who have less than two unlock records."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n prev.achievement_id AS second_recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1\n AND prev.rn = 2\n AND recent.cnt >= 2;"}, {"role": "user", "content": "Also include the unlocked_at timestamp of the second most recent achievement."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at,\n prev.achievement_id AS second_recent_achievement_id,\n prev.unlocked_at AS second_recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1\n AND prev.rn = 2\n AND recent.cnt >= 2;"}, {"role": "user", "content": "Finally, order the output by recent_unlocked_at in descending order."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT player_id, achievement_id, unlocked_at,\n ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY unlocked_at DESC) AS rn,\n COUNT(*) OVER (PARTITION BY player_id) AS cnt\n FROM gaming_technology.player_achievements\n)\nSELECT recent.player_id,\n recent.achievement_id AS recent_achievement_id,\n recent.unlocked_at AS recent_unlocked_at,\n prev.achievement_id AS second_recent_achievement_id,\n prev.unlocked_at AS second_recent_unlocked_at\nFROM ranked recent\nJOIN ranked prev\n ON recent.player_id = prev.player_id\nWHERE recent.rn = 1 AND prev.rn = 2 AND recent.cnt >= 2\nORDER BY recent.unlocked_at DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 )\n", "conversations": [{"role": "user", "content": "For each server, what is the earliest and latest start time of its sessions?"}, {"role": "assistant", "content": "SELECT server_id, MIN(start_time), MAX(start_time) FROM gaming_technology.game_sessions GROUP BY server_id;"}, {"role": "user", "content": "Only show servers where the difference between the earliest and latest session is more than 30 days."}, {"role": "assistant", "content": "SELECT server_id, MIN(start_time), MAX(start_time) FROM gaming_technology.game_sessions GROUP BY server_id HAVING MAX(start_time) - MIN(start_time) > INTERVAL '30 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\n", "conversations": [{"role": "user", "content": "List all posts created by user 'U100' in March 2024."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01';"}, {"role": "user", "content": "Only show posts with `media_type` 'video'."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at, media_type FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01' AND media_type = 'video';"}, {"role": "user", "content": "Order them by creation time descending and limit to the top 10."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at, media_type FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01' AND media_type = 'video' ORDER BY created_at DESC LIMIT 10;"}, {"role": "user", "content": "Also, only include posts with `visibility` 'public'."}, {"role": "assistant", "content": "SELECT post_id, user_id, content, created_at, media_type, visibility FROM social_media.posts WHERE user_id = 'U100' AND created_at >= '2024-03-01' AND created_at < '2024-04-01' AND media_type = 'video' AND visibility = 'public' ORDER BY created_at DESC LIMIT 10;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nIndex 'suppliers'. Mapping: { properties: { supplier_id: { type: 'keyword' }, supplier_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, address: { type: 'text' }, country: { type: 'keyword' }, contact_person: { type: 'text', index: false }, contact_email: { type: 'keyword' }, quality_rating: { type: 'float' }, certified_date: { type: 'date' } } }. Document _id can be supplier_id.\n", "conversations": [{"role": "user", "content": "특정 국가의 모든 공급업체 정보를 조회하고 싶습니다. 국가 이름, 공급업체 이름, 주소, 품질 등급을 포함해 주세요."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\"]\n}"}, {"role": "user", "content": "품질 등급이 3.5 이상인 공급업체만 보고 싶습니다. 어떻게 수정해야 하나요?"}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\"]\n}"}, {"role": "user", "content": "인증 날짜가 2020년 이후인 공급업체만 추가로 필터링하고 싶습니다."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n },\n {\n \"range\": {\n \"certified_date\": {\n \"gte\": \"2020-01-01\"\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\", \"certified_date\"]\n}"}, {"role": "user", "content": "결과를 품질 등급 기준으로 내림차순 정렬해 주세요."}, {"role": "assistant", "content": "GET suppliers/_search\n{\n \"query\": {\n \"bool\": {\n \"must\": [\n {\n \"term\": {\n \"country\": \"Korea\"\n }\n },\n {\n \"range\": {\n \"quality_rating\": {\n \"gte\": 3.5\n }\n }\n },\n {\n \"range\": {\n \"certified_date\": {\n \"gte\": \"2020-01-01\"\n }\n }\n }\n ]\n }\n },\n \"_source\": [\"supplier_name\", \"address\", \"country\", \"quality_rating\", \"certified_date\"],\n \"sort\": [\n {\n \"quality_rating\": {\n \"order\": \"desc\"\n }\n }\n ]\n}"}]} +{"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 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 beneficiaries who are listed as 'Sibling' or 'Parent' on policies where their share is between 20 and 60 percent. Include beneficiary_id, policy_id, first_name, last_name, relationship, and percentage_share."}, {"role": "assistant", "content": "SELECT beneficiary_id, policy_id, first_name, last_name, relationship, percentage_share\nFROM insurance.policy_beneficiaries\nWHERE relationship IN ('Sibling', 'Parent')\n AND percentage_share BETWEEN 20 AND 60;"}, {"role": "user", "content": "Actually, could you also include the contact_info for each beneficiary and only show beneficiaries who were added after January 1, 2024?"}, {"role": "assistant", "content": "SELECT beneficiary_id, policy_id, first_name, last_name, relationship, percentage_share, contact_info\nFROM insurance.policy_beneficiaries\nWHERE relationship IN ('Sibling', 'Parent')\n AND percentage_share BETWEEN 20 AND 60\n AND added_at > '2024-01-01';"}, {"role": "user", "content": "Only include beneficiaries where contact_info is not null and sort the results by added_at descending."}, {"role": "assistant", "content": "SELECT beneficiary_id, policy_id, first_name, last_name, relationship, percentage_share, contact_info, added_at\nFROM insurance.policy_beneficiaries\nWHERE relationship IN ('Sibling', 'Parent')\n AND percentage_share BETWEEN 20 AND 60\n AND added_at > '2024-01-01'\n AND contact_info IS NOT NULL\nORDER BY added_at DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nNode Label ':AircraftModel'. Properties: { model_id: String (Constraint: UNIQUE), model_name: String, manufacturer: String, passenger_capacity: Integer, max_range_km: Integer, engine_type: String, wingspan_m: Float, status: String, first_flight_date: Date }. Index on model_id.\nNode Label ':Material'. Properties: { material_id: String (Constraint: UNIQUE), material_name: String, specification: String, description: String, density_kg_m3: Float, tensile_strength_mpa: Integer }. Index on material_id.\nNode Label ':AssemblyLine'. Properties: { line_id: String (Constraint: UNIQUE), line_name: String, location_building: String, location_area: String, capacity_units_per_month: Integer, status: String }. Relationship: (:AssemblyLine)-[:BUILDS_MODEL]->(:AircraftModel {model_id}). Index on line_id.\nNode Label ':AssemblyStep'. Properties: { step_id: String (Constraint: UNIQUE), step_number: Integer, step_name: String, description: String, standard_duration_hours: Float, required_skill_level: String, workstation: String }. Relationship: (:AssemblyLine {line_id})-[:HAS_STEP {sequence: }]->(:AssemblyStep). Index on step_id.\nNode Label ':AircraftBuild'. Properties: { build_id: String (Constraint: UNIQUE), serial_number: String (Constraint: UNIQUE), build_start_date: Datetime, estimated_completion_date: Date, actual_completion_date: Datetime, current_status: String, customer_order_id: String }. Relationships: (:AircraftBuild)-[:IS_MODEL]->(:AircraftModel {model_id}), (:AircraftBuild)-[:ASSEMBLED_ON]->(:AssemblyLine {line_id}). Index on build_id, serial_number, current_status.\nNode Label ':Employee'. Properties: { employee_id: String (Constraint: UNIQUE), first_name: String, last_name: String, job_title: String, skill_certifications: String[], hire_date: Date, employment_status: String }. Relationships: (:Employee)-[:ASSIGNED_TO]->(:AssemblyLine {line_id}), (:Employee)-[:REPORTS_TO]->(:Employee {employee_id as supervisor_id}). Index on employee_id.\nNode Label ':InventoryBatch'. Properties: { inventory_record_id: String (Constraint: UNIQUE), quantity: Integer, location_warehouse: String, location_bin: String, received_date: Datetime, expiry_date: Date, batch_number: String, last_updated: Datetime }. Relationship: (:InventoryBatch)-[:IS_INSTANCE_OF]->(:Component {component_id}). Index on inventory_record_id, component_id.\n", "conversations": [{"role": "user", "content": "Can you help me fetch the inventory details for components associated with a specific aircraft build, including the batch number, quantity, and warehouse location?"}, {"role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"}, {"role": "user", "content": "Can you modify this to show only inventory batches received after a specific date, say June 1, 2023?"}, {"role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01')\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"}, {"role": "user", "content": "What if I also want to exclude batches with quantities less than 10?"}, {"role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01') AND ib.quantity >= 10\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"}]} +{"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 social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\n", "conversations": [{"role": "user", "content": "List all hashtag names and their creation dates."}, {"role": "assistant", "content": "SELECT tag_name, created_at FROM social_media.hashtags;"}, {"role": "user", "content": "Please only include hashtags created in the year 2023."}, {"role": "assistant", "content": "SELECT tag_name, created_at FROM social_media.hashtags WHERE created_at >= '2023-01-01' AND created_at < '2024-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 )\n", "conversations": [{"role": "user", "content": "How many users were registered in each month of 2024?"}, {"role": "assistant", "content": "SELECT date_trunc('month', created_at) AS month, COUNT(*) AS user_count\nFROM social_media.users\nWHERE created_at >= '2024-01-01'\n AND created_at < '2025-01-01'\nGROUP BY month\nORDER BY month;"}]} +{"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 social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List all pairs of hashtags created within the same hour, including both hashtag IDs and their creation timestamps."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.created_at AS created1, h2.hashtag_id AS hashtag2_id, h2.created_at AS created2 FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id;"}, {"role": "user", "content": "Actually, I also want to include the time difference in minutes between the two hashtags."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.created_at AS created1, h2.hashtag_id AS hashtag2_id, h2.created_at AS created2, EXTRACT(EPOCH FROM (h2.created_at - h1.created_at)) / 60 AS diff_minutes FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id;"}, {"role": "user", "content": "Also, filter to only include pairs where both tag names start with the letter 'T'."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.tag_name AS tag1, h2.hashtag_id AS hashtag2_id, h2.tag_name AS tag2, EXTRACT(EPOCH FROM (h2.created_at - h1.created_at)) / 60 AS diff_minutes FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id WHERE h1.tag_name LIKE 'T%' AND h2.tag_name LIKE 'T%';"}, {"role": "user", "content": "Finally, order the results by the earlier creation timestamp in descending order."}, {"role": "assistant", "content": "SELECT h1.hashtag_id AS hashtag1_id, h1.tag_name AS tag1, h2.hashtag_id AS hashtag2_id, h2.tag_name AS tag2, EXTRACT(EPOCH FROM (h2.created_at - h1.created_at)) / 60 AS diff_minutes FROM hashtags h1 JOIN hashtags h2 ON date_trunc('hour', h1.created_at) = date_trunc('hour', h2.created_at) AND h1.hashtag_id < h2.hashtag_id WHERE h1.tag_name LIKE 'T%' AND h2.tag_name LIKE 'T%' ORDER BY LEAST(h1.created_at, h2.created_at) DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_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 (doctor_id) )\nCREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, appointment_time timestamp with time zone NOT NULL, duration_minutes integer NOT NULL, reason text, status character varying(32) NOT NULL, location_id character varying(64), notes text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\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": "Can you show me the count of new doctors added each month in 2023? Return the month and number of doctors."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', created_at) AS month, COUNT(*) AS doctor_count\nFROM healthcare.doctors\nWHERE created_at >= '2023-01-01' AND created_at < '2024-01-01'\nGROUP BY DATE_TRUNC('month', created_at);"}, {"role": "user", "content": "Actually, include the month as the first day of the month and order the results by month in descending order."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', created_at)::date AS month_start, COUNT(*) AS doctor_count\nFROM healthcare.doctors\nWHERE created_at >= '2023-01-01' AND created_at < '2024-01-01'\nGROUP BY DATE_TRUNC('month', created_at)\nORDER BY month_start DESC;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\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": "What is the average number of refills allowed across all prescriptions?"}, {"role": "assistant", "content": "SELECT AVG(refills_allowed) FROM healthcare.prescriptions;"}]} -{"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 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 pairs of distinct locations in the same city that share the same location type. Show both location IDs, names, city, and the shared type."}, {"role": "assistant", "content": "SELECT L1.location_id AS location1_id, L1.name AS location1_name, L2.location_id AS location2_id, L2.name AS location2_name, L1.city AS shared_city, L1.type AS shared_type FROM transportation.locations AS L1 JOIN transportation.locations AS L2 ON L1.city = L2.city AND L1.type = L2.type WHERE L1.location_id < L2.location_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n// Use Hashes for ticket details. Key format: ticket:\n// HSET ticket:tkt_1a2b ticket_id \"tkt_1a2b\" booking_id \"book_zyx\" car_id \"car_abc\" seat_number \"12A\" ... is_checked_in 0 ...\n\n// To link tickets to bookings (optional):\n// SADD booking:book_zyx:tickets ticket:tkt_1a2b\n// Use Hashes for maintenance record details. Key format: maintenance_record:\n// HSET maintenance_record:maint_rec_001 record_id \"maint_rec_001\" asset_id \"train_789\" asset_type \"Train\" ... status \"Completed\"\n\n// To link records to assets (optional):\n// SADD train:train_789:maintenance maintenance_record:maint_rec_001\n// SADD platform:plat_123:maintenance maintenance_record:maint_rec_002\n", "conversations": [{"role": "user", "content": "\u7279\u5b9a\u306e\u5217\u8ecaID 'train_789' \u306b\u95a2\u9023\u3059\u308b\u3059\u3079\u3066\u306e\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u8a18\u9332\u306e\u8a73\u7d30\u3092\u53d6\u5f97\u3059\u308b\u306e\u3092\u624b\u4f1d\u3063\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SMEMBERS train:train_789:maintenance\nHGETALL maintenance_record:"}]} -{"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 transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )\n", "conversations": [{"role": "user", "content": "Show me pairs of trip IDs that used the same vehicle."}, {"role": "assistant", "content": "SELECT\n t1.trip_id AS trip1_id,\n t2.trip_id AS trip2_id\nFROM transportation.trips AS t1\nJOIN transportation.trips AS t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id;"}, {"role": "user", "content": "Now, filter this list to only include pairs where both trips have a 'Completed' status."}, {"role": "assistant", "content": "SELECT\n t1.trip_id AS trip1_id,\n t2.trip_id AS trip2_id\nFROM transportation.trips AS t1\nJOIN transportation.trips AS t2\n ON t1.vehicle_id = t2.vehicle_id\n AND t1.trip_id < t2.trip_id\nWHERE\n t1.status = 'Completed' AND t2.status = 'Completed';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )\nCREATE TABLE government_services.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.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "For each citizen who has made a payment for an application that is still in 'Processing' status, list their full name, application_id, payment_id, amount, currency, and the application status."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS full_name,\n a.application_id,\n p.payment_id,\n p.amount,\n p.currency,\n a.status AS application_status\nFROM government_services.citizens c\nJOIN government_services.applications a ON c.citizen_id = a.citizen_id\nJOIN government_services.payments p ON a.application_id = p.application_id\nWHERE a.status = 'Processing';"}]} -{"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 legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List each client_id, first_name, last_name, and the sum of total_amount for all of their invoices."}, {"role": "assistant", "content": "SELECT c.client_id,\n c.first_name,\n c.last_name,\n SUM(i.total_amount) AS total_invoiced\nFROM legal_services.clients c\nJOIN legal_services.invoices i ON i.client_id = c.client_id\nGROUP BY c.client_id, c.first_name, c.last_name;"}, {"role": "user", "content": "Now show only clients whose total_invoiced exceeds 20000 and include the count of invoices as invoice_count."}, {"role": "assistant", "content": "SELECT c.client_id,\n c.first_name,\n c.last_name,\n SUM(i.total_amount) AS total_invoiced,\n COUNT(i.invoice_id) AS invoice_count\nFROM legal_services.clients c\nJOIN legal_services.invoices i ON i.client_id = c.client_id\nGROUP BY c.client_id, c.first_name, c.last_name\nHAVING SUM(i.total_amount) > 20000;"}]} -{"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 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": "Show me all insurance products with coverage details mentioning 'liability', along with their product names and base premiums."}, {"role": "assistant", "content": "SELECT product_name, base_premium, coverage_details FROM insurance.insurance_products WHERE coverage_details LIKE '%liability%';"}, {"role": "user", "content": "Now filter to only show active products with base premium between $100 and $500."}, {"role": "assistant", "content": "SELECT product_name, base_premium, coverage_details FROM insurance.insurance_products WHERE coverage_details LIKE '%liability%' AND is_active = true AND base_premium BETWEEN 100 AND 500;"}, {"role": "user", "content": "I also want to see the count of these products by product type."}, {"role": "assistant", "content": "SELECT product_type, COUNT(*) as product_count FROM insurance.insurance_products WHERE coverage_details LIKE '%liability%' AND is_active = true AND base_premium BETWEEN 100 AND 500 GROUP BY product_type;"}, {"role": "user", "content": "Finally, show me the average base premium for these liability products by product type, ordered from highest to lowest average."}, {"role": "assistant", "content": "SELECT product_type, AVG(base_premium) as avg_base_premium FROM insurance.insurance_products WHERE coverage_details LIKE '%liability%' AND is_active = true AND base_premium BETWEEN 100 AND 500 GROUP BY product_type ORDER BY avg_base_premium DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\nCREATE TABLE legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Find the total number of distinct lawyers and distinct documents in the database."}, {"role": "assistant", "content": "SELECT (SELECT COUNT(DISTINCT lawyer_id) FROM legal_services.lawyers) AS distinct_lawyer_count, (SELECT COUNT(DISTINCT document_id) FROM legal_services.documents) AS distinct_document_count;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE 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 token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n", "conversations": [{"role": "user", "content": "List all wallet addresses holding NFT contract '0xbbbb...' and token ID '99'."}, {"role": "assistant", "content": "SELECT wallet_address, amount\nFROM nft_holders\nWHERE contract_address = '0xbbbb...'\n AND token_id = '99';"}, {"role": "user", "content": "How many unique holders are there?"}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT wallet_address) AS unique_holders\nFROM nft_holders\nWHERE contract_address = '0xbbbb...'\n AND token_id = '99';"}, {"role": "user", "content": "Only include wallets holding more than one token."}, {"role": "assistant", "content": "SELECT wallet_address, amount\nFROM nft_holders\nWHERE contract_address = '0xbbbb...'\n AND token_id = '99'\n AND CAST(amount AS numeric) > 1;"}, {"role": "user", "content": "Sort the result by amount descending and limit to top 5."}, {"role": "assistant", "content": "SELECT wallet_address, amount\nFROM nft_holders\nWHERE contract_address = '0xbbbb...'\n AND token_id = '99'\n AND CAST(amount AS numeric) > 1\nORDER BY CAST(amount AS numeric) DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Find pairs of user IDs (A, B) such that user A follows user B, and user B also follows user A (mutual follows). List user A's ID and user B's ID."}, {"role": "assistant", "content": "SELECT T1.follower_user_id AS user_a, T1.following_user_id AS user_b FROM social_media.follows AS T1 JOIN social_media.follows AS T2 ON T1.follower_user_id = T2.following_user_id AND T1.following_user_id = T2.follower_user_id;"}, {"role": "user", "content": "Only show pairs where user B started following user A after user A started following user B. Also include the follow dates for both."}, {"role": "assistant", "content": "SELECT T1.follower_user_id AS user_a, T1.following_user_id AS user_b, T1.created_at AS user_a_follows_b_date, T2.created_at AS user_b_follows_a_date FROM social_media.follows AS T1 JOIN social_media.follows AS T2 ON T1.follower_user_id = T2.following_user_id AND T1.following_user_id = T2.follower_user_id WHERE T2.created_at > T1.created_at;"}, {"role": "user", "content": "Order the results by the date user B followed user A, from oldest to newest."}, {"role": "assistant", "content": "SELECT T1.follower_user_id AS user_a, T1.following_user_id AS user_b, T1.created_at AS user_a_follows_b_date, T2.created_at AS user_b_follows_a_date FROM social_media.follows AS T1 JOIN social_media.follows AS T2 ON T1.follower_user_id = T2.following_user_id AND T1.following_user_id = T2.follower_user_id WHERE T2.created_at > T1.created_at ORDER BY user_b_follows_a_date ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\n", "conversations": [{"role": "user", "content": "How many lawyers are there in each specialization, and what is the count per specialization?"}, {"role": "assistant", "content": "SELECT specialization,\n COUNT(*) AS lawyer_count\nFROM legal_services.lawyers\nGROUP BY specialization;"}]} -{"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 social_media.users ( user_id.text, username.text, email.text, password_hash.text, full_name.text, profile_picture_url.text, bio.text, location.text, created_at.timestamp, updated_at.timestamp, is_verified.boolean )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.user_settings ( setting_id.text, user_id.text, theme.text, email_notifications_enabled.boolean, push_notifications_enabled.boolean, private_profile.boolean, updated_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the usernames and the group names of group chats where each user has posted at least one post containing a hashtag."}, {"role": "assistant", "content": "SELECT u.username, c.group_name\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id\nJOIN social_media.post_hashtags ph ON p.post_id = ph.post_id\nJOIN social_media.conversations c ON p.user_id = u.user_id AND c.is_group_chat = TRUE\nGROUP BY u.username, c.group_name;"}, {"role": "user", "content": "Can you also show when each group chat was created?"}, {"role": "assistant", "content": "SELECT u.username, c.group_name, c.created_at\nFROM social_media.users u\nJOIN social_media.posts p ON u.user_id = p.user_id\nJOIN social_media.post_hashtags ph ON p.post_id = ph.post_id\nJOIN social_media.conversations c ON p.user_id = u.user_id AND c.is_group_chat = TRUE\nGROUP BY u.username, c.group_name, c.created_at;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 the usernames and registration dates for all users whose email ends with '@gmail.com'."}, {"role": "assistant", "content": "SELECT username, created_at FROM web3.users WHERE email LIKE '%@gmail.com';"}, {"role": "user", "content": "Actually, can you also include how many such users there are in total in the result?"}, {"role": "assistant", "content": "SELECT username, created_at, COUNT(*) OVER() AS total_gmail_users FROM web3.users WHERE email LIKE '%@gmail.com';"}]} -{"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 social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text, tag_name text, created_at timestamp )\nCREATE TABLE social_media.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )\nCREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id text, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve all public posts that have geolocation coordinates specified, showing post_id, user_id, location_lat, location_lon, ordered by created_at descending."}, {"role": "assistant", "content": "SELECT post_id, user_id, location_lat, location_lon\nFROM social_media.posts\nWHERE visibility = 'public'\n AND location_lat IS NOT NULL\n AND location_lon IS NOT NULL\nORDER BY created_at DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\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": "How many notifications are there for each distinct notification type?"}, {"role": "assistant", "content": "SELECT notification_type, COUNT(*) FROM social_media.notifications GROUP BY notification_type;"}]} +{"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 healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\n", "conversations": [{"role": "user", "content": "List the medication_id, medication_name, and description for all medications whose generic_name starts with 'A'."}, {"role": "assistant", "content": "SELECT medication_id, medication_name, description\nFROM healthcare.medications\nWHERE generic_name LIKE 'A%';"}]} +{"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 healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n", "conversations": [{"role": "user", "content": "Show me a list of all patient names along with the full names of their doctors for appointments scheduled in February 2024."}, {"role": "assistant", "content": "SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nWHERE a.status = 'Scheduled' AND DATE_TRUNC('month', a.appointment_time) = DATE '2024-02-01';"}, {"role": "user", "content": "Actually, can you also include the appointment time for each result?"}, {"role": "assistant", "content": "SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nWHERE a.status = 'Scheduled' AND DATE_TRUNC('month', a.appointment_time) = DATE '2024-02-01';"}, {"role": "user", "content": "I got an error: column 'appointment_time' does not exist. Can you check and fix the query?"}, {"role": "assistant", "content": "SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nWHERE a.status = 'Scheduled' AND DATE_TRUNC('month', a.appointment_time) = DATE '2024-02-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\n", "conversations": [{"role": "user", "content": "List appointment IDs, patient first and last names, and their chief complaint for appointments that have an associated medical record."}, {"role": "assistant", "content": "SELECT a.appointment_id, p.first_name, p.last_name, mr.chief_complaint\nFROM healthcare.appointments a\nJOIN healthcare.medical_records mr\n ON a.appointment_id = mr.appointment_id\nJOIN healthcare.patients p\n ON a.patient_id = p.patient_id;"}, {"role": "user", "content": "Also include the appointment_time and only include records from the past 30 days."}, {"role": "assistant", "content": "SELECT a.appointment_id, p.first_name, p.last_name, mr.chief_complaint, a.appointment_time\nFROM healthcare.appointments a\nJOIN healthcare.medical_records mr\n ON a.appointment_id = mr.appointment_id\nJOIN healthcare.patients p\n ON a.patient_id = p.patient_id\nWHERE mr.record_date >= NOW() - INTERVAL '30 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n", "conversations": [{"role": "user", "content": "Show me a list of all appointments and the number of prescriptions that were issued on the same day for each appointment."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time::date AS appointment_date,\n COUNT(pr.prescription_id) AS prescriptions_count\nFROM healthcare.appointments a\nLEFT JOIN healthcare.medical_records mr ON mr.appointment_id = a.appointment_id\nLEFT JOIN healthcare.prescriptions pr ON pr.record_id = mr.record_id\nGROUP BY a.appointment_id, a.appointment_time::date;"}, {"role": "user", "content": "Only include appointments where at least one prescription was made that day, and show the full names of the patient and doctor for each appointment."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.appointment_time::date AS appointment_date,\n p.first_name || ' ' || p.last_name AS patient_full_name,\n d.first_name || ' ' || d.last_name AS doctor_full_name,\n COUNT(pr.prescription_id) AS prescriptions_count\nFROM healthcare.appointments a\nJOIN healthcare.patients p ON a.patient_id = p.patient_id\nJOIN healthcare.doctors d ON a.doctor_id = d.doctor_id\nLEFT JOIN healthcare.medical_records mr ON mr.appointment_id = a.appointment_id\nLEFT JOIN healthcare.prescriptions pr ON pr.record_id = mr.record_id\nGROUP BY a.appointment_id, a.appointment_time::date, p.first_name, p.last_name, d.first_name, d.last_name\nHAVING COUNT(pr.prescription_id) > 0;"}]} +{"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 healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\n", "conversations": [{"role": "user", "content": "List the description and diagnosis date for all diagnoses that are marked as chronic and were made in the year 2023."}, {"role": "assistant", "content": "SELECT description, diagnosis_date FROM healthcare.diagnoses WHERE is_chronic = true AND diagnosis_date BETWEEN '2023-01-01' AND '2023-12-31';"}, {"role": "user", "content": "Also include the patient ID and order the results by diagnosis date ascending."}, {"role": "assistant", "content": "SELECT patient_id, description, diagnosis_date FROM healthcare.diagnoses WHERE is_chronic = true AND diagnosis_date BETWEEN '2023-01-01' AND '2023-12-31' ORDER BY diagnosis_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records ( record_id.text, patient_id.text, appointment_id.text, doctor_id.text, record_date.timestamp, chief_complaint.text, present_illness_history.text, past_medical_history.text, physical_examination_notes.text, assessment.text, treatment_plan.text, vitals.json, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n", "conversations": [{"role": "user", "content": "List all prescriptions with medication details. Return prescription_id, patient full name, medication_name, and prescription_date."}, {"role": "assistant", "content": "SELECT pr.prescription_id,\n p.first_name || ' ' || p.last_name AS patient_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.prescriptions pr\nJOIN healthcare.patients p ON pr.patient_id = p.patient_id\nJOIN healthcare.medications m ON pr.medication_id = m.medication_id;"}, {"role": "user", "content": "Filter to only include prescriptions where the quantity_dispensed is greater than 30."}, {"role": "assistant", "content": "SELECT pr.prescription_id,\n p.first_name || ' ' || p.last_name AS patient_name,\n m.medication_name,\n pr.prescription_date\nFROM healthcare.prescriptions pr\nJOIN healthcare.patients p ON pr.patient_id = p.patient_id\nJOIN healthcare.medications m ON pr.medication_id = m.medication_id\nWHERE pr.quantity_dispensed > 30;"}]} +{"system": "You are an 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 healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n", "conversations": [{"role": "user", "content": "List each patient's first and last name along with the insurance plan name they are enrolled in, including only primary policies. Return patient_id, first_name, last_name, and plan_name."}, {"role": "assistant", "content": "SELECT p.patient_id,\n p.first_name,\n p.last_name,\n ip.plan_name\nFROM healthcare.patients AS p\nJOIN healthcare.patient_insurance AS pi\n ON p.patient_id = pi.patient_id AND pi.is_primary = true\nJOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id;"}, {"role": "user", "content": "Now limit to plans with plan_type 'EPO' and sort by patient last name ascending."}, {"role": "assistant", "content": "SELECT p.patient_id,\n p.first_name,\n p.last_name,\n ip.plan_name\nFROM healthcare.patients AS p\nJOIN healthcare.patient_insurance AS pi\n ON p.patient_id = pi.patient_id AND pi.is_primary = true\nJOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id\nWHERE ip.plan_type = 'EPO'\nORDER BY p.last_name ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_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 (doctor_id) )\nCREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, appointment_id character varying(64) UNIQUE, doctor_id character varying(64) NOT NULL, record_date timestamp with time zone NOT NULL, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals jsonb, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n", "conversations": [{"role": "user", "content": "Show a list of diagnoses along with the chief complaint noted in the corresponding medical record. Display diagnosis description, diagnosis date, and the chief complaint."}, {"role": "assistant", "content": "SELECT T1.description, T1.diagnosis_date, T2.chief_complaint FROM healthcare.diagnoses AS T1 JOIN healthcare.medical_records AS T2 ON T1.record_id = T2.record_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\nCREATE TABLE healthcare.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 each patient's policy number, the associated insurance plan ID, and any medications they have been prescribed, including the medication ID and prescription date."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.plan_id, pr.medication_id, pr.prescription_date\nFROM healthcare.patient_insurance pi\nJOIN healthcare.prescriptions pr ON pi.patient_id = pr.patient_id;"}, {"role": "user", "content": "Only include prescriptions that were made after the insurance policy's effective date."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.plan_id, pr.medication_id, pr.prescription_date\nFROM healthcare.patient_insurance pi\nJOIN healthcare.prescriptions pr ON pi.patient_id = pr.patient_id\nWHERE pr.prescription_date >= pi.effective_date;"}, {"role": "user", "content": "Add the expiration date of the insurance policy and only show records where the prescription was made before the policy expired."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.plan_id, pi.expiration_date, pr.medication_id, pr.prescription_date\nFROM healthcare.patient_insurance pi\nJOIN healthcare.prescriptions pr ON pi.patient_id = pr.patient_id\nWHERE pr.prescription_date >= pi.effective_date\n AND (pi.expiration_date IS NULL OR pr.prescription_date < pi.expiration_date);"}]} +{"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 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 )\n", "conversations": [{"role": "user", "content": "List all medical records along with the chief complaint and record date for patients who had their medical record created after March 1, 2023 and whose record was created by doctor with ID 'doctor_123'."}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01';"}, {"role": "user", "content": "Can you also include the treatment plan for each record in the result?"}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date, treatment_plan FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01';"}, {"role": "user", "content": "Actually, I only want records where the assessment field is not null."}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date, treatment_plan FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01' AND assessment IS NOT NULL;"}, {"role": "user", "content": "Now, restrict the results to records where the chief complaint contains the word 'cough'."}, {"role": "assistant", "content": "SELECT record_id, patient_id, chief_complaint, record_date, treatment_plan FROM healthcare.medical_records WHERE doctor_id = 'doctor_123' AND record_date > '2023-03-01' AND assessment IS NOT NULL AND chief_complaint ILIKE '%cough%';"}]} +{"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 healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "Show me all primary insurance policies along with their policy numbers and effective dates for patient with ID 'patient_555'."}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE;"}, {"role": "user", "content": "Can you also show the group number for each policy?"}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date, group_number FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE;"}, {"role": "user", "content": "I only want to see those policies that are still active."}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date, group_number FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE AND expiration_date > CURRENT_DATE;"}, {"role": "user", "content": "Actually, can you order the results by expiration_date, with the soonest expiration first?"}, {"role": "assistant", "content": "SELECT patient_insurance_id, policy_number, effective_date, group_number FROM healthcare.patient_insurance WHERE patient_id = 'patient_555' AND is_primary = TRUE AND expiration_date > CURRENT_DATE ORDER BY expiration_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )\n", "conversations": [{"role": "user", "content": "Can you show me the total number of diagnosis records for each doctor, along with the doctor's ID? Please include only those diagnoses marked as 'chronic'."}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS total_chronic_diagnoses FROM healthcare.diagnoses WHERE is_chronic = TRUE GROUP BY doctor_id;"}, {"role": "user", "content": "Now, can you also include the average number of chronic diagnoses per patient for each doctor in the results?"}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS total_chronic_diagnoses, COUNT(*)::FLOAT / COUNT(DISTINCT patient_id) AS avg_chronic_per_patient FROM healthcare.diagnoses WHERE is_chronic = TRUE GROUP BY doctor_id;"}, {"role": "user", "content": "Please filter the results to only include doctors with at least 5 chronic diagnoses."}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS total_chronic_diagnoses, COUNT(*)::FLOAT / COUNT(DISTINCT patient_id) AS avg_chronic_per_patient FROM healthcare.diagnoses WHERE is_chronic = TRUE GROUP BY doctor_id HAVING COUNT(*) >= 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all medical records created by doctor 'doctor_001' for patients who had their last medical record on or after '2024-01-01', including record_id, patient_id, record_date, chief_complaint, and doctor_id."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.patient_id, mr.record_date, mr.chief_complaint, mr.doctor_id\nFROM healthcare.medical_records mr\nJOIN (\n SELECT patient_id, MAX(record_date) AS last_record_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) last_rec ON mr.patient_id = last_rec.patient_id\nWHERE mr.doctor_id = 'doctor_001' AND last_rec.last_record_date >= '2024-01-01';"}, {"role": "user", "content": "Please refine the results to only include records where the 'assessment' field is not null."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.patient_id, mr.record_date, mr.chief_complaint, mr.doctor_id\nFROM healthcare.medical_records mr\nJOIN (\n SELECT patient_id, MAX(record_date) AS last_record_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) last_rec ON mr.patient_id = last_rec.patient_id\nWHERE mr.doctor_id = 'doctor_001' AND last_rec.last_record_date >= '2024-01-01' AND mr.assessment IS NOT NULL;"}, {"role": "user", "content": "I received too many results. Can you only show records where 'treatment_plan' is also not null?"}, {"role": "assistant", "content": "SELECT mr.record_id, mr.patient_id, mr.record_date, mr.chief_complaint, mr.doctor_id\nFROM healthcare.medical_records mr\nJOIN (\n SELECT patient_id, MAX(record_date) AS last_record_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) last_rec ON mr.patient_id = last_rec.patient_id\nWHERE mr.doctor_id = 'doctor_001' AND last_rec.last_record_date >= '2024-01-01' AND mr.assessment IS NOT NULL AND mr.treatment_plan IS NOT NULL;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "List the medication IDs and names for all entries where the description is missing or empty."}, {"role": "assistant", "content": "SELECT medication_id, medication_name FROM healthcare.medications WHERE description IS NULL OR description = '';"}, {"role": "user", "content": "For those medications, please also show the manufacturer and sort the results by medication name in ascending order."}, {"role": "assistant", "content": "SELECT medication_id, medication_name, manufacturer FROM healthcare.medications WHERE description IS NULL OR description = '' ORDER BY medication_name ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "I need to find patients who received prescriptions within 7 days after their latest appointment. Show patient_id, first and last name, appointment_time, prescription_date, and medication_name."}, {"role": "assistant", "content": "WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id"}, {"role": "user", "content": "Actually, restrict it to prescriptions where dosage contains 'mg'."}, {"role": "assistant", "content": "WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\n AND pr.dosage LIKE '%mg%'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id"}, {"role": "user", "content": "Also, sort the results by prescription_date descending and limit to 5."}, {"role": "assistant", "content": "WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\n AND pr.dosage LIKE '%mg%'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id\nORDER BY pr.prescription_date DESC\nLIMIT 5"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "Show a list of patients along with their most recent diagnoses, including patient ID, diagnosis description, and the diagnosis date."}, {"role": "assistant", "content": "SELECT d.patient_id, d.description AS diagnosis_description, d.diagnosis_date FROM healthcare.diagnoses d INNER JOIN (SELECT patient_id, MAX(diagnosis_date) AS latest_date FROM healthcare.diagnoses GROUP BY patient_id) latest ON d.patient_id = latest.patient_id AND d.diagnosis_date = latest.latest_date;"}, {"role": "user", "content": "Add the doctor's full name who made each diagnosis to the results."}, {"role": "assistant", "content": "SELECT d.patient_id, doc.first_name || ' ' || doc.last_name AS doctor_full_name, d.description AS diagnosis_description, d.diagnosis_date FROM healthcare.diagnoses d INNER JOIN (SELECT patient_id, MAX(diagnosis_date) AS latest_date FROM healthcare.diagnoses GROUP BY patient_id) latest ON d.patient_id = latest.patient_id AND d.diagnosis_date = latest.latest_date INNER JOIN healthcare.doctors doc ON d.doctor_id = doc.doctor_id;"}, {"role": "user", "content": "Could you also include the diagnosis code in the output?"}, {"role": "assistant", "content": "SELECT d.patient_id, doc.first_name || ' ' || doc.last_name AS doctor_full_name, d.diagnosis_code, d.description AS diagnosis_description, d.diagnosis_date FROM healthcare.diagnoses d INNER JOIN (SELECT patient_id, MAX(diagnosis_date) AS latest_date FROM healthcare.diagnoses GROUP BY patient_id) latest ON d.patient_id = latest.patient_id AND d.diagnosis_date = latest.latest_date INNER JOIN healthcare.doctors doc ON d.doctor_id = doc.doctor_id;"}]} {"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id.text, first_name.text, last_name.text, date_of_birth.date, gender.text, address.text, phone_number.text, email.text, emergency_contact_name.text, emergency_contact_phone.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "I need a count of appointments per patient that took place between '2024-04-01' and '2024-04-30', showing patient_id, first_name, last_name, and the total number of appointments."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, COUNT(a.appointment_id) AS appointment_count\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nWHERE a.appointment_time BETWEEN '2024-04-01' AND '2024-04-30'\nGROUP BY p.patient_id, p.first_name, p.last_name;"}, {"role": "user", "content": "Only include patients who had at least 2 appointments in that period."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, COUNT(a.appointment_id) AS appointment_count\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nWHERE a.appointment_time BETWEEN '2024-04-01' AND '2024-04-30'\nGROUP BY p.patient_id, p.first_name, p.last_name\nHAVING COUNT(a.appointment_id) >= 2;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "List all staff members who have responded to at least one review in the last 6 months, including their first and last names and the count of responses."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, COUNT(r.review_id) AS response_count\nFROM hospitality_technology.reviews AS r\nJOIN hospitality_technology.staff AS s\n ON r.response_staff_id = s.staff_id\nWHERE r.response_date >= CURRENT_DATE - INTERVAL '6 months'\nGROUP BY s.staff_id, s.first_name, s.last_name;"}, {"role": "user", "content": "Actually, only include responses to public reviews."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name, COUNT(r.review_id) AS response_count\nFROM hospitality_technology.reviews AS r\nJOIN hospitality_technology.staff AS s\n ON r.response_staff_id = s.staff_id\nWHERE r.response_date >= CURRENT_DATE - INTERVAL '6 months'\n AND r.is_public = TRUE\nGROUP BY s.staff_id, s.first_name, s.last_name;"}, {"role": "user", "content": "Also include the average response time in days for each staff member."}, {"role": "assistant", "content": "SELECT s.staff_id, s.first_name, s.last_name,\n COUNT(r.review_id) AS response_count,\n AVG(EXTRACT(EPOCH FROM (r.response_date - r.review_date)) / 86400) AS avg_response_days\nFROM hospitality_technology.reviews AS r\nJOIN hospitality_technology.staff AS s\n ON r.response_staff_id = s.staff_id\nWHERE r.response_date >= CURRENT_DATE - INTERVAL '6 months'\n AND r.is_public = TRUE\nGROUP BY s.staff_id, s.first_name, s.last_name;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )\nCREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "For each service location in Texas, provide the location name, city, and the number of appointments scheduled there by verified citizens."}, {"role": "assistant", "content": "SELECT sl.location_name, sl.city, COUNT(a.appointment_id) AS appointment_count\nFROM government_services.service_locations sl\nJOIN government_services.appointments a ON sl.location_id = a.location_id\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id AND c.is_verified = TRUE\nWHERE sl.state = 'Texas'\nGROUP BY sl.location_id, sl.location_name, sl.city;"}]} -{"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 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": "Which staff members have never been assigned a manager? List their full names and property IDs."}, {"role": "assistant", "content": "SELECT staff_id, first_name, last_name, property_id\nFROM hospitality_technology.staff\nWHERE manager_id IS NULL;"}, {"role": "user", "content": "Also include their work email and only show currently active staff."}, {"role": "assistant", "content": "SELECT staff_id, first_name, last_name, property_id, work_email\nFROM hospitality_technology.staff\nWHERE manager_id IS NULL AND is_active = true;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "How many reservations have been booked each month in 2023?"}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', created_at) AS month,\n COUNT(*) AS reservation_count\nFROM hospitality_technology.reservations\nWHERE created_at >= '2023-01-01' AND created_at < '2024-01-01'\nGROUP BY month;"}, {"role": "user", "content": "Actually, exclude reservations with status 'Canceled' and order by month."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', created_at) AS month,\n COUNT(*) AS reservation_count\nFROM hospitality_technology.reservations\nWHERE created_at >= '2023-01-01'\n AND created_at < '2024-01-01'\n AND status <> 'Canceled'\nGROUP BY month\nORDER BY month;"}]} -{"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 healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\n", "conversations": [{"role": "user", "content": "Find pairs of patients who share the same last name. Show the patient IDs, full names, and the shared last name."}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient1_id, p1.first_name AS patient1_first_name, p1.last_name AS patient1_last_name, p2.patient_id AS patient2_id, p2.first_name AS patient2_first_name, p2.last_name AS patient2_last_name, p1.last_name AS shared_last_name FROM healthcare.patients p1 JOIN healthcare.patients p2 ON p1.last_name = p2.last_name AND p1.patient_id < p2.patient_id;"}, {"role": "user", "content": "Now, only include pairs where they also share the same date of birth."}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient1_id, p1.first_name AS patient1_first_name, p1.last_name AS patient1_last_name, p2.patient_id AS patient2_id, p2.first_name AS patient2_first_name, p2.last_name AS patient2_last_name, p1.last_name AS shared_last_name, p1.date_of_birth AS shared_date_of_birth FROM healthcare.patients p1 JOIN healthcare.patients p2 ON p1.last_name = p2.last_name AND p1.date_of_birth = p2.date_of_birth AND p1.patient_id < p2.patient_id;"}, {"role": "user", "content": "Could you also restrict the results to only include pairs where at least one patient has a non-null phone number?"}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient1_id, p1.first_name AS patient1_first_name, p1.last_name AS patient1_last_name, p2.patient_id AS patient2_id, p2.first_name AS patient2_first_name, p2.last_name AS patient2_last_name, p1.last_name AS shared_last_name, p1.date_of_birth AS shared_date_of_birth FROM healthcare.patients p1 JOIN healthcare.patients p2 ON p1.last_name = p2.last_name AND p1.date_of_birth = p2.date_of_birth AND p1.patient_id < p2.patient_id WHERE p1.phone_number IS NOT NULL OR p2.phone_number IS NOT NULL;"}, {"role": "user", "content": "Finally, sort the results by shared last name, then date of birth, ascending."}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient1_id, p1.first_name AS patient1_first_name, p1.last_name AS patient1_last_name, p2.patient_id AS patient2_id, p2.first_name AS patient2_first_name, p2.last_name AS patient2_last_name, p1.last_name AS shared_last_name, p1.date_of_birth AS shared_date_of_birth FROM healthcare.patients p1 JOIN healthcare.patients p2 ON p1.last_name = p2.last_name AND p1.date_of_birth = p2.date_of_birth AND p1.patient_id < p2.patient_id WHERE p1.phone_number IS NOT NULL OR p2.phone_number IS NOT NULL ORDER BY shared_last_name ASC, shared_date_of_birth ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id.text, first_name.text, last_name.text, date_of_birth.date, gender.text, address.text, phone_number.text, email.text, emergency_contact_name.text, emergency_contact_phone.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n", "conversations": [{"role": "user", "content": "List each doctor's ID, first name, last name, and the total number of appointments they have. Display columns doctor_id, first_name, last_name, and appointment_count."}, {"role": "assistant", "content": "SELECT d.doctor_id,\n d.first_name,\n d.last_name,\n COUNT(a.appointment_id) AS appointment_count\nFROM healthcare.doctors d\nLEFT JOIN healthcare.appointments a\n ON d.doctor_id = a.doctor_id\nGROUP BY d.doctor_id, d.first_name, d.last_name;"}, {"role": "user", "content": "Actually, only include doctors with more than 5 appointments and sort by appointment_count descending."}, {"role": "assistant", "content": "SELECT d.doctor_id,\n d.first_name,\n d.last_name,\n COUNT(a.appointment_id) AS appointment_count\nFROM healthcare.doctors d\nLEFT JOIN healthcare.appointments a\n ON d.doctor_id = a.doctor_id\nGROUP BY d.doctor_id, d.first_name, d.last_name\nHAVING COUNT(a.appointment_id) > 5\nORDER BY appointment_count DESC;"}, {"role": "user", "content": "Add each doctor's specialty to the output as well."}, {"role": "assistant", "content": "SELECT d.doctor_id,\n d.first_name,\n d.last_name,\n d.specialty,\n COUNT(a.appointment_id) AS appointment_count\nFROM healthcare.doctors d\nLEFT JOIN healthcare.appointments a\n ON d.doctor_id = a.doctor_id\nGROUP BY d.doctor_id, d.first_name, d.last_name, d.specialty\nHAVING COUNT(a.appointment_id) > 5\nORDER BY appointment_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n", "conversations": [{"role": "user", "content": "List collection name, contract address, token count, and floor price for NFT collections on the Ethereum blockchain."}, {"role": "assistant", "content": "SELECT name, contract_address, token_count, floor_price FROM nft_collections WHERE blockchain = 'Ethereum';"}, {"role": "user", "content": "Also include the average rarity score for NFTs within each collection."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.token_count, nc.floor_price, AVG(nm.rarity_score) AS avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' GROUP BY nc.name, nc.contract_address, nc.token_count, nc.floor_price;"}, {"role": "user", "content": "Filter the results to only include collections with an average rarity score above 75."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.token_count, nc.floor_price, AVG(nm.rarity_score) AS avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' GROUP BY nc.name, nc.contract_address, nc.token_count, nc.floor_price HAVING AVG(nm.rarity_score) > 75;"}, {"role": "user", "content": "Order the results by average rarity score descending and limit to the top 10 collections."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.token_count, nc.floor_price, AVG(nm.rarity_score) AS avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' GROUP BY nc.name, nc.contract_address, nc.token_count, nc.floor_price HAVING AVG(nm.rarity_score) > 75 ORDER BY avg_rarity_score DESC LIMIT 10;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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": "How many securities are there for each security type?"}, {"role": "assistant", "content": "SELECT security_type, COUNT(*) AS security_count FROM financial_services.securities GROUP BY security_type;"}, {"role": "user", "content": "Only show security types that have more than 50 securities."}, {"role": "assistant", "content": "SELECT security_type, COUNT(*) AS security_count FROM financial_services.securities GROUP BY security_type HAVING COUNT(*) > 50;"}, {"role": "user", "content": "Sort the result by the count in descending order."}, {"role": "assistant", "content": "SELECT security_type, COUNT(*) AS security_count FROM financial_services.securities GROUP BY security_type HAVING COUNT(*) > 50 ORDER BY security_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE insurance.agents ( agent_id.text, first_name.text, last_name.text, agency_name.text, license_number.text, license_state.text, contact_email.text, contact_phone.text, hire_date.date, termination_date.date, status.text, commission_rate.numeric, manager_id.text )\nCREATE TABLE insurance.premium_payments ( payment_id text, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\nCREATE TABLE insurance.policy_beneficiaries (\n beneficiary_id character varying(64) NOT NULL, -- unique identifier for the beneficiary entry\n policy_id character varying(64) NOT NULL, -- identifier of the life/relevant policy (FK to policies)\n customer_id character varying(64) NOT NULL, -- identifier of the beneficiary (could be FK to customers or store info directly)\n first_name character varying(100) NOT NULL, -- beneficiary first name (if not linking to customers table)\n last_name character varying(100) NOT NULL, -- beneficiary last name\n relationship character varying(50) NOT NULL, -- relationship to the policyholder (e.g., Spouse, Child, Parent)\n percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), -- percentage of payout\n contact_info text, -- contact details for the beneficiary\n added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (beneficiary_id),\n UNIQUE (policy_id, customer_id) -- Ensure a person is listed only once per policy\n)\n", "conversations": [{"role": "user", "content": "Show all claims and the full name of the customer who filed each claim."}, {"role": "assistant", "content": "SELECT T1.claim_id, T1.incident_date, T1.description, T2.first_name, T2.last_name FROM insurance.claims AS T1 JOIN insurance.customers AS T2 ON T1.customer_id = T2.customer_id"}, {"role": "user", "content": "Can you also include the ID of the claim handler for each claim?"}, {"role": "assistant", "content": "SELECT T1.claim_id, T1.incident_date, T1.description, T2.first_name, T2.last_name, T1.claim_handler_id FROM insurance.claims AS T1 JOIN insurance.customers AS T2 ON T1.customer_id = T2.customer_id"}, {"role": "user", "content": "Actually, only show claims with status 'Open' and an estimated loss greater than $10,000."}, {"role": "assistant", "content": "SELECT T1.claim_id, T1.incident_date, T1.description, T2.first_name, T2.last_name, T1.claim_handler_id FROM insurance.claims AS T1 JOIN insurance.customers AS T2 ON T1.customer_id = T2.customer_id WHERE T1.status = 'Open' AND T1.estimated_loss > 10000"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.likes ( like_id.text, user_id.text, post_id.text, comment_id.text, created_at.timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags (\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 )\n", "conversations": [{"role": "user", "content": "Show a list of group chat names with their conversation_id, the total number of participants, and the total number of messages sent in each group chat."}, {"role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(cp.participant_id) AS participant_count,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nLEFT JOIN social_media.messages m ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY c.conversation_id, c.group_name;"}, {"role": "user", "content": "Please filter to include only group chats that have at least 5 participants."}, {"role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(cp.participant_id) AS participant_count,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nLEFT JOIN social_media.messages m ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY c.conversation_id, c.group_name\nHAVING COUNT(cp.participant_id) >= 5;"}, {"role": "user", "content": "Now order the results by message_count descending and limit to the top 10 group chats."}, {"role": "assistant", "content": "SELECT c.conversation_id,\n c.group_name,\n COUNT(cp.participant_id) AS participant_count,\n COUNT(m.message_id) AS message_count\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nLEFT JOIN social_media.messages m ON c.conversation_id = m.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY c.conversation_id, c.group_name\nHAVING COUNT(cp.participant_id) >= 5\nORDER BY message_count DESC\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\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )\nCREATE TABLE hospitality_technology.payments (\n payment_id character varying(64) NOT NULL, -- unique identifier for the payment transaction\n reservation_id character varying(64), -- FK to reservations (if payment is for a stay)\n guest_id character varying(64) NOT NULL, -- FK to guests (who paid)\n bill_id character varying(64), -- FK to bills/invoices this payment applies to\n amount numeric(12,2) NOT NULL, -- amount of the payment\n currency_code character varying(3) NOT NULL, -- ISO currency code (e.g., USD, EUR)\n payment_method character varying(50) NOT NULL, -- e.g., CreditCard, Cash, BankTransfer, Points, Voucher\n card_type character varying(50), -- e.g., Visa, MasterCard, Amex (if CC)\n card_last_four character varying(4), -- last 4 digits of CC (if CC)\n transaction_ref character varying(128), -- reference ID from payment gateway or processor\n payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the payment occurred\n status character varying(50) NOT NULL, -- e.g., Pending, Succeeded, Failed, Refunded, Disputed\n staff_id_processed character varying(64), -- FK to staff (who processed the payment)\n notes text, -- notes about the payment\n PRIMARY KEY (payment_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "Show all payments along with the guest's first and last name, and the staff member who processed each payment. Include payment_id, amount, currency_code, payment_timestamp, guest first_name, guest last_name, staff first_name, and staff last_name."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.amount,\n p.currency_code,\n p.payment_timestamp,\n g.first_name AS guest_first_name,\n g.last_name AS guest_last_name,\n s.first_name AS staff_first_name,\n s.last_name AS staff_last_name\nFROM hospitality_technology.payments p\nJOIN hospitality_technology.guests g ON p.guest_id = g.guest_id\nJOIN hospitality_technology.staff s ON p.staff_id_processed = s.staff_id;"}, {"role": "user", "content": "Filter to only include payments with status = 'Succeeded' and amount greater than 100."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.amount,\n p.currency_code,\n p.payment_timestamp,\n g.first_name AS guest_first_name,\n g.last_name AS guest_last_name,\n s.first_name AS staff_first_name,\n s.last_name AS staff_last_name\nFROM hospitality_technology.payments p\nJOIN hospitality_technology.guests g ON p.guest_id = g.guest_id\nJOIN hospitality_technology.staff s ON p.staff_id_processed = s.staff_id\nWHERE p.status = 'Succeeded'\n AND p.amount > 100;"}, {"role": "user", "content": "Also order the results by amount descending and limit to the top 10 payments."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.amount,\n p.currency_code,\n p.payment_timestamp,\n g.first_name AS guest_first_name,\n g.last_name AS guest_last_name,\n s.first_name AS staff_first_name,\n s.last_name AS staff_last_name\nFROM hospitality_technology.payments p\nJOIN hospitality_technology.guests g ON p.guest_id = g.guest_id\nJOIN hospitality_technology.staff s ON p.staff_id_processed = s.staff_id\nWHERE p.status = 'Succeeded'\n AND p.amount > 100\nORDER BY p.amount DESC\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\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id.text, post_id.text, user_id.text, parent_comment_id.text, content.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id text, post_id text, hashtag_id text )\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "List the five earliest hashtags created in 2024 along with their names."}, {"role": "assistant", "content": "SELECT hashtag_id, tag_name, created_at\nFROM social_media.hashtags\nWHERE created_at >= '2024-01-01' AND created_at < '2025-01-01'\nORDER BY created_at ASC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\n", "conversations": [{"role": "user", "content": "Find all medications whose NDC code starts with '0003'. Show the medication ID and NDC code."}, {"role": "assistant", "content": "SELECT medication_id, ndc_code FROM healthcare.medications WHERE ndc_code LIKE '0003%';"}, {"role": "user", "content": "Count the number of medications for each manufacturer and show manufacturers with more than 100 medications."}, {"role": "assistant", "content": "SELECT manufacturer, COUNT(*) AS medication_count FROM healthcare.medications GROUP BY manufacturer HAVING COUNT(*) > 100;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.reviews (\n review_id character varying(64) NOT NULL, -- unique identifier for the review\n property_id character varying(64) NOT NULL, -- FK to properties table\n reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good)\n guest_id character varying(64) NOT NULL, -- FK to guests table\n rating_overall integer, -- overall score (e.g., 1-5 or 1-10)\n rating_cleanliness integer,\n rating_service integer,\n rating_location integer,\n rating_value integer,\n comment text, -- guest's written feedback\n review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com\n review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted\n is_public boolean DEFAULT true, -- whether the review is publicly visible\n staff_response text, -- official response from the property\n response_staff_id character varying(64), -- FK to staff (who responded)\n response_date timestamp with time zone, -- when the response was posted\n PRIMARY KEY (review_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id)\n)\n", "conversations": [{"role": "user", "content": "For each reservation in the last three months, show the reservation ID, check-in date, number of adults, and the corresponding room type name."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.check_in_date, r.num_adults, rt.type_name\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nWHERE r.created_at >= NOW() - INTERVAL '3 months';"}, {"role": "user", "content": "Also include the name of the property for each reservation."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.check_in_date, r.num_adults, rt.type_name, p.property_name\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE r.created_at >= NOW() - INTERVAL '3 months';"}, {"role": "user", "content": "Sort the results by number of adults descending, and then by check-in date ascending."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.check_in_date, r.num_adults, rt.type_name, p.property_name\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE r.created_at >= NOW() - INTERVAL '3 months'\nORDER BY r.num_adults DESC, r.check_in_date ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n", "conversations": [{"role": "user", "content": "List all services in the 'Concierge' department along with their names, price, and whether they are currently available. Include the property name as well."}, {"role": "assistant", "content": "SELECT s.service_name, s.price, s.is_available, p.property_name\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.department = 'Concierge';"}, {"role": "user", "content": "Could you filter only those services that are not currently available and sort by price ascending?"}, {"role": "assistant", "content": "SELECT s.service_name, s.price, s.is_available, p.property_name\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.department = 'Concierge'\n AND s.is_available = false\nORDER BY s.price ASC;"}, {"role": "user", "content": "Instead, show only properties in the city of 'Miami' and add the service category to the results."}, {"role": "assistant", "content": "SELECT s.service_name, s.category, s.price, s.is_available, p.property_name\nFROM hospitality_technology.services s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nWHERE s.department = 'Concierge'\n AND s.is_available = false\n AND p.city = 'Miami'\nORDER BY s.price ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.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.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) )\n", "conversations": [{"role": "user", "content": "List all staff members, showing their full name, position, and the name of the property where they work."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T1.position, T2.property_name FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id;"}, {"role": "user", "content": "Only include staff who are currently active and add their manager's full name if they have one."}, {"role": "assistant", "content": "SELECT T1.first_name AS staff_first_name, T1.last_name AS staff_last_name, T1.position, T2.property_name, T3.first_name AS manager_first_name, T3.last_name AS manager_last_name FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id LEFT JOIN hospitality_technology.staff AS T3 ON T1.manager_id = T3.staff_id WHERE T1.is_active = TRUE;"}, {"role": "user", "content": "Filter further to only include staff working at properties in the 'California' state and sort by property name, then staff last name."}, {"role": "assistant", "content": "SELECT T1.first_name AS staff_first_name, T1.last_name AS staff_last_name, T1.position, T2.property_name, T3.first_name AS manager_first_name, T3.last_name AS manager_last_name FROM hospitality_technology.staff AS T1 JOIN hospitality_technology.properties AS T2 ON T1.property_id = T2.property_id LEFT JOIN hospitality_technology.staff AS T3 ON T1.manager_id = T3.staff_id WHERE T1.is_active = TRUE AND T2.state_province = 'California' ORDER BY T2.property_name, T1.last_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all staff members hired in 2024, showing their first name, last name, and hire date."}, {"role": "assistant", "content": "SELECT first_name, last_name, hire_date FROM hospitality_technology.staff WHERE EXTRACT(YEAR FROM hire_date) = 2024"}, {"role": "user", "content": "Now, only include those whose position is 'Manager'."}, {"role": "assistant", "content": "SELECT first_name, last_name, hire_date FROM hospitality_technology.staff WHERE EXTRACT(YEAR FROM hire_date) = 2024 AND position = 'Manager'"}]} +{"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 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.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.reservations ( reservation_id.text, property_id.text, guest_id.text, room_id.text, room_type_id.text, check_in_date.date, check_out_date.date, actual_check_in_ts.timestamp, actual_check_out_ts.timestamp, num_adults.integer, num_children.integer, status.text, booking_source.text, rate_plan_id.text, total_amount.numeric, amount_paid.numeric, special_requests.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.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) )\n", "conversations": [{"role": "user", "content": "For each property, list the names of all available services in the 'Wellness' category. Show property name and service name."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.service_name FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.services AS T2 ON T1.property_id = T2.property_id WHERE T2.category = 'Wellness' AND T2.is_available = TRUE ORDER BY T1.property_name, T2.service_name;"}, {"role": "user", "content": "Now, filter those services to only include ones with a price less than 75 and also include the department and price in the output."}, {"role": "assistant", "content": "SELECT T1.property_name, T2.service_name, T2.department, T2.price FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.services AS T2 ON T1.property_id = T2.property_id WHERE T2.category = 'Wellness' AND T2.is_available = TRUE AND T2.price < 75 ORDER BY T1.property_name, T2.service_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )\nCREATE TABLE hospitality_technology.reservations (\n reservation_id character varying(64) NOT NULL, -- unique identifier for the booking\n property_id character varying(64) NOT NULL, -- FK to properties table\n guest_id character varying(64) NOT NULL, -- FK to guests table (primary guest)\n room_id character varying(64), -- FK to rooms table (assigned room, might be null initially)\n room_type_id character varying(64) NOT NULL, -- FK to room_types table (booked room type)\n check_in_date date NOT NULL, -- scheduled check-in date\n check_out_date date NOT NULL, -- scheduled check-out date\n actual_check_in_ts timestamp with time zone, -- actual check-in time\n actual_check_out_ts timestamp with time zone, -- actual check-out time\n num_adults integer NOT NULL, -- number of adults\n num_children integer DEFAULT 0, -- number of children\n status character varying(50) NOT NULL, -- e.g., Pending, Confirmed, CheckedIn, CheckedOut, Cancelled, NoShow\n booking_source character varying(100), -- e.g., Website, OTA (Expedia, Booking.com), Phone, WalkIn\n rate_plan_id character varying(64), -- FK to rate_plans table (optional)\n total_amount numeric(12, 2), -- estimated or final total cost\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n special_requests text, -- specific guest requests for this booking\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (reservation_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.services ( service_id.text, property_id.text, service_name.text, description.text, category.text, price.numeric, unit.text, is_available.boolean, department.text )\nCREATE TABLE hospitality_technology.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) )\n", "conversations": [{"role": "user", "content": "For each guest, show their full name and the total quantity of services they have ordered in the last 30 days."}, {"role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.quantity) AS total_quantity\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.order_timestamp >= NOW() - INTERVAL '30 days'\nGROUP BY g.guest_id, g.first_name, g.last_name;"}, {"role": "user", "content": "Now only include guests whose total_quantity is greater than 10, and order by total_quantity descending."}, {"role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.quantity) AS total_quantity\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.order_timestamp >= NOW() - INTERVAL '30 days'\nGROUP BY g.guest_id, g.first_name, g.last_name\nHAVING SUM(so.quantity) > 10\nORDER BY total_quantity DESC;"}, {"role": "user", "content": "Also include the total spending for each of these guests in that period."}, {"role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n SUM(so.quantity) AS total_quantity,\n ROUND(SUM(so.total_price), 2) AS total_spending\nFROM hospitality_technology.guests g\nJOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nWHERE so.order_timestamp >= NOW() - INTERVAL '30 days'\nGROUP BY g.guest_id, g.first_name, g.last_name\nHAVING SUM(so.quantity) > 10\nORDER BY total_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\n", "conversations": [{"role": "user", "content": "Show the average base rate and maximum occupancy of room types grouped by property_type."}, {"role": "assistant", "content": "SELECT p.property_type,\n AVG(rt.base_rate) AS avg_base_rate,\n MAX(rt.max_occupancy) AS max_occupancy\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.room_types rt\n ON p.property_id = rt.property_id\nGROUP BY p.property_type;"}, {"role": "user", "content": "Only include those property types where the average base rate is greater than 200."}, {"role": "assistant", "content": "SELECT p.property_type,\n AVG(rt.base_rate) AS avg_base_rate,\n MAX(rt.max_occupancy) AS max_occupancy\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.room_types rt\n ON p.property_id = rt.property_id\nGROUP BY p.property_type\nHAVING AVG(rt.base_rate) > 200;"}]} {"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 hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve all room types with a base_rate above 150 for each property."}, {"role": "assistant", "content": "SELECT property_id, type_name, base_rate\nFROM hospitality_technology.room_types\nWHERE base_rate > 150;"}, {"role": "user", "content": "Also filter to only include room types with max_occupancy >= 3."}, {"role": "assistant", "content": "SELECT property_id, type_name, base_rate\nFROM hospitality_technology.room_types\nWHERE base_rate > 150\n AND max_occupancy >= 3;"}, {"role": "user", "content": "Finally, show guest first and last names of guests created after '2023-01-01' who could book these room types."}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, rt.property_id, rt.type_name, rt.base_rate\nFROM hospitality_technology.room_types rt\nCROSS JOIN hospitality_technology.guests g\nWHERE rt.base_rate > 150\n AND rt.max_occupancy >= 3\n AND g.created_at > '2023-01-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Provide a list of all future appointments showing appointment_id, scheduled_start_time, location_name, city, and state."}, {"role": "assistant", "content": "SELECT\n a.appointment_id,\n a.scheduled_start_time,\n sl.location_name,\n sl.city,\n sl.state\nFROM appointments a\nJOIN service_locations sl\n ON a.location_id = sl.location_id\nWHERE a.scheduled_start_time > CURRENT_TIMESTAMP;"}]} -{"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 healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )\n", "conversations": [{"role": "user", "content": "Show me a list of all insurance policies along with the subscriber's name and the effective and expiration dates for each policy, including the associated plan ID."}, {"role": "assistant", "content": "SELECT policy_number, subscriber_name, effective_date, expiration_date, plan_id FROM healthcare.patient_insurance;"}, {"role": "user", "content": "Now, I only want to see policies that are primary and do not have a group number assigned. Please also include the patient_id."}, {"role": "assistant", "content": "SELECT policy_number, subscriber_name, effective_date, expiration_date, plan_id, patient_id FROM healthcare.patient_insurance WHERE is_primary = TRUE AND group_number IS NULL;"}, {"role": "user", "content": "Actually, please filter further to only show policies that expire after 2024-12-31."}, {"role": "assistant", "content": "SELECT policy_number, subscriber_name, effective_date, expiration_date, plan_id, patient_id FROM healthcare.patient_insurance WHERE is_primary = TRUE AND group_number IS NULL AND expiration_date > '2024-12-31';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\n", "conversations": [{"role": "user", "content": "Find all pairs of drivers who share the same status. Include both driver_ids, full names, and the shared status."}, {"role": "assistant", "content": "SELECT d1.driver_id AS driver1_id, d1.first_name || ' ' || d1.last_name AS driver1_name, d2.driver_id AS driver2_id, d2.first_name || ' ' || d2.last_name AS driver2_name, d1.status FROM transportation.drivers d1 JOIN transportation.drivers d2 ON d1.status = d2.status AND d1.driver_id < d2.driver_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\n", "conversations": [{"role": "user", "content": "Show all fuel logs for vehicle_id 'VH123', including the timestamp, fuel type, quantity, and the location_id. Sort the list by timestamp descending."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "Can you also include the odometer reading and total cost for each fuel log in the result?"}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "I only want to see records where the total_cost is above 100."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\n AND total_cost > 100\nORDER BY log_timestamp DESC;"}, {"role": "user", "content": "Actually, please limit the results to just the 5 most recent logs."}, {"role": "assistant", "content": "SELECT fuel_log_id, log_timestamp, fuel_type, quantity, location_id, odometer_reading, total_cost\nFROM transportation.fuel_logs\nWHERE vehicle_id = 'VH123'\n AND total_cost > 100\nORDER BY log_timestamp DESC\nLIMIT 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.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.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "List all routes showing the route_number, origin_location_id, destination_location_id, distance_km, and type."}, {"role": "assistant", "content": "SELECT\n route_number,\n origin_location_id,\n destination_location_id,\n distance_km,\n type\nFROM transportation.routes;"}, {"role": "user", "content": "Only include routes where distance_km is less than 100."}, {"role": "assistant", "content": "SELECT\n route_number,\n origin_location_id,\n destination_location_id,\n distance_km,\n type\nFROM transportation.routes\nWHERE distance_km < 100;"}, {"role": "user", "content": "Also, sort the results by estimated_duration_minutes in ascending order."}, {"role": "assistant", "content": "SELECT\n route_number,\n origin_location_id,\n destination_location_id,\n distance_km,\n type,\n estimated_duration_minutes\nFROM transportation.routes\nWHERE distance_km < 100\nORDER BY estimated_duration_minutes ASC;"}, {"role": "user", "content": "Actually, I want to see the duration per kilometer (estimated_duration_minutes divided by distance_km) as a new column named duration_per_km. Can you add that?"}, {"role": "assistant", "content": "SELECT\n route_number,\n origin_location_id,\n destination_location_id,\n distance_km,\n type,\n estimated_duration_minutes,\n estimated_duration_minutes / distance_km AS duration_per_km\nFROM transportation.routes\nWHERE distance_km < 100\nORDER BY estimated_duration_minutes ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.applications ( application_id text PRIMARY KEY, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text PRIMARY KEY, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "I want to get the total number of appointments scheduled at each agency in 2024. Please provide the agency name and the appointment count."}, {"role": "assistant", "content": "SELECT a.agency_name,\n COUNT(ap.appointment_id) AS appointment_count\nFROM government_services.appointments ap\nJOIN government_services.employees e\n ON ap.employee_id = e.employee_id\nJOIN government_services.agencies a\n ON e.agency_id = a.agency_id\nWHERE ap.scheduled_start_time BETWEEN '2024-01-01' AND '2024-12-31'\nGROUP BY a.agency_name;"}, {"role": "user", "content": "Now only include agencies with more than 100 appointments and order the results by appointment_count descending."}, {"role": "assistant", "content": "SELECT a.agency_name,\n COUNT(ap.appointment_id) AS appointment_count\nFROM government_services.appointments ap\nJOIN government_services.employees e\n ON ap.employee_id = e.employee_id\nJOIN government_services.agencies a\n ON e.agency_id = a.agency_id\nWHERE ap.scheduled_start_time BETWEEN '2024-01-01' AND '2024-12-31'\nGROUP BY a.agency_name\nHAVING COUNT(ap.appointment_id) > 100\nORDER BY appointment_count DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id text, 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 PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "List the full name of employees and the names of the agencies they work for, but only for employees who are currently employed."}, {"role": "assistant", "content": "SELECT e.first_name || ' ' || e.last_name AS employee_full_name, a.agency_name\nFROM government_services.employees e\nJOIN government_services.agencies a ON e.agency_id = a.agency_id\nWHERE e.termination_date IS NULL;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nIndex 'component_inventory'. Mapping: { properties: { inventory_record_id: { type: 'keyword' }, component_id: { type: 'keyword' }, quantity: { type: 'integer' }, location_warehouse: { type: 'keyword' }, location_bin: { type: 'keyword' }, received_date: { type: 'date' }, expiry_date: { type: 'date' }, batch_number: { type: 'keyword' }, last_updated: { type: 'date' } } }. Document _id can be inventory_record_id.\n", "conversations": [{"role": "user", "content": "\u7279\u5b9a\u306e\u5009\u5eab\u306b\u3042\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u5728\u5eab\u60c5\u5831\u3092\u53d6\u5f97\u3057\u305f\u3044\u3067\u3059\u3002\u5009\u5eab\u306e\u5834\u6240\u3001\u30d3\u30f3\u306e\u4f4d\u7f6e\u3001\u5728\u5eab\u6570\u91cf\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8ID\u3092\u8868\u793a\u3057\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "SELECT location_warehouse, location_bin, quantity, component_id FROM component_inventory WHERE location_warehouse = 'specific_warehouse';"}, {"role": "user", "content": "\u53d7\u3051\u53d6\u308a\u65e5\u304c2023\u5e741\u67081\u65e5\u4ee5\u964d\u306e\u8a18\u9332\u3060\u3051\u306b\u7d5e\u308a\u8fbc\u3080\u3053\u3068\u306f\u3067\u304d\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SELECT location_warehouse, location_bin, quantity, component_id FROM component_inventory WHERE location_warehouse = 'specific_warehouse' AND received_date >= '2023-01-01';"}, {"role": "user", "content": "\u3055\u3089\u306b\u3001\u6700\u7d42\u66f4\u65b0\u65e5\u304c\u904e\u53bb1\u30f6\u6708\u4ee5\u5185\u306e\u3082\u306e\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3067\u304d\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SELECT location_warehouse, location_bin, quantity, component_id FROM component_inventory WHERE location_warehouse = 'specific_warehouse' AND received_date >= '2023-01-01' AND last_updated >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH);"}, {"role": "user", "content": "\u6700\u5f8c\u306b\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8ID\u3054\u3068\u306b\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u3066\u3001\u5728\u5eab\u6570\u91cf\u306e\u5408\u8a08\u3092\u8868\u793a\u3057\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "SELECT location_warehouse, location_bin, component_id, SUM(quantity) AS total_quantity FROM component_inventory WHERE location_warehouse = 'specific_warehouse' AND received_date >= '2023-01-01' AND last_updated >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) GROUP BY component_id, location_warehouse, location_bin;"}]} -{"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 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": "Show the total payment amount and the number of payments processed by each staff member, including their staff_id_processed."}, {"role": "assistant", "content": "SELECT staff_id_processed, SUM(amount) AS total_payment_amount, COUNT(payment_id) AS payment_count FROM hospitality_technology.payments GROUP BY staff_id_processed;"}]} -{"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 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": "Show the number of staff members for each property, along with the property name."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(s.staff_id) AS staff_count\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.staff s ON p.property_id = s.property_id\nGROUP BY p.property_name;"}, {"role": "user", "content": "Only include properties with more than 20 staff members, and order the result by staff count descending."}, {"role": "assistant", "content": "SELECT p.property_name, COUNT(s.staff_id) AS staff_count\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.staff s ON p.property_id = s.property_id\nGROUP BY p.property_name\nHAVING COUNT(s.staff_id) > 20\nORDER BY staff_count DESC;"}]} -{"system": "You are an 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 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 all pairs of achievements in the same game, returning game_id, the first achievement name as achv1, and the second as achv2."}, {"role": "assistant", "content": "SELECT a1.game_id, a1.name AS achv1, a2.name AS achv2\nFROM achievements a1\nJOIN achievements a2\n ON a1.game_id = a2.game_id\n AND a1.achievement_id < a2.achievement_id;"}, {"role": "user", "content": "Only include pairs where the sum of their points exceeds 150."}, {"role": "assistant", "content": "SELECT a1.game_id,\n a1.name AS achv1,\n a2.name AS achv2\nFROM achievements a1\nJOIN achievements a2\n ON a1.game_id = a2.game_id\n AND a1.achievement_id < a2.achievement_id\nWHERE a1.points + a2.points > 150;"}, {"role": "user", "content": "Exclude any pairs where either achievement is hidden."}, {"role": "assistant", "content": "SELECT a1.game_id,\n a1.name AS achv1,\n a2.name AS achv2\nFROM achievements a1\nJOIN achievements a2\n ON a1.game_id = a2.game_id\n AND a1.achievement_id < a2.achievement_id\nWHERE a1.points + a2.points > 150\n AND a1.hidden = false\n AND a2.hidden = false;"}, {"role": "user", "content": "Finally, order the results by the combined points descending."}, {"role": "assistant", "content": "SELECT a1.game_id,\n a1.name AS achv1,\n a2.name AS achv2\nFROM achievements a1\nJOIN achievements a2\n ON a1.game_id = a2.game_id\n AND a1.achievement_id < a2.achievement_id\nWHERE a1.points + a2.points > 150\n AND a1.hidden = false\n AND a2.hidden = false\nORDER BY (a1.points + a2.points) DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id 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.transactions ( transaction_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, related_account_id character varying(64), transaction_type character varying(50) NOT NULL, amount numeric(19, 4) NOT NULL, currency character varying(3) NOT NULL, transaction_date timestamp NOT NULL, effective_date date NOT NULL, description text, status character varying(32) NOT NULL, reference_number character varying(128), PRIMARY KEY (transaction_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id) )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data (\n data_point_id bigserial NOT NULL, -- auto-incrementing primary key\n security_id character varying(64) NOT NULL, -- identifier for the security\n data_timestamp timestamp NOT NULL, -- timestamp for the data point (e.g., end of day, intraday)\n open_price numeric(19, 8), -- opening price for the period\n high_price numeric(19, 8), -- highest price during the period\n low_price numeric(19, 8), -- lowest price during the period\n close_price numeric(19, 8) NOT NULL, -- closing price for the period\n adjusted_close_price numeric(19, 8), -- closing price adjusted for dividends and splits\n volume bigint, -- trading volume during the period\n source character varying(50), -- source of the market data (e.g., Bloomberg, Refinitiv)\n PRIMARY KEY (data_point_id),\n UNIQUE (security_id, data_timestamp), -- Ensure unique data point per security per time\n FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id)\n)\nCREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )\n", "conversations": [{"role": "user", "content": "For each account, show the account number, currency, and the sum of all incoming transaction amounts, where an incoming transaction is one where the account appears as related_account_id."}, {"role": "assistant", "content": "SELECT a.account_number, a.currency, COALESCE(SUM(t.amount), 0) AS total_incoming\nFROM financial_services.accounts a\nLEFT JOIN financial_services.transactions t ON a.account_id = t.related_account_id\nGROUP BY a.account_id, a.account_number, a.currency;"}, {"role": "user", "content": "Only include accounts with total incoming over 2000 and show the account type as well. Please order by total_incoming descending."}, {"role": "assistant", "content": "SELECT a.account_number, a.currency, a.account_type, COALESCE(SUM(t.amount), 0) AS total_incoming\nFROM financial_services.accounts a\nLEFT JOIN financial_services.transactions t ON a.account_id = t.related_account_id\nGROUP BY a.account_id, a.account_number, a.currency, a.account_type\nHAVING COALESCE(SUM(t.amount), 0) > 2000\nORDER BY total_incoming DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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": "Show the total payment amount grouped by currency_code and filtered to only include payments with status 'Pending' or 'Failed'."}, {"role": "assistant", "content": "SELECT currency_code, SUM(amount) AS total_amount FROM hospitality_technology.payments WHERE status IN ('Pending', 'Failed') GROUP BY currency_code;"}, {"role": "user", "content": "Actually, please break down the result further by payment method as well."}, {"role": "assistant", "content": "SELECT currency_code, payment_method, SUM(amount) AS total_amount FROM hospitality_technology.payments WHERE status IN ('Pending', 'Failed') GROUP BY currency_code, payment_method;"}, {"role": "user", "content": "Can you also count the number of distinct guests for each combination of currency_code and payment_method in the result?"}, {"role": "assistant", "content": "SELECT currency_code, payment_method, SUM(amount) AS total_amount, COUNT(DISTINCT guest_id) AS guest_count FROM hospitality_technology.payments WHERE status IN ('Pending', 'Failed') GROUP BY currency_code, payment_method;"}]} -{"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 transportation.passengers ( passenger_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Count the number of passengers in each month of the year 2024 based on their created_at date."}, {"role": "assistant", "content": "SELECT EXTRACT(MONTH FROM created_at) AS month, COUNT(*) AS passenger_count\nFROM transportation.passengers\nWHERE created_at >= '2024-01-01' AND created_at < '2025-01-01'\nGROUP BY EXTRACT(MONTH FROM created_at)\nORDER BY month;"}, {"role": "user", "content": "Now, only include months where the passenger_count exceeds 50."}, {"role": "assistant", "content": "SELECT EXTRACT(MONTH FROM created_at) AS month, COUNT(*) AS passenger_count\nFROM transportation.passengers\nWHERE created_at >= '2024-01-01' AND created_at < '2025-01-01'\nGROUP BY EXTRACT(MONTH FROM created_at)\nHAVING COUNT(*) > 50\nORDER BY month;"}]} -{"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 social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me all replies to comments, including the reply's comment ID, the parent comment ID, and the content."}, {"role": "assistant", "content": "SELECT comment_id, parent_comment_id, content FROM social_media.comments WHERE parent_comment_id IS NOT NULL;"}, {"role": "user", "content": "I also want to see which post each reply was made on. Can you include the post ID as well?"}, {"role": "assistant", "content": "SELECT comment_id, parent_comment_id, post_id, content FROM social_media.comments WHERE parent_comment_id IS NOT NULL;"}, {"role": "user", "content": "Now, only show replies made after June 1, 2024."}, {"role": "assistant", "content": "SELECT comment_id, parent_comment_id, post_id, content FROM social_media.comments WHERE parent_comment_id IS NOT NULL AND created_at > '2024-06-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\n", "conversations": [{"role": "user", "content": "Which exchanges hold the largest total USD value of tokens on the BSC chain in the most recent snapshot, and what is the top token (by usd_value) held by each exchange?"}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"}, {"role": "user", "content": "Can you add the number of distinct tokens each exchange holds on BSC in the latest snapshot to the result?"}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value,\n COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n e.token_count,\n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"}, {"role": "user", "content": "I'd like the results filtered so only exchanges holding more than $2,000,000 in total on BSC are included."}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value,\n COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n HAVING SUM(c.usd_value) > 2000000\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n e.token_count,\n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"}]} -{"system": "You are an 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 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 ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.time_entries ( 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.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the names of all law firms and the total number of lawyers associated with each firm."}, {"role": "assistant", "content": "SELECT T1.firm_name, count(T2.lawyer_id) FROM legal_services.law_firms AS T1 JOIN legal_services.lawyers AS T2 ON T1.firm_id = T2.firm_id GROUP BY T1.firm_id, T1.firm_name"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\n", "conversations": [{"role": "user", "content": "Can you provide a list of all law firms, including their address and phone number?"}, {"role": "assistant", "content": "SELECT firm_id, firm_name, address, phone FROM legal_services.law_firms;"}, {"role": "user", "content": "I would like to see only those firms founded before 2010."}, {"role": "assistant", "content": "SELECT firm_id, firm_name, address, phone FROM legal_services.law_firms WHERE founded_date < '2010-01-01';"}, {"role": "user", "content": "Filter the list further to include only firms that have a phone number specified."}, {"role": "assistant", "content": "SELECT firm_id, firm_name, address, phone FROM legal_services.law_firms WHERE founded_date < '2010-01-01' AND phone IS NOT NULL;"}, {"role": "user", "content": "Please display the results ordered by firm name alphabetically."}, {"role": "assistant", "content": "SELECT firm_id, firm_name, address, phone FROM legal_services.law_firms WHERE founded_date < '2010-01-01' AND phone IS NOT NULL ORDER BY firm_name ASC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "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 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 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": "I need to compare consecutive daily close_prices for each security to find when the close_price increased compared to the previous day."}, {"role": "assistant", "content": "SELECT a.security_id, b.data_timestamp AS prev_date, b.close_price AS prev_close, a.data_timestamp AS curr_date, a.close_price AS curr_close\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nWHERE a.close_price > b.close_price;"}, {"role": "user", "content": "Now, restrict this to only securities whose average volume over the past 30 days exceeds 1,000,000."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id, b.data_timestamp AS prev_date, b.close_price AS prev_close, a.data_timestamp AS curr_date, a.close_price AS curr_close\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE a.close_price > b.close_price;"}, {"role": "user", "content": "Also, only include those increases where the percentage change between days is greater than 2%."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id,\n b.data_timestamp AS prev_date,\n b.close_price AS prev_close,\n a.data_timestamp AS curr_date,\n a.close_price AS curr_close,\n ROUND((a.close_price - b.close_price) / b.close_price * 100, 2) AS pct_change\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE (a.close_price - b.close_price) / b.close_price * 100 > 2;"}, {"role": "user", "content": "Finally, add the adjusted_close_price for both current and previous days to the result."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id,\n b.data_timestamp AS prev_date,\n b.close_price AS prev_close,\n b.adjusted_close_price AS prev_adj_close,\n a.data_timestamp AS curr_date,\n a.close_price AS curr_close,\n a.adjusted_close_price AS curr_adj_close,\n ROUND((a.close_price - b.close_price) / b.close_price * 100, 2) AS pct_change\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE (a.close_price - b.close_price) / b.close_price * 100 > 2;"}]} -{"system": "You are an 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 financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id text PRIMARY KEY, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.securities ( security_id text, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(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 (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\n", "conversations": [{"role": "user", "content": "List all trades with their order_id, trade_type, and commission for trades with commission higher than 100."}, {"role": "assistant", "content": "SELECT trade_id, order_id, trade_type, commission FROM financial_services.trades WHERE commission > 100;"}, {"role": "user", "content": "Include the security_name and ticker_symbol for each trade as well."}, {"role": "assistant", "content": "SELECT t.trade_id, t.order_id, t.trade_type, t.commission, s.security_name, s.ticker_symbol FROM financial_services.trades t INNER JOIN financial_services.securities s ON t.security_id = s.security_id WHERE t.commission > 100;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n", "conversations": [{"role": "user", "content": "Show me the names of law firms founded after 2010, along with the full name of their managing partner."}, {"role": "assistant", "content": "SELECT f.firm_name, l.first_name, l.last_name FROM legal_services.law_firms AS f JOIN legal_services.lawyers AS l ON f.managing_partner_id = l.lawyer_id WHERE f.founded_date > '2010-12-31';"}]} -{"system": "You are an 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 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.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id text, 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 the number of appointments scheduled at each location, along with the location name and city."}, {"role": "assistant", "content": "SELECT loc.location_name, loc.city, COUNT(appt.appointment_id) AS appointment_count\nFROM government_services.appointments appt\nJOIN government_services.service_locations loc ON appt.location_id = loc.location_id\nGROUP BY loc.location_name, loc.city;"}, {"role": "user", "content": "Can you add the state for each location as well?"}, {"role": "assistant", "content": "SELECT loc.location_name, loc.city, loc.state, COUNT(appt.appointment_id) AS appointment_count\nFROM government_services.appointments appt\nJOIN government_services.service_locations loc ON appt.location_id = loc.location_id\nGROUP BY loc.location_name, loc.city, loc.state;"}, {"role": "user", "content": "Now only include locations where the number of appointments is greater than 20."}, {"role": "assistant", "content": "SELECT loc.location_name, loc.city, loc.state, COUNT(appt.appointment_id) AS appointment_count\nFROM government_services.appointments appt\nJOIN government_services.service_locations loc ON appt.location_id = loc.location_id\nGROUP BY loc.location_name, loc.city, loc.state\nHAVING COUNT(appt.appointment_id) > 20;"}]} -{"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 transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\n", "conversations": [{"role": "user", "content": "For each driver, find the other driver whose license_expiry_date is the next one after theirs. Show both IDs, names and their expiry dates."}, {"role": "assistant", "content": "SELECT\n d1.driver_id AS driver_id,\n d1.first_name || ' ' || d1.last_name AS driver_name,\n d1.license_expiry_date AS expiry_date,\n d2.driver_id AS next_driver_id,\n d2.first_name || ' ' || d2.last_name AS next_driver_name,\n d2.license_expiry_date AS next_expiry_date\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date = (\n SELECT MIN(d3.license_expiry_date)\n FROM transportation.drivers d3\n WHERE d3.license_expiry_date > d1.license_expiry_date\n );"}]} -{"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 financial_services.accounts (\n account_id character varying(64) NOT NULL, -- unique identifier for the account\n customer_id character varying(64) NOT NULL, -- foreign key linking to the customer\n account_number character varying(128) NOT NULL UNIQUE, -- unique account number visible to customer\n account_type character varying(50) NOT NULL, -- e.g., Checking, Savings, Investment, Loan, Credit Card\n balance numeric(19, 4) NOT NULL DEFAULT 0.00, -- current account balance\n currency character varying(3) NOT NULL, -- currency code (e.g., USD, EUR)\n opened_date date NOT NULL, -- date the account was opened\n status character varying(32) NOT NULL, -- e.g., Open, Closed, Frozen\n interest_rate numeric(5, 4), -- annual interest rate, if applicable\n last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last account update\n PRIMARY KEY (account_id),\n FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id)\n)\nCREATE TABLE financial_services.transactions ( 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 PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\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 text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\nCREATE TABLE financial_services.loans (\n loan_id character varying(64) NOT NULL, -- unique identifier for the loan, could be same as account_id\n account_id character varying(64) NOT NULL UNIQUE, -- link to the general account record\n loan_type character varying(50) NOT NULL, -- e.g., Mortgage, Personal, Auto, Student\n principal_amount numeric(19, 4) NOT NULL, -- original loan amount\n current_principal_balance numeric(19, 4) NOT NULL, -- remaining principal\n interest_rate numeric(6, 4) NOT NULL, -- annual interest rate\n term_months integer NOT NULL, -- loan term in months\n origination_date date NOT NULL, -- date the loan was disbursed\n maturity_date date NOT NULL, -- date the loan is due to be fully repaid\n monthly_payment numeric(12, 4), -- scheduled monthly payment amount\n collateral_description text, -- description of collateral, if secured loan\n status character varying(32) NOT NULL, -- e.g., Active, Paid Off, Defaulted\n PRIMARY KEY (loan_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id)\n)\n", "conversations": [{"role": "user", "content": "For each customer, show their full name and the average amount of all transactions linked to any of their accounts."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS customer_full_name, AVG(t.amount) AS average_transaction_amount FROM financial_services.customers AS c JOIN financial_services.accounts AS a ON c.customer_id = a.customer_id JOIN financial_services.transactions AS t ON a.account_id = t.account_id OR a.account_id = t.related_account_id GROUP BY c.customer_id, customer_full_name;"}, {"role": "user", "content": "Only consider transactions that occurred within the last 90 days for this calculation."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS customer_full_name, AVG(t.amount) AS average_transaction_amount FROM financial_services.customers AS c JOIN financial_services.accounts AS a ON c.customer_id = a.customer_id JOIN financial_services.transactions AS t ON a.account_id = t.account_id OR a.account_id = t.related_account_id WHERE t.transaction_date >= CURRENT_DATE - INTERVAL '90 day' GROUP BY c.customer_id, customer_full_name;"}, {"role": "user", "content": "Filter the results to only show customers where this average transaction amount is greater than 1000."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS customer_full_name, AVG(t.amount) AS average_transaction_amount FROM financial_services.customers AS c JOIN financial_services.accounts AS a ON c.customer_id = a.customer_id JOIN financial_services.transactions AS t ON a.account_id = t.account_id OR a.account_id = t.related_account_id WHERE t.transaction_date >= CURRENT_DATE - INTERVAL '90 day' GROUP BY c.customer_id, customer_full_name HAVING AVG(t.amount) > 1000;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n", "conversations": [{"role": "user", "content": "How many primary insurance policies are currently active for each plan_id? Show plan_id and active_count."}, {"role": "assistant", "content": "SELECT plan_id,\n COUNT(*) AS active_count\nFROM healthcare.patient_insurance\nWHERE is_primary = TRUE\n AND (expiration_date IS NULL OR expiration_date > CURRENT_DATE)\nGROUP BY plan_id;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Find employees who work in the same department as their manager. Display the employee's full name, the manager's full name, and the department they share."}, {"role": "assistant", "content": "SELECT e.first_name || ' ' || e.last_name AS employee_full_name, m.first_name || ' ' || m.last_name AS manager_full_name, e.department FROM government_services.employees AS e JOIN government_services.employees AS m ON e.manager_employee_id = m.employee_id WHERE e.department = m.department;"}]} -{"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 gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\nCREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\n", "conversations": [{"role": "user", "content": "List all servers that are currently online and have a player count greater than their average player count across all servers in the same region."}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, s.current_players\nFROM gaming_technology.servers s\nJOIN (SELECT region, AVG(current_players) AS avg_players FROM gaming_technology.servers GROUP BY region) r\n ON s.region = r.region\nWHERE s.status = 'online' AND s.current_players > r.avg_players;"}, {"role": "user", "content": "Can you also include the maximum players of each server in the result?"}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, s.current_players, s.max_players\nFROM gaming_technology.servers s\nJOIN (SELECT region, AVG(current_players) AS avg_players FROM gaming_technology.servers GROUP BY region) r\n ON s.region = r.region\nWHERE s.status = 'online' AND s.current_players > r.avg_players;"}, {"role": "user", "content": "Now only show servers where current_players is at least 75% of max_players."}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, s.current_players, s.max_players\nFROM gaming_technology.servers s\nJOIN (SELECT region, AVG(current_players) AS avg_players FROM gaming_technology.servers GROUP BY region) r\n ON s.region = r.region\nWHERE s.status = 'online'\n AND s.current_players > r.avg_players\n AND s.current_players >= 0.75 * s.max_players;"}, {"role": "user", "content": "Please also show the average player count for the region in each row."}, {"role": "assistant", "content": "SELECT s.server_id, s.server_name, s.region, s.current_players, s.max_players, r.avg_players\nFROM gaming_technology.servers s\nJOIN (SELECT region, AVG(current_players) AS avg_players FROM gaming_technology.servers GROUP BY region) r\n ON s.region = r.region\nWHERE s.status = 'online'\n AND s.current_players > r.avg_players\n AND s.current_players >= 0.75 * s.max_players;"}]} -{"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 legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.law_firms (\n firm_id character varying(64) NOT NULL, -- unique identifier for the law firm\n firm_name character varying(200) NOT NULL, -- official name of the law firm\n address text NOT NULL, -- primary address of the firm\n phone character varying(32), -- firm's main phone number\n website character varying(255), -- firm's website URL\n founded_date date, -- date the firm was established\n managing_partner_id character varying(64), -- FK to lawyers table (optional)\n PRIMARY KEY (firm_id)\n)\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\nCREATE TABLE legal_services.documents ( document_id character varying(64) NOT NULL, case_id character varying(64) NOT NULL, document_name character varying(255) NOT NULL, document_type character varying(100), storage_path text NOT NULL, uploaded_by_lawyer_id character varying(64), upload_timestamp timestamp NOT NULL, version integer DEFAULT 1, description text, PRIMARY KEY (document_id) )\nCREATE TABLE legal_services.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 ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the name of each law firm and the full name of its managing partner."}, {"role": "assistant", "content": "SELECT T1.firm_name, T2.first_name, T2.last_name FROM law_firms AS T1 JOIN lawyers AS T2 ON T1.managing_partner_id = T2.lawyer_id;"}, {"role": "user", "content": "Only include firms founded before '2010-01-01' and exclude those without a managing partner listed."}, {"role": "assistant", "content": "SELECT T1.firm_name, T2.first_name, T2.last_name FROM law_firms AS T1 JOIN lawyers AS T2 ON T1.managing_partner_id = T2.lawyer_id WHERE T1.founded_date < '2010-01-01';"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nIndex 'component_inventory'. Mapping: { properties: { inventory_record_id: { type: 'keyword' }, component_id: { type: 'keyword' }, quantity: { type: 'integer' }, location_warehouse: { type: 'keyword' }, location_bin: { type: 'keyword' }, received_date: { type: 'date' }, expiry_date: { type: 'date' }, batch_number: { type: 'keyword' }, last_updated: { type: 'date' } } }. Document _id can be inventory_record_id.\n", "conversations": [{"role": "user", "content": "\u7279\u5b9a\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u5728\u5eab\u60c5\u5831\u3092\u53d6\u5f97\u3057\u305f\u3044\u3067\u3059\u3002\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8ID\u3068\u5728\u5eab\u6570\u91cf\u3001\u5009\u5eab\u306e\u5834\u6240\u3092\u542b\u3081\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id';"}, {"role": "user", "content": "\u3055\u3089\u306b\u3001\u53d7\u3051\u53d6\u308a\u65e5\u304c2022\u5e74\u4ee5\u964d\u306e\u8a18\u9332\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u3067\u304d\u307e\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01';"}, {"role": "user", "content": "\u5728\u5eab\u6570\u91cf\u304c100\u672a\u6e80\u306e\u3082\u306e\u3060\u3051\u306b\u7d5e\u308a\u8fbc\u3080\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u304b\uff1f"}, {"role": "assistant", "content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01' AND quantity < 100;"}, {"role": "user", "content": "\u6700\u5f8c\u306b\u3001\u53d7\u3051\u53d6\u308a\u65e5\u3092\u65b0\u3057\u3044\u9806\u306b\u4e26\u3079\u66ff\u3048\u3066\u304f\u3060\u3055\u3044\u3002"}, {"role": "assistant", "content": "SELECT component_id, quantity, location_warehouse FROM component_inventory WHERE component_id = 'specific_component_id' AND received_date >= '2022-01-01' AND quantity < 100 ORDER BY received_date DESC;"}]} -{"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 social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Count the number of posts that have received at least one comment."}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT post_id) FROM social_media.comments"}]} -{"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 web3.token_transfers (\n transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer\n token_id character varying(64) NOT NULL, -- identifier of the token being transferred\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128) NOT NULL, -- address of the receiver\n value numeric(38,14) NOT NULL, -- amount of tokens transferred\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer\n log_index integer NOT NULL, -- index of the transfer log in the transaction\n PRIMARY KEY (transfer_id)\n)\n", "conversations": [{"role": "user", "content": "For each sender address, count how many distinct tokens they have transferred. Show from_address and token_count."}, {"role": "assistant", "content": "SELECT from_address, COUNT(DISTINCT token_id) AS token_count\nFROM web3.token_transfers\nGROUP BY from_address;"}, {"role": "user", "content": "Now filter to only include senders who have transferred more than 5 distinct tokens."}, {"role": "assistant", "content": "SELECT from_address, COUNT(DISTINCT token_id) AS token_count\nFROM web3.token_transfers\nGROUP BY from_address\nHAVING COUNT(DISTINCT token_id) > 5;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE manufacturing.components (\n component_id character varying(64) NOT NULL, -- unique identifier for the component\n part_number character varying(100) NOT NULL UNIQUE, -- manufacturer-specific part number\n component_name character varying(255) NOT NULL, -- descriptive name (e.g., Landing Gear Strut, Wing Spar)\n description text, -- detailed description\n material_id character varying(64), -- FK linking to the material used\n supplier_id character varying(64), -- FK linking to the supplier\n weight_kg numeric(10,3), -- weight of the component in kg\n cost_usd numeric(12,2), -- cost of the component in USD\n criticality_level character varying(20), -- e.g., 'High', 'Medium', 'Low'\n PRIMARY KEY (component_id)\n)\nCREATE TABLE manufacturing.suppliers (\n supplier_id character varying(64) NOT NULL, -- unique identifier for the supplier\n supplier_name character varying(255) NOT NULL, -- legal name of the supplier company\n address text, -- primary address of the supplier\n country character varying(100), -- country of the supplier\n contact_person character varying(128), -- primary contact person\n contact_email character varying(128), -- contact email\n quality_rating numeric(3,1), -- supplier quality rating (e.g., 1.0 to 5.0)\n certified_date date, -- date when supplier certification was last validated\n PRIMARY KEY (supplier_id)\n)\nCREATE TABLE manufacturing.materials (\n material_id character varying(64) NOT NULL, -- unique identifier for the material\n material_name character varying(128) NOT NULL, -- common name (e.g., Titanium Alloy Grade 5, Carbon Fiber Prepreg)\n specification character varying(255), -- specification standard (e.g., AMS 4928)\n description text, -- detailed description of properties\n density_kg_m3 numeric(10, 4), -- density in kg per cubic meter\n tensile_strength_mpa integer, -- tensile strength in Megapascals\n PRIMARY KEY (material_id)\n)\nCREATE TABLE manufacturing.assembly_steps (\n step_id character varying(64) NOT NULL, -- unique identifier for an assembly step/task\n line_id character varying(64) NOT NULL, -- FK to the assembly line where this step occurs\n step_number integer NOT NULL, -- sequence number of the step on the line\n step_name character varying(255) NOT NULL, -- name of the task (e.g., Install Wing Root Fairing)\n description text, -- detailed instructions or description\n standard_duration_hours numeric(8,2), -- estimated time to complete the step\n required_skill_level character varying(50), -- skill level needed (e.g., 'Mechanic II', 'Electrician I')\n workstation character varying(100), -- specific workstation or area for the step\n PRIMARY KEY (step_id)\n)\nCREATE TABLE manufacturing.inspections (\n inspection_id character varying(64) NOT NULL, -- unique identifier for the inspection event\n build_id character varying(64) NOT NULL, -- FK to the specific aircraft build being inspected\n component_id character varying(64), -- FK to the specific component inspected (if applicable)\n step_id character varying(64), -- FK to the assembly step after which inspection occurred (if applicable)\n inspection_type character varying(100) NOT NULL, -- e.g., 'Visual', 'NDT', 'Functional Test'\n inspector_employee_id character varying(64) NOT NULL, -- FK to the employee who performed the inspection\n inspection_timestamp timestamp NOT NULL, -- time when the inspection was completed\n result character varying(20) NOT NULL, -- 'Pass', 'Fail', 'Rework Needed'\n remarks text, -- detailed notes or findings\n PRIMARY KEY (inspection_id)\n)\nCREATE TABLE manufacturing.component_inventory (\n inventory_record_id character varying(64) NOT NULL, -- unique ID for this inventory record/batch\n component_id character varying(64) NOT NULL, -- FK to the component\n quantity integer NOT NULL, -- number of units of this component in stock for this batch\n location_warehouse character varying(100), -- warehouse identifier\n location_bin character varying(100), -- specific bin or shelf location\n received_date timestamp NOT NULL, -- when this batch was received\n expiry_date date, -- expiry date if applicable (e.g., for sealants, adhesives)\n batch_number character varying(100), -- supplier batch number\n last_updated timestamp NOT NULL, -- timestamp of the last update to this record\n PRIMARY KEY (inventory_record_id)\n)\n", "conversations": [{"role": "user", "content": "\u6211\u60f3\u67e5\u8be2\u67d0\u4e2a\u7ec4\u4ef6\u7684\u68c0\u67e5\u8bb0\u5f55\uff0c\u5305\u62ec\u68c0\u67e5\u7c7b\u578b\u3001\u68c0\u67e5\u7ed3\u679c\u548c\u68c0\u67e5\u65f6\u95f4\uff0c\u540c\u65f6\u8fd8\u9700\u8981\u7ec4\u4ef6\u7684\u540d\u79f0\u548c\u63cf\u8ff0\u3002"}, {"role": "assistant", "content": "SELECT i.inspection_type, i.result, i.inspection_timestamp, c.component_name, c.description\nFROM manufacturing.inspections i\nJOIN manufacturing.components c ON i.component_id = c.component_id\nWHERE c.component_id = 'specific_component_id';"}, {"role": "user", "content": "\u80fd\u4e0d\u80fd\u53ea\u663e\u793a\u68c0\u67e5\u7ed3\u679c\u4e3a'Fail'\u7684\u8bb0\u5f55\uff1f"}, {"role": "assistant", "content": "SELECT i.inspection_type, i.result, i.inspection_timestamp, c.component_name, c.description\nFROM manufacturing.inspections i\nJOIN manufacturing.components c ON i.component_id = c.component_id\nWHERE c.component_id = 'specific_component_id' AND i.result = 'Fail';"}, {"role": "user", "content": "\u5982\u679c\u6211\u60f3\u8fdb\u4e00\u6b65\u7b5b\u9009\u51fa\u68c0\u67e5\u65f6\u95f4\u5728\u8fc7\u53bb\u4e00\u4e2a\u6708\u5185\u7684\u8bb0\u5f55\uff0c\u5e94\u8be5\u600e\u4e48\u505a\uff1f"}, {"role": "assistant", "content": "SELECT i.inspection_type, i.result, i.inspection_timestamp, c.component_name, c.description\nFROM manufacturing.inspections i\nJOIN manufacturing.components c ON i.component_id = c.component_id\nWHERE c.component_id = 'specific_component_id' AND i.result = 'Fail' AND i.inspection_timestamp >= NOW() - INTERVAL '1 month';"}, {"role": "user", "content": "\u8bf7\u518d\u52a0\u4e0a\u68c0\u67e5\u5907\u6ce8\u4fe1\u606f\uff0c\u5e76\u6309\u68c0\u67e5\u65f6\u95f4\u4ece\u65b0\u5230\u65e7\u6392\u5e8f\u3002"}, {"role": "assistant", "content": "SELECT i.inspection_type, i.result, i.inspection_timestamp, c.component_name, c.description, i.remarks\nFROM manufacturing.inspections i\nJOIN manufacturing.components c ON i.component_id = c.component_id\nWHERE c.component_id = 'specific_component_id' AND i.result = 'Fail' AND i.inspection_timestamp >= NOW() - INTERVAL '1 month'\nORDER BY i.inspection_timestamp DESC;"}]} -{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Find pairs of distinct locations in the same city that have different types. Include location IDs, names, city, and type for both locations."}, {"role": "assistant", "content": "SELECT l1.location_id AS location1_id, l1.name AS location1_name, l1.city, l1.type AS location1_type, l2.location_id AS location2_id, l2.name AS location2_name, l2.type AS location2_type FROM transportation.locations AS l1 JOIN transportation.locations AS l2 ON l1.city = l2.city AND l1.location_id < l2.location_id WHERE l1.type != l2.type;"}]} -{"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 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 )\n", "conversations": [{"role": "user", "content": "Find pairs of reservations for the same guest at the same property where the check-in date of the second reservation is the same as the check-out date of the first reservation. List guest ID, property ID, and both reservation IDs."}, {"role": "assistant", "content": "SELECT r1.guest_id, r1.property_id, r1.reservation_id AS first_reservation_id, r2.reservation_id AS second_reservation_id FROM reservations r1 JOIN reservations r2 ON r1.guest_id = r2.guest_id AND r1.property_id = r2.property_id AND r1.check_out_date = r2.check_in_date AND r1.reservation_id != r2.reservation_id;"}, {"role": "user", "content": "Only include pairs where the first reservation had a status of 'CheckedOut'."}, {"role": "assistant", "content": "SELECT r1.guest_id, r1.property_id, r1.reservation_id AS first_reservation_id, r2.reservation_id AS second_reservation_id FROM reservations r1 JOIN reservations r2 ON r1.guest_id = r2.guest_id AND r1.property_id = r2.property_id AND r1.check_out_date = r2.check_in_date AND r1.reservation_id != r2.reservation_id WHERE r1.status = 'CheckedOut';"}, {"role": "user", "content": "Additionally, filter to show only those pairs where the first reservation occurred in 2023."}, {"role": "assistant", "content": "SELECT r1.guest_id, r1.property_id, r1.reservation_id AS first_reservation_id, r2.reservation_id AS second_reservation_id FROM reservations r1 JOIN reservations r2 ON r1.guest_id = r2.guest_id AND r1.property_id = r2.property_id AND r1.check_out_date = r2.check_in_date AND r1.reservation_id != r2.reservation_id WHERE r1.status = 'CheckedOut' AND EXTRACT(YEAR FROM r1.check_in_date) = 2023;"}]} -{"system": "You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE manufacturing.aircraft_models ( model_id.text, model_name.text, manufacturer.text, passenger_capacity.integer, max_range_km.integer, engine_type.text, wingspan_m.numeric, status.text, first_flight_date.date )\n", "conversations": [{"role": "user", "content": "What are the fuel consumption rates per hour for the Boeing 747-8 model?"}, {"role": "assistant", "content": "I'm sorry, but I can't provide information on the fuel consumption rates for the Boeing 747-8 model as this data is not included in the aircraft_models table. The table contains details such as model name, manufacturer, passenger capacity, and other specifications, but fuel consumption data is not available. If you have another question or need assistance with something else related to the table, I'm happy to help."}]} +{"system": "You are an 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 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.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\n", "conversations": [{"role": "user", "content": "List all room types along with their property name, bed type, and base rate for properties located in Canada, ordered by base rate descending."}, {"role": "assistant", "content": "SELECT rt.type_name, p.property_name, rt.bed_type, rt.base_rate\nFROM hospitality_technology.room_types rt\nJOIN hospitality_technology.properties p\n ON rt.property_id = p.property_id\nWHERE p.country_code = 'CA'\nORDER BY rt.base_rate DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text 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.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": "For each property, show the property name and the count of staff members with the position 'Manager'."}, {"role": "assistant", "content": "SELECT\n p.property_name,\n COUNT(s.staff_id) AS manager_count\nFROM hospitality_technology.properties AS p\nJOIN hospitality_technology.staff AS s\n ON p.property_id = s.property_id\nWHERE\n s.position = 'Manager'\nGROUP BY\n p.property_name;"}, {"role": "user", "content": "Now, only include properties located in the state of 'California' and sort the results by the count of managers descending."}, {"role": "assistant", "content": "SELECT\n p.property_name,\n COUNT(s.staff_id) AS manager_count\nFROM hospitality_technology.properties AS p\nJOIN hospitality_technology.staff AS s\n ON p.property_id = s.property_id\nWHERE\n s.position = 'Manager' AND p.state_province = 'California'\nGROUP BY\n p.property_name\nORDER BY\n manager_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.rooms (\n room_id character varying(64) NOT NULL, -- unique identifier for the room\n property_id character varying(64) NOT NULL, -- FK to properties table\n room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B')\n room_type_id character varying(64) NOT NULL, -- FK to room_types table\n floor integer, -- floor number the room is on\n status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance\n is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag\n features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi)\n current_condition text, -- notes on room condition\n last_cleaned_at timestamp with time zone, -- timestamp of last cleaning\n PRIMARY KEY (room_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\n", "conversations": [{"role": "user", "content": "List all rooms, showing their room number, type name, and the name of the property they are in."}, {"role": "assistant", "content": "SELECT T1.room_number, T2.type_name, T3.property_name FROM hospitality_technology.rooms AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.room_type_id = T2.room_type_id JOIN hospitality_technology.properties AS T3 ON T1.property_id = T3.property_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_profit ( address.text, rank.numeric, profit.numeric, roi.numeric, realized_ratio.numeric, most_profit_token.text, last_trade_time.text, chain.text )\n", "conversations": [{"role": "user", "content": "List the top 3 addresses with the highest profit on the Arbitrum chain, including roi and most_profit_token."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}, {"role": "user", "content": "Please add the realized_ratio and last_trade_time for each result."}, {"role": "assistant", "content": "SELECT address, profit, roi, most_profit_token, realized_ratio, last_trade_time FROM smart_money_profit WHERE chain = 'Arbitrum' ORDER BY profit DESC LIMIT 3;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\nCREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n", "conversations": [{"role": "user", "content": "For the 'DeFi' narrative, what is the average ROI and the total net inflow (usd_value where type=1) from smart money token inflow?"}, {"role": "assistant", "content": "SELECT AVG(sm.roi) AS avg_roi, SUM(smt.usd_value) AS total_net_inflow\nFROM smart_money_token_inflow smt\nJOIN smart_money_profit sm ON smt.chain = sm.chain\nWHERE smt.narrative = 'DeFi' AND smt.type = 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\nCREATE TABLE cex_token_balance ( snapshot_time text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n", "conversations": [{"role": "user", "content": "Which are the top 3 tokens on BSC by total USD value held by all CEXs, and what is their narrative and current price?"}, {"role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nORDER BY total_usd_value DESC\nLIMIT 3;"}, {"role": "user", "content": "Can you also show, for each token, the number of CEX addresses holding it?"}, {"role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, COUNT(DISTINCT ctb.address) AS cex_address_count, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nORDER BY total_usd_value DESC\nLIMIT 3;"}, {"role": "user", "content": "Only include tokens with total USD value above 1,000,000."}, {"role": "assistant", "content": "SELECT ctb.token_symbol, tbi.narrative, tbi.price, COUNT(DISTINCT ctb.address) AS cex_address_count, SUM(ctb.usd_value) AS total_usd_value\nFROM cex_token_balance ctb\nJOIN token_basic_info tbi ON ctb.token_symbol = tbi.token_symbol AND ctb.chain = tbi.chain\nWHERE ctb.chain = 'BSC'\nGROUP BY ctb.token_symbol, tbi.narrative, tbi.price\nHAVING SUM(ctb.usd_value) > 1000000\nORDER BY total_usd_value DESC\nLIMIT 3;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\n", "conversations": [{"role": "user", "content": "Show the tokens with a negative net flow this month on all chains."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now());"}, {"role": "user", "content": "Order them by net flow ascending and only show the bottom 5."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now()) ORDER BY net_flow ASC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\n", "conversations": [{"role": "user", "content": "List addresses on the 'Ethereum' chain that have an ROI greater than 5 and a profit greater than $1000. Show their address, profit, ROI, and realized ratio."}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000"}, {"role": "user", "content": "Can you order these addresses by their profit in descending order?"}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000 ORDER BY profit DESC"}, {"role": "user", "content": "Only show addresses whose last trade time is in 2024."}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000 AND last_trade_time LIKE '2024%' ORDER BY profit DESC"}, {"role": "user", "content": "Include the rank of these addresses in the output and show only the top 5 results."}, {"role": "assistant", "content": "SELECT address, profit, roi, realized_ratio, rank FROM smart_money_profit WHERE chain = 'Ethereum' AND roi > 5 AND profit > 1000 AND last_trade_time LIKE '2024%' ORDER BY profit DESC LIMIT 5"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id 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.transactions ( transaction_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, related_account_id character varying(64), transaction_type character varying(50) NOT NULL, amount numeric(19, 4) NOT NULL, currency character varying(3) NOT NULL, transaction_date timestamp NOT NULL, effective_date date NOT NULL, description text, status character varying(32) NOT NULL, reference_number character varying(128), PRIMARY KEY (transaction_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id) )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data (\n data_point_id bigserial NOT NULL, -- auto-incrementing primary key\n security_id character varying(64) NOT NULL, -- identifier for the security\n data_timestamp timestamp NOT NULL, -- timestamp for the data point (e.g., end of day, intraday)\n open_price numeric(19, 8), -- opening price for the period\n high_price numeric(19, 8), -- highest price during the period\n low_price numeric(19, 8), -- lowest price during the period\n close_price numeric(19, 8) NOT NULL, -- closing price for the period\n adjusted_close_price numeric(19, 8), -- closing price adjusted for dividends and splits\n volume bigint, -- trading volume during the period\n source character varying(50), -- source of the market data (e.g., Bloomberg, Refinitiv)\n PRIMARY KEY (data_point_id),\n UNIQUE (security_id, data_timestamp), -- Ensure unique data point per security per time\n FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id)\n)\nCREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )\n", "conversations": [{"role": "user", "content": "Which customers have traded securities with the highest average trading amount per trade across all their accounts? Show me the customer full name, email, and the average trade amount for each customer."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS full_name, c.email, AVG(t.total_amount) AS avg_trade_amount\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email;"}, {"role": "user", "content": "Actually, I'd like to see only those customers whose average trade amount is above 5000 and who have executed at least 3 trades. Can you add those filters and show the customer id too?"}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name || ' ' || c.last_name AS full_name, c.email, AVG(t.total_amount) AS avg_trade_amount, COUNT(t.trade_id) AS trade_count\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email\nHAVING AVG(t.total_amount) > 5000 AND COUNT(t.trade_id) >= 3;"}, {"role": "user", "content": "I'd also like to see the total traded quantity per customer in this result. Please include it and sort the output by avg_trade_amount descending."}, {"role": "assistant", "content": "SELECT c.customer_id, c.first_name || ' ' || c.last_name AS full_name, c.email, AVG(t.total_amount) AS avg_trade_amount, COUNT(t.trade_id) AS trade_count, SUM(t.quantity) AS total_traded_quantity\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.trades t ON a.account_id = t.account_id\nGROUP BY c.customer_id, c.first_name, c.last_name, c.email\nHAVING AVG(t.total_amount) > 5000 AND COUNT(t.trade_id) >= 3\nORDER BY avg_trade_amount DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )\nCREATE TABLE financial_services.accounts ( account_id.text, customer_id.text, account_number.text, account_type.text, balance.numeric, currency.text, opened_date.date, status.text, interest_rate.numeric, last_updated_at.timestamp )\nCREATE TABLE financial_services.transactions ( 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.employees ( employee_id.text, first_name.text, last_name.text, job_title.text, department.text, branch_id.text, email.text, phone_extension.text, hire_date.date, termination_date.date, manager_id.text, status.text )\nCREATE TABLE financial_services.loans ( loan_id.text, account_id.text, loan_type.text, principal_amount.numeric, current_principal_balance.numeric, interest_rate.numeric, term_months.integer, origination_date.date, maturity_date.date, monthly_payment.numeric, collateral_description.text, status.text )\n", "conversations": [{"role": "user", "content": "Show me all employees (employee_id, first_name, last_name) in the 'Investment' department who have processed loans (loan_id) with a principal amount greater than $100,000, along with the count of such loans for each employee."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name, e.last_name, COUNT(l.loan_id) AS loan_count\nFROM financial_services.employees e\nJOIN financial_services.loans l ON e.employee_id = l.account_id\nWHERE e.department = 'Investment' AND l.principal_amount > 100000\nGROUP BY e.employee_id, e.first_name, e.last_name"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.securities ( security_id text, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.trades ( trade_id text, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.employees ( employee_id text, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "Can you list all securities that have had at least one trade in the past 30 days? Please include the ticker_symbol, security_name, exchange, and the total number of trades for each security."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY s.ticker_symbol, s.security_name, s.exchange;"}, {"role": "user", "content": "I want to see the average trade quantity as well for each security in the same result."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count, AVG(t.quantity) AS avg_quantity\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY s.ticker_symbol, s.security_name, s.exchange;"}, {"role": "user", "content": "I need only those securities where the average trade quantity is above 100. Please order by avg_quantity descending."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count, AVG(t.quantity) AS avg_quantity\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY s.ticker_symbol, s.security_name, s.exchange\nHAVING AVG(t.quantity) > 100\nORDER BY avg_quantity DESC;"}, {"role": "user", "content": "Instead, show only securities traded on the 'NASDAQ' or 'NYSE' exchanges."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, s.security_name, s.exchange, COUNT(t.trade_id) AS trade_count, AVG(t.quantity) AS avg_quantity\nFROM financial_services.securities s\nJOIN financial_services.trades t ON s.security_id = t.security_id\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\n AND s.exchange IN ('NASDAQ', 'NYSE')\nGROUP BY s.ticker_symbol, s.security_name, s.exchange\nHAVING AVG(t.quantity) > 100\nORDER BY avg_quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\n", "conversations": [{"role": "user", "content": "Give me the number of active customers grouped by city."}, {"role": "assistant", "content": "SELECT city, COUNT(*) AS customer_count FROM financial_services.customers WHERE status = 'Active' GROUP BY city;"}, {"role": "user", "content": "Actually, only include cities with at least 10 active customers."}, {"role": "assistant", "content": "SELECT city, COUNT(*) AS customer_count FROM financial_services.customers WHERE status = 'Active' GROUP BY city HAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Also, order the results by customer_count ascending."}, {"role": "assistant", "content": "SELECT city, COUNT(*) AS customer_count FROM financial_services.customers WHERE status = 'Active' GROUP BY city HAVING COUNT(*) >= 10 ORDER BY customer_count ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.trades ( trade_id.text, account_id.text, security_id.text, order_id.text, trade_type.text, quantity.numeric, price_per_unit.numeric, total_amount.numeric, commission.numeric, trade_timestamp.timestamp, settlement_date.date, status.text, execution_venue.text )\nCREATE TABLE financial_services.employees ( employee_id text, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "For each employee who serves as a relationship manager, what is the total transaction amount processed for the accounts they manage?"}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, SUM(t.amount) AS total_managed_transaction_amount FROM financial_services.employees e JOIN financial_services.accounts a ON e.employee_id = a.relationship_manager_id JOIN financial_services.transactions t ON a.account_id = t.account_id GROUP BY e.employee_id, e.first_name, e.last_name;"}, {"role": "user", "content": "Only include transactions with a status of 'Completed' in this calculation."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, SUM(t.amount) AS total_managed_transaction_amount FROM financial_services.employees e JOIN financial_services.accounts a ON e.employee_id = a.relationship_manager_id JOIN financial_services.transactions t ON a.account_id = t.account_id WHERE t.status = 'Completed' GROUP BY e.employee_id, e.first_name, e.last_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n", "conversations": [{"role": "user", "content": "Find all distinct pairs of customers having the same first_name but living in different cities. Display a.customer_id, a.first_name, a.city AS city_a, b.customer_id, b.city AS city_b."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a,\n a.first_name,\n a.city AS city_a,\n b.customer_id AS customer_id_b,\n b.city AS city_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.first_name = b.first_name\n AND a.city <> b.city\n AND a.customer_id < b.customer_id;"}, {"role": "user", "content": "Only include pairs where both customers have status 'Active'."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a,\n a.first_name,\n a.city AS city_a,\n b.customer_id AS customer_id_b,\n b.city AS city_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.first_name = b.first_name\n AND a.city <> b.city\n AND a.customer_id < b.customer_id\nWHERE a.status = 'Active'\n AND b.status = 'Active';"}, {"role": "user", "content": "Sort the output by first_name ascending and then by customer_id_a ascending."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_id_a,\n a.first_name,\n a.city AS city_a,\n b.customer_id AS customer_id_b,\n b.city AS city_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.first_name = b.first_name\n AND a.city <> b.city\n AND a.customer_id < b.customer_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\nORDER BY a.first_name ASC,\n customer_id_a ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n", "conversations": [{"role": "user", "content": "I want to see pairs of customers living in the same state but having different risk profiles. Show their customer_ids, states, and risk_profiles."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile;"}, {"role": "user", "content": "Exclude any pairs where either customer has a null phone_number."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL;"}, {"role": "user", "content": "Ensure each pair appears only once, without reversed duplicates."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL AND a.customer_id < b.customer_id;"}, {"role": "user", "content": "Finally, only include states that have more than 3 customers in total."}, {"role": "assistant", "content": "SELECT a.customer_id AS customer_a, a.state, a.risk_profile AS risk_profile_a, b.customer_id AS customer_b, b.risk_profile AS risk_profile_b FROM financial_services.customers a JOIN financial_services.customers b ON a.state = b.state AND a.risk_profile <> b.risk_profile WHERE a.phone_number IS NOT NULL AND b.phone_number IS NOT NULL AND a.customer_id < b.customer_id AND a.state IN (SELECT state FROM financial_services.customers GROUP BY state HAVING COUNT(*) > 3);"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.securities (\n security_id character varying(64) NOT NULL, -- unique identifier for the security\n ticker_symbol character varying(20) NOT NULL UNIQUE, -- stock ticker or fund symbol\n isin_code character varying(12) UNIQUE, -- International Securities Identification Number\n cusip_code character varying(9) UNIQUE, -- CUSIP number\n security_name text NOT NULL, -- full name of the security\n security_type character varying(50) NOT NULL, -- e.g., Stock, Bond, ETF, Mutual Fund, Option, Future\n exchange character varying(50), -- primary exchange where traded (e.g., NYSE, NASDAQ)\n currency character varying(3) NOT NULL, -- currency the security is denominated in\n issuer_name character varying(255), -- name of the issuing entity\n sector character varying(100), -- industry sector\n last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (security_id)\n)\n", "conversations": [{"role": "user", "content": "List pairs of securities that trade on different exchanges but belong to the same sector, showing ticker_symbol of both as symbol_a and symbol_b, their exchanges, and the sector."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.ticker_symbol < b.ticker_symbol;"}, {"role": "user", "content": "Actually, exclude any pairs where the sector is NULL and ensure uniqueness by requiring symbol_a < symbol_b."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.sector IS NOT NULL\n AND a.ticker_symbol < b.ticker_symbol;"}, {"role": "user", "content": "Now also order the results by sector ascending and symbol_a ascending."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.sector IS NOT NULL\n AND a.ticker_symbol < b.ticker_symbol\nORDER BY a.sector ASC, a.ticker_symbol ASC;"}, {"role": "user", "content": "Finally, only include pairs where both securities are denominated in USD."}, {"role": "assistant", "content": "SELECT a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b\n ON a.sector = b.sector\n AND a.exchange <> b.exchange\nWHERE a.sector IS NOT NULL\n AND a.currency = 'USD'\n AND b.currency = 'USD'\n AND a.ticker_symbol < b.ticker_symbol\nORDER BY a.sector ASC, a.ticker_symbol ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id text PRIMARY KEY, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions ( transaction_id text PRIMARY KEY, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )\nCREATE TABLE financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n", "conversations": [{"role": "user", "content": "List all employees and the branch they work at, along with their job title and department."}, {"role": "assistant", "content": "SELECT employee_id, first_name || ' ' || last_name AS full_name, job_title, department, branch_id\nFROM financial_services.employees;"}, {"role": "user", "content": "Add the full name of each employee's manager to the result. If there is no manager, show NULL."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS full_name, e.job_title, e.department, e.branch_id, m.first_name || ' ' || m.last_name AS manager_full_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id;"}, {"role": "user", "content": "Only include employees who are currently active, and sort the list by department, then by full_name."}, {"role": "assistant", "content": "SELECT e.employee_id, e.first_name || ' ' || e.last_name AS full_name, e.job_title, e.department, e.branch_id, m.first_name || ' ' || m.last_name AS manager_full_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.status = 'Active'\nORDER BY e.department, full_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.securities ( security_id text PRIMARY KEY, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\n", "conversations": [{"role": "user", "content": "List all securities (security_id, ticker_symbol, security_name) that have a currency of 'EUR' and were last updated within the last 30 days, along with their exchange and sector information."}, {"role": "assistant", "content": "SELECT security_id, ticker_symbol, security_name, exchange, sector FROM financial_services.securities WHERE currency = 'EUR' AND last_updated >= CURRENT_DATE - INTERVAL '30 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\n", "conversations": [{"role": "user", "content": "Provide for each security its ticker_symbol, the most recent close_price and corresponding timestamp."}, {"role": "assistant", "content": "SELECT s.ticker_symbol, md.close_price, md.data_timestamp\nFROM financial_services.market_data md\nJOIN financial_services.securities s ON md.security_id = s.security_id\nWHERE md.data_timestamp = (\n SELECT MAX(md2.data_timestamp)\n FROM financial_services.market_data md2\n WHERE md2.security_id = md.security_id\n);"}, {"role": "user", "content": "Actually, I'd like to filter to only those securities where the latest adjusted_close_price is at least 2% higher than the previous data point."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT md.security_id, s.ticker_symbol, md.data_timestamp, md.adjusted_close_price,\n LAG(md.adjusted_close_price) OVER (PARTITION BY md.security_id ORDER BY md.data_timestamp) AS prev_adj\n FROM financial_services.market_data md\n JOIN financial_services.securities s ON md.security_id = s.security_id\n)\nSELECT r.ticker_symbol, r.data_timestamp AS latest_timestamp, r.adjusted_close_price\nFROM ranked r\nWHERE r.data_timestamp = (\n SELECT MAX(r2.data_timestamp) FROM ranked r2 WHERE r2.security_id = r.security_id\n )\n AND r.adjusted_close_price >= r.prev_adj * 1.02;"}, {"role": "user", "content": "The SQL gives errors about ambiguous column names. Please fully qualify all columns and table aliases."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT md.security_id, s.ticker_symbol, md.data_timestamp, md.adjusted_close_price,\n LAG(md.adjusted_close_price) OVER (PARTITION BY md.security_id ORDER BY md.data_timestamp) AS prev_adj\n FROM financial_services.market_data AS md\n JOIN financial_services.securities AS s ON md.security_id = s.security_id\n)\nSELECT ranked.ticker_symbol,\n ranked.data_timestamp AS latest_timestamp,\n ranked.adjusted_close_price\nFROM ranked\nWHERE ranked.data_timestamp = (\n SELECT MAX(r2.data_timestamp)\n FROM ranked AS r2\n WHERE r2.security_id = ranked.security_id\n )\n AND ranked.adjusted_close_price >= ranked.prev_adj * 1.02;"}]} +{"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 trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "Retrieve all orders placed after '2024-06-01', including order_id, user_id, asset_id, quantity, and price."}, {"role": "assistant", "content": "SELECT order_id, user_id, asset_id, quantity, price\nFROM trading_platform.orders\nWHERE created_at > '2024-06-01';"}, {"role": "user", "content": "Actually, only include orders for assets whose metadata key is 'category' and value is 'cryptocurrency'."}, {"role": "assistant", "content": "SELECT o.order_id, o.user_id, o.asset_id, o.quantity, o.price\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m ON o.asset_id = m.asset_id\nWHERE o.created_at > '2024-06-01'\n AND m.key = 'category' AND m.value = 'cryptocurrency';"}, {"role": "user", "content": "Now, count the number of such orders per asset, along with the asset_id."}, {"role": "assistant", "content": "SELECT o.asset_id, COUNT(*) AS order_count\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m ON o.asset_id = m.asset_id\nWHERE o.created_at > '2024-06-01'\n AND m.key = 'category' AND m.value = 'cryptocurrency'\nGROUP BY o.asset_id;"}, {"role": "user", "content": "Finally, only show assets with more than 5 such orders, ordered by order_count descending."}, {"role": "assistant", "content": "SELECT o.asset_id, COUNT(*) AS order_count\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m ON o.asset_id = m.asset_id\nWHERE o.created_at > '2024-06-01'\n AND m.key = 'category' AND m.value = 'cryptocurrency'\nGROUP BY o.asset_id\nHAVING COUNT(*) > 5\nORDER BY order_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\n", "conversations": [{"role": "user", "content": "Count the number of metadata entries for each asset."}, {"role": "assistant", "content": "SELECT asset_id, COUNT(*) AS metadata_count\nFROM trading_platform.metadata\nGROUP BY asset_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "For each user, show their username and the number of unique IP addresses from the peers table where the port is less than 2000."}, {"role": "assistant", "content": "SELECT u.username, COUNT(DISTINCT p.ip_address) AS unique_ip_count\nFROM trading_platform.users u\nJOIN trading_platform.peers p ON u.user_id = p.peer_id\nWHERE p.port < 2000\nGROUP BY u.username;"}, {"role": "user", "content": "This query isn't working because peer_id and user_id don't always match. Could you just show the total number of unique IPs with port < 2000 in the peers table, excluding user data?"}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT ip_address) AS unique_ip_count\nFROM trading_platform.peers\nWHERE port < 2000;"}, {"role": "user", "content": "Now, for each port number below 2000, show the count of unique IP addresses using that port."}, {"role": "assistant", "content": "SELECT port, COUNT(DISTINCT ip_address) AS unique_ip_count\nFROM trading_platform.peers\nWHERE port < 2000\nGROUP BY port;"}, {"role": "user", "content": "Actually, only show ports where more than one unique IP address exists."}, {"role": "assistant", "content": "SELECT port, COUNT(DISTINCT ip_address) AS unique_ip_count\nFROM trading_platform.peers\nWHERE port < 2000\nGROUP BY port\nHAVING COUNT(DISTINCT ip_address) > 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\n", "conversations": [{"role": "user", "content": "I want to see the number of 'buy' and 'sell' orders for each asset, along with the asset_id."}, {"role": "assistant", "content": "SELECT asset_id, order_type, COUNT(*) AS order_count FROM trading_platform.orders GROUP BY asset_id, order_type;"}, {"role": "user", "content": "Can you also show the average price for 'buy' and 'sell' orders for each asset?"}, {"role": "assistant", "content": "SELECT asset_id, order_type, COUNT(*) AS order_count, AVG(price) AS avg_price FROM trading_platform.orders GROUP BY asset_id, order_type;"}]} +{"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 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.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets ( asset_id 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.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n", "conversations": [{"role": "user", "content": "Show me the usernames of buyers along with the names of assets they have traded."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, a.name AS asset_name\nFROM trading_platform.trades t\nJOIN trading_platform.users u ON t.buyer_id = u.user_id\nJOIN trading_platform.assets a ON t.asset_id = a.asset_id;"}, {"role": "user", "content": "Add the trade quantity for each user and asset pair."}, {"role": "assistant", "content": "SELECT u.username, a.name AS asset_name, SUM(t.quantity) AS total_quantity\nFROM trading_platform.trades t\nJOIN trading_platform.users u ON t.buyer_id = u.user_id\nJOIN trading_platform.assets a ON t.asset_id = a.asset_id\nGROUP BY u.username, a.name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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)\n", "conversations": [{"role": "user", "content": "Show the name, symbol, and total quantity traded for each asset."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol;"}, {"role": "user", "content": "Only show assets with a total traded quantity less than 50 and order them by total_quantity_traded ascending."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COALESCE(SUM(t.quantity), 0) < 50\nORDER BY total_quantity_traded ASC;"}, {"role": "user", "content": "Some assets have never been traded and do not appear in the result. Please include those assets as well, with total_quantity_traded as 0."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COALESCE(SUM(t.quantity), 0) < 50 OR SUM(t.quantity) IS NULL\nORDER BY total_quantity_traded ASC;"}, {"role": "user", "content": "I noticed that assets with no trades still appear, but the column name is inconsistent when there are no trades. Can you make sure total_quantity_traded always appears as 0 for such assets and is labeled consistently?"}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COALESCE(SUM(t.quantity), 0) AS total_quantity_traded\nFROM trading_platform.assets a\nLEFT JOIN trading_platform.trades t ON t.asset_id = a.asset_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COALESCE(SUM(t.quantity), 0) < 50\nORDER BY total_quantity_traded ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n", "conversations": [{"role": "user", "content": "List all DApps along with the number of metadata entries linked to each, even if the DApp has no linked metadata."}, {"role": "assistant", "content": "SELECT d.name, d.url, COUNT(m.metadata_id) AS metadata_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON d.dapp_id = m.asset_id\nGROUP BY d.dapp_id, d.name, d.url;"}]} +{"system": "You are an 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 trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\n", "conversations": [{"role": "user", "content": "Provide a summary for each user, showing their user_id, username, and the total number of orders they have placed overall."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders\nFROM trading_platform.users u\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Now filter to include only users who have 'approved' status in the KYC audit."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders\nFROM trading_platform.users u\nJOIN trading_platform.kyc_audit k ON u.user_id = k.user_id AND k.status = 'approved'\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Also add the sum of quantities from their 'sell' orders."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders, SUM(CASE WHEN o.order_type = 'sell' THEN o.quantity ELSE 0 END) AS total_sell_quantity\nFROM trading_platform.users u\nJOIN trading_platform.kyc_audit k ON u.user_id = k.user_id AND k.status = 'approved'\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username;"}, {"role": "user", "content": "Finally, sort by total_sell_quantity descending and limit to the top 5 users."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, COUNT(o.order_id) AS total_orders, SUM(CASE WHEN o.order_type = 'sell' THEN o.quantity ELSE 0 END) AS total_sell_quantity\nFROM trading_platform.users u\nJOIN trading_platform.kyc_audit k ON u.user_id = k.user_id AND k.status = 'approved'\nLEFT JOIN trading_platform.orders o ON u.user_id = o.user_id\nGROUP BY u.user_id, u.username\nORDER BY total_sell_quantity DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "List pairs of wallets created on the same day but belonging to different users. Show the wallet IDs, user IDs, and creation dates for both wallets in each pair."}, {"role": "assistant", "content": "SELECT w1.wallet_id AS wallet1_id, w1.user_id AS user1_id, w1.created_at AS wallet1_created_at, w2.wallet_id AS wallet2_id, w2.user_id AS user2_id, w2.created_at AS wallet2_created_at FROM wallets w1 JOIN wallets w2 ON DATE(w1.created_at) = DATE(w2.created_at) AND w1.user_id != w2.user_id AND w1.wallet_id < w2.wallet_id;"}, {"role": "user", "content": "Filter the previous results to only include pairs where both wallet addresses start with '0x'."}, {"role": "assistant", "content": "SELECT w1.wallet_id AS wallet1_id, w1.user_id AS user1_id, w1.created_at AS wallet1_created_at, w2.wallet_id AS wallet2_id, w2.user_id AS user2_id, w2.created_at AS wallet2_created_at FROM wallets w1 JOIN wallets w2 ON DATE(w1.created_at) = DATE(w2.created_at) AND w1.user_id != w2.user_id AND w1.wallet_id < w2.wallet_id WHERE w1.address LIKE '0x%' AND w2.address LIKE '0x%';"}]} +{"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 PRIMARY KEY, previous_block_id text, timestamp timestamp, nonce int, merkle_root text, difficulty int )\nCREATE TABLE blockchain.transactions ( transaction_id text PRIMARY KEY, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text )\nCREATE TABLE blockchain.addresses ( address_id text PRIMARY KEY, public_key text, balance numeric )\nCREATE TABLE blockchain.nodes ( node_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE blockchain.users ( user_id text PRIMARY KEY, username text, email text, password_hash text )\nCREATE TABLE blockchain.smart_contracts ( contract_id text PRIMARY KEY, creator_address text, code text, timestamp timestamp )\n", "conversations": [{"role": "user", "content": "List all smart contracts created by addresses that have a balance greater than 1000."}, {"role": "assistant", "content": "SELECT sc.* FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id WHERE a.balance > 1000;"}, {"role": "user", "content": "Now include the username of the user who created these contracts if the creator address is associated with a user."}, {"role": "assistant", "content": "SELECT sc.*, u.username FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id LEFT JOIN blockchain.users u ON a.address_id = u.user_id WHERE a.balance > 1000;"}, {"role": "user", "content": "This query isn't working correctly because the join between addresses and users is wrong. The user_id in users table is not the same as address_id."}, {"role": "assistant", "content": "SELECT sc.*, u.username FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id LEFT JOIN blockchain.users u ON a.public_key = u.email WHERE a.balance > 1000;"}, {"role": "user", "content": "That still doesn't seem right. Let's just show the contracts and their creators' balances without trying to join with users."}, {"role": "assistant", "content": "SELECT sc.contract_id, sc.creator_address, a.balance FROM blockchain.smart_contracts sc JOIN blockchain.addresses a ON sc.creator_address = a.address_id WHERE a.balance > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.smart_contracts ( contract_id text PRIMARY KEY, creator_address text, code text, timestamp timestamp )\n", "conversations": [{"role": "user", "content": "Show me the earliest created smart contract for each creator address."}, {"role": "assistant", "content": "SELECT DISTINCT ON (creator_address) contract_id, creator_address, code, timestamp FROM blockchain.smart_contracts ORDER BY creator_address, timestamp ASC;"}, {"role": "user", "content": "Now include the total number of contracts each creator has made alongside this information."}, {"role": "assistant", "content": "WITH earliest_contracts AS (SELECT DISTINCT ON (creator_address) contract_id, creator_address, code, timestamp FROM blockchain.smart_contracts ORDER BY creator_address, timestamp ASC) SELECT ec.*, (SELECT COUNT(*) FROM blockchain.smart_contracts sc WHERE sc.creator_address = ec.creator_address) AS total_contracts FROM earliest_contracts ec;"}, {"role": "user", "content": "Filter this to only show creators who have made at least 10 contracts."}, {"role": "assistant", "content": "WITH earliest_contracts AS (SELECT DISTINCT ON (creator_address) contract_id, creator_address, code, timestamp FROM blockchain.smart_contracts ORDER BY creator_address, timestamp ASC) SELECT ec.*, (SELECT COUNT(*) FROM blockchain.smart_contracts sc WHERE sc.creator_address = ec.creator_address) AS total_contracts FROM earliest_contracts ec WHERE (SELECT COUNT(*) FROM blockchain.smart_contracts sc WHERE sc.creator_address = ec.creator_address) >= 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\nCREATE TABLE blockchain.blocks (\n block_id character varying(64) NOT NULL, -- unique identifier for the block\n previous_block_id character varying(64), -- identifier of the previous block\n timestamp timestamp NOT NULL, -- time when the block was mined\n nonce integer NOT NULL, -- nonce value used in the proof of work\n merkle_root character varying(128) NOT NULL, -- root of the Merkle tree for transactions\n difficulty integer NOT NULL, -- difficulty level of the block\n PRIMARY KEY (block_id)\n)\n", "conversations": [{"role": "user", "content": "Retrieve the block ID, timestamp, current block's difficulty, and the difficulty of the *previous* block for all blocks where the current block's difficulty is strictly greater than the previous block's difficulty."}, {"role": "assistant", "content": "SELECT b1.block_id, b1.timestamp, b1.difficulty AS current_difficulty, b2.difficulty AS previous_difficulty FROM blockchain.blocks b1 JOIN blockchain.blocks b2 ON b1.previous_block_id = b2.block_id WHERE b1.difficulty > b2.difficulty;"}]} +{"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.nodes ( node_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (node_id) )\n", "conversations": [{"role": "user", "content": "Retrieve all pairs of nodes where one node was last seen before '2023-06-01' and the other after '2023-06-01', and they share the same IP address."}, {"role": "assistant", "content": "SELECT a.node_id AS node_before,\n b.node_id AS node_after,\n a.ip_address\nFROM blockchain.nodes a\nJOIN blockchain.nodes b\n ON a.ip_address = b.ip_address\nWHERE a.last_seen < '2023-06-01'\n AND b.last_seen > '2023-06-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id.text, citizen_id.text, employee_id.text, location_id.text, service_id.text, scheduled_start_time.timestamp, scheduled_end_time.timestamp, purpose.text, status.text, booking_method.text, created_at.timestamp, notes.text )\n", "conversations": [{"role": "user", "content": "List the names of services that have been scheduled at accessible service locations."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name FROM government_services.services AS T1 JOIN government_services.appointments AS T2 ON T1.service_id = T2.service_id JOIN government_services.service_locations AS T3 ON T2.location_id = T3.location_id WHERE T3.is_accessible = TRUE"}, {"role": "user", "content": "Now, only include services from agencies with 'State' jurisdiction level."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name FROM government_services.services AS T1 JOIN government_services.appointments AS T2 ON T1.service_id = T2.service_id JOIN government_services.service_locations AS T3 ON T2.location_id = T3.location_id JOIN government_services.agencies AS T4 ON T1.agency_id = T4.agency_id WHERE T3.is_accessible = TRUE AND T4.jurisdiction_level = 'State'"}]} +{"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 government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\n", "conversations": [{"role": "user", "content": "How many documents are in each verification_status?"}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nGROUP BY verification_status;"}, {"role": "user", "content": "Only include statuses with more than 100 documents."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nGROUP BY verification_status\nHAVING COUNT(*) > 100;"}, {"role": "user", "content": "Order the results by document_count in descending order."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nGROUP BY verification_status\nHAVING COUNT(*) > 100\nORDER BY document_count DESC;"}, {"role": "user", "content": "Also exclude documents where expiry_date is before today."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) AS document_count\nFROM government_services.documents\nWHERE expiry_date >= CURRENT_DATE\nGROUP BY verification_status\nHAVING COUNT(*) > 100\nORDER BY document_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.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.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 PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "List application reference numbers and the total amount paid for each application that has at least one completed payment."}, {"role": "assistant", "content": "SELECT a.reference_number, SUM(p.amount) AS total_paid FROM government_services.applications AS a JOIN government_services.payments AS p ON a.application_id = p.application_id WHERE p.status = 'Completed' GROUP BY a.reference_number;"}, {"role": "user", "content": "Also include the citizen's first and last name who submitted the application."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, a.reference_number, SUM(p.amount) AS total_paid FROM government_services.applications AS a JOIN government_services.payments AS p ON a.application_id = p.application_id JOIN government_services.citizens AS c ON a.citizen_id = c.citizen_id WHERE p.status = 'Completed' GROUP BY c.first_name, c.last_name, a.reference_number;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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 )\n", "conversations": [{"role": "user", "content": "How many documents were uploaded in the month of October 2023?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM government_services.documents WHERE upload_timestamp >= '2023-10-01 00:00:00' AND upload_timestamp < '2023-11-01 00:00:00';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )\n", "conversations": [{"role": "user", "content": "Can you list the names of agencies that do not have a parent agency assigned, ordered by their established date?"}, {"role": "assistant", "content": "SELECT agency_id, agency_name, established_date\nFROM government_services.agencies\nWHERE parent_agency_id IS NULL\nORDER BY established_date;"}]} +{"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 government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.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.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.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "For each employee, find their first and last name along with the number of applications they've been assigned. Only include employees with at least 5 assigned applications."}, {"role": "assistant", "content": "SELECT e.first_name,\n e.last_name,\n COUNT(a.application_id) AS assigned_count\nFROM government_services.employees e\nJOIN government_services.applications a ON e.employee_id = a.assigned_employee_id\nGROUP BY e.first_name, e.last_name\nHAVING COUNT(a.application_id) >= 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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 )\n", "conversations": [{"role": "user", "content": "How many documents have a file reference assigned?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM government_services.documents WHERE file_reference IS NOT NULL AND file_reference <> '';"}]} +{"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 government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "List the appointment ID, the scheduled start time, and the name of the service location for all appointments scheduled between '2024-01-01' and '2024-12-31'."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.scheduled_start_time, T2.location_name FROM government_services.appointments AS T1 INNER JOIN government_services.service_locations AS T2 ON T1.location_id = T2.location_id WHERE T1.scheduled_start_time >= '2024-01-01' AND T1.scheduled_start_time < '2025-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "How many payments have been made using each payment_method, and what is the total amount for each method?"}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nGROUP BY payment_method;"}, {"role": "user", "content": "Can you filter to only include methods where the total_amount exceeds 1000?"}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nGROUP BY payment_method\nHAVING SUM(amount) > 1000;"}, {"role": "user", "content": "Also exclude any payments with status other than 'Completed'."}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nWHERE status = 'Completed'\nGROUP BY payment_method\nHAVING SUM(amount) > 1000;"}, {"role": "user", "content": "Order the results by total_amount descending and limit to the top 5 payment methods."}, {"role": "assistant", "content": "SELECT payment_method, COUNT(*) AS payment_count, SUM(amount) AS total_amount\nFROM government_services.payments\nWHERE status = 'Completed'\nGROUP BY payment_method\nHAVING SUM(amount) > 1000\nORDER BY total_amount DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text PRIMARY KEY, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "Find the total payment amount and payment count made by citizen with national ID number 'A123456789'."}, {"role": "assistant", "content": "SELECT SUM(p.amount) AS total_amount, COUNT(p.payment_id) AS payment_count\nFROM government_services.citizens c\nJOIN government_services.payments p ON c.citizen_id = p.citizen_id\nWHERE c.national_id_number = 'A123456789';"}]} +{"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 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.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 )\n", "conversations": [{"role": "user", "content": "List all agents who have sold at least one policy for an insurance product of type 'Health'. For each agent, show their full name, agency name, and the product name."}, {"role": "assistant", "content": "SELECT DISTINCT a.first_name || ' ' || a.last_name AS agent_full_name, a.agency_name, ip.product_name\nFROM insurance.agents a\nJOIN insurance.policies p ON a.agent_id = p.agent_id\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE ip.product_type = 'Health';"}]} +{"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 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 )\n", "conversations": [{"role": "user", "content": "List the product_id, product_name, and base_premium for all products that are currently inactive."}, {"role": "assistant", "content": "SELECT product_id, product_name, base_premium\nFROM insurance.insurance_products\nWHERE is_active = false;"}]} +{"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 insurance.claims ( claim_id text, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "I want a list of all claims where at least one document is larger than 2 megabytes. Include the claim ID, incident date, and the file name of such documents."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152;"}, {"role": "user", "content": "Actually, please also show the document type and only include documents uploaded after June 1, 2024."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01';"}, {"role": "user", "content": "Add the file size in kilobytes and order the results by file size descending."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type, (d.file_size_bytes/1024) AS file_size_kb\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01'\nORDER BY d.file_size_bytes DESC;"}, {"role": "user", "content": "Sorry, I'm getting some records where file_size_bytes is NULL. Please exclude those from the results."}, {"role": "assistant", "content": "SELECT c.claim_id, c.incident_date, d.file_name, d.document_type, (d.file_size_bytes/1024) AS file_size_kb\nFROM insurance.claims c\nJOIN insurance.claim_documents d ON c.claim_id = d.claim_id\nWHERE d.file_size_bytes > 2097152\n AND d.uploaded_at > '2024-06-01'\n AND d.file_size_bytes IS NOT NULL\nORDER BY d.file_size_bytes DESC;"}]} +{"system": "You are an 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 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.premium_payments ( payment_id.text, policy_id.text, customer_id.text, payment_date.timestamp, amount_paid.numeric, payment_method.text, transaction_reference.text, due_date.date, payment_period_start.date, payment_period_end.date, status.text )\n", "conversations": [{"role": "user", "content": "Show me all active policies with coverage limits above $1,000,000, along with the customer names and agent names, sorted by coverage limit in descending order."}, {"role": "assistant", "content": "SELECT p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, p.premium_amount, p.start_date, p.end_date FROM insurance.policies p WHERE p.status = 'active' AND p.coverage_limit > 1000000 ORDER BY p.coverage_limit DESC;"}, {"role": "user", "content": "Actually, I need to see the customer's first and last name from the customers table and the agent's full name from the agents table as well."}, {"role": "assistant", "content": "SELECT p.policy_id, p.coverage_limit, p.premium_amount, c.first_name AS customer_first_name, c.last_name AS customer_last_name, a.first_name AS agent_first_name, a.last_name AS agent_last_name FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.agents a ON p.agent_id = a.agent_id WHERE p.status = 'active' AND p.coverage_limit > 1000000 ORDER BY p.coverage_limit DESC;"}, {"role": "user", "content": "Now I also want to see the total number of claims each of these high-coverage policies has had."}, {"role": "assistant", "content": "SELECT p.policy_id, p.coverage_limit, p.premium_amount, c.first_name AS customer_first_name, c.last_name AS customer_last_name, a.first_name AS agent_first_name, a.last_name AS agent_last_name, COUNT(cl.claim_id) AS total_claims FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.agents a ON p.agent_id = a.agent_id LEFT JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'active' AND p.coverage_limit > 1000000 GROUP BY p.policy_id, p.coverage_limit, p.premium_amount, c.first_name, c.last_name, a.first_name, a.last_name ORDER BY p.coverage_limit DESC;"}, {"role": "user", "content": "Finally, filter these results to only show policies that have at least one claim and include the average settlement amount for those claims."}, {"role": "assistant", "content": "SELECT p.policy_id, p.coverage_limit, p.premium_amount, c.first_name AS customer_first_name, c.last_name AS customer_last_name, a.first_name AS agent_first_name, a.last_name AS agent_last_name, COUNT(cl.claim_id) AS total_claims, AVG(cl.settlement_amount) AS avg_settlement FROM insurance.policies p JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.agents a ON p.agent_id = a.agent_id JOIN insurance.claims cl ON p.policy_id = cl.policy_id WHERE p.status = 'active' AND p.coverage_limit > 1000000 GROUP BY p.policy_id, p.coverage_limit, p.premium_amount, c.first_name, c.last_name, a.first_name, a.last_name HAVING COUNT(cl.claim_id) > 0 ORDER BY p.coverage_limit DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n", "conversations": [{"role": "user", "content": "Show the top 5 largest documents by file size, including document_id, claim_id, file_name, and file_size_bytes."}, {"role": "assistant", "content": "SELECT document_id,\n claim_id,\n file_name,\n file_size_bytes\nFROM insurance.claim_documents\nORDER BY file_size_bytes DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\n", "conversations": [{"role": "user", "content": "Show the policy number, start date, and the first and last name of the agent for all policies that started in 2024."}, {"role": "assistant", "content": "SELECT p.policy_number, p.start_date, a.first_name AS agent_first_name, a.last_name AS agent_last_name\nFROM insurance.policies p\nJOIN insurance.agents a ON p.agent_id = a.agent_id\nWHERE p.start_date >= '2024-01-01' AND p.start_date < '2025-01-01';"}, {"role": "user", "content": "Also include the status of each policy and only show those where the policy's premium_amount is over 3000."}, {"role": "assistant", "content": "SELECT p.policy_number, p.start_date, a.first_name AS agent_first_name, a.last_name AS agent_last_name, p.status, p.premium_amount\nFROM insurance.policies p\nJOIN insurance.agents a ON p.agent_id = a.agent_id\nWHERE p.start_date >= '2024-01-01' AND p.start_date < '2025-01-01' AND p.premium_amount > 3000;"}]} +{"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 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 PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.premium_payments ( payment_id text, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the customer ID, payment ID, payment amount, and payment date for all premium payments with an amount paid over 2000."}, {"role": "assistant", "content": "SELECT customer_id, payment_id, amount_paid, payment_date\nFROM insurance.premium_payments\nWHERE amount_paid > 2000;"}]} +{"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 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": "Retrieve the number of open claims each customer has filed. Return customer_id, first_name, last_name, and open_claim_count."}, {"role": "assistant", "content": "SELECT cu.customer_id, cu.first_name, cu.last_name, COUNT(cl.claim_id) AS open_claim_count\nFROM insurance.customers cu\nLEFT JOIN insurance.claims cl ON cu.customer_id = cl.customer_id AND cl.status = 'Open'\nGROUP BY cu.customer_id, cu.first_name, cu.last_name;"}, {"role": "user", "content": "Now include only customers who have at least 3 open claims and order the results by open_claim_count descending."}, {"role": "assistant", "content": "SELECT cu.customer_id, cu.first_name, cu.last_name, COUNT(cl.claim_id) AS open_claim_count\nFROM insurance.customers cu\nJOIN insurance.claims cl ON cu.customer_id = cl.customer_id\nWHERE cl.status = 'Open'\nGROUP BY cu.customer_id, cu.first_name, cu.last_name\nHAVING COUNT(cl.claim_id) >= 3\nORDER BY open_claim_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\nCREATE TABLE insurance.premium_payments ( payment_id text, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\n", "conversations": [{"role": "user", "content": "Show me all policies that have at least two premium payments associated with them, along with the total amount paid for each policy."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, COUNT(pp.payment_id) AS payment_count, SUM(pp.amount_paid) AS total_amount_paid\nFROM insurance.policies p\nJOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id\nGROUP BY p.policy_id, p.policy_number\nHAVING COUNT(pp.payment_id) >= 2;"}, {"role": "user", "content": "Actually, also include the start_date and status of each policy in the result."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, p.start_date, p.status, COUNT(pp.payment_id) AS payment_count, SUM(pp.amount_paid) AS total_amount_paid\nFROM insurance.policies p\nJOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id\nGROUP BY p.policy_id, p.policy_number, p.start_date, p.status\nHAVING COUNT(pp.payment_id) >= 2;"}, {"role": "user", "content": "Now restrict the result to only policies with status 'active'."}, {"role": "assistant", "content": "SELECT p.policy_id, p.policy_number, p.start_date, p.status, COUNT(pp.payment_id) AS payment_count, SUM(pp.amount_paid) AS total_amount_paid\nFROM insurance.policies p\nJOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id\nWHERE p.status = 'active'\nGROUP BY p.policy_id, p.policy_number, p.start_date, p.status\nHAVING COUNT(pp.payment_id) >= 2;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\n", "conversations": [{"role": "user", "content": "List all agents and their managers' full names."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a LEFT JOIN insurance.agents m ON a.manager_id = m.agent_id;"}, {"role": "user", "content": "Filter the results to only include agents with a commission rate greater than 0.05."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a LEFT JOIN insurance.agents m ON a.manager_id = m.agent_id WHERE a.commission_rate > 0.05;"}, {"role": "user", "content": "From those results, also only show agents whose manager is licensed in 'CA'."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a JOIN insurance.agents m ON a.manager_id = m.agent_id WHERE a.commission_rate > 0.05 AND m.license_state = 'CA';"}, {"role": "user", "content": "Please refine the output to only include the agent's first name, last name, and the manager's full name, sorted by manager's last name descending, and limit to the top 5."}, {"role": "assistant", "content": "SELECT a.first_name, a.last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name FROM insurance.agents a JOIN insurance.agents m ON a.manager_id = m.agent_id WHERE a.commission_rate > 0.05 AND m.license_state = 'CA' ORDER BY m.last_name DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Show me all insurance products of type 'Travel', including their product_id, product_name, and base_premium."}, {"role": "assistant", "content": "SELECT product_id, product_name, base_premium\nFROM insurance.insurance_products\nWHERE product_type = 'Travel';"}]} +{"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 healthcare.prescriptions ( prescription_id text PRIMARY KEY, 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 int, prescription_date timestamp )\n", "conversations": [{"role": "user", "content": "Find pairs of prescriptions issued to the same patient but for different medications, issued on the same date. Show the patient ID, the prescription IDs of the two prescriptions, and their medication IDs and prescription dates."}, {"role": "assistant", "content": "SELECT p1.patient_id, p1.prescription_id AS prescription1_id, p1.medication_id AS medication1_id, p2.prescription_id AS prescription2_id, p2.medication_id AS medication2_id, p1.prescription_date FROM healthcare.prescriptions p1 JOIN healthcare.prescriptions p2 ON p1.patient_id = p2.patient_id AND p1.prescription_date = p2.prescription_date AND p1.medication_id <> p2.medication_id AND p1.prescription_id < p2.prescription_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List the first and last names of passengers who share the same loyalty_program_id with at least one other passenger."}, {"role": "assistant", "content": "SELECT DISTINCT p1.first_name, p1.last_name\nFROM transportation.passengers p1\nJOIN transportation.passengers p2 ON p1.loyalty_program_id = p2.loyalty_program_id AND p1.passenger_id <> p2.passenger_id\nWHERE p1.loyalty_program_id IS NOT NULL;"}, {"role": "user", "content": "Now refine this list to only include passengers who joined after January 1, 2023."}, {"role": "assistant", "content": "SELECT DISTINCT p1.first_name, p1.last_name\nFROM transportation.passengers p1\nJOIN transportation.passengers p2 ON p1.loyalty_program_id = p2.loyalty_program_id AND p1.passenger_id <> p2.passenger_id\nWHERE p1.loyalty_program_id IS NOT NULL\n AND p1.created_at >= '2023-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.policies ( policy_id.text, customer_id.text, product_id.text, agent_id.text, policy_number.text, start_date.date, end_date.date, premium_amount.numeric, coverage_limit.numeric, deductible.numeric, status.text, issued_at.timestamp, cancellation_date.date, cancellation_reason.text )\n", "conversations": [{"role": "user", "content": "For each policy, find its immediate predecessor policy for the same customer. Return customer_id, predecessor policy_number, current policy_number, predecessor end_date, and current start_date."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1;"}, {"role": "user", "content": "Only include those where the gap between predecessor end_date and current start_date is less than 7 days."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1\n AND (current_start - prev_end) < INTERVAL '7 days';"}, {"role": "user", "content": "Also filter to include only customers whose customer_id starts with 'CUST'."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1\n AND (current_start - prev_end) < INTERVAL '7 days'\n AND customer_id LIKE 'CUST%';"}, {"role": "user", "content": "Finally, order the results by customer_id and current_start_date descending, limit to 10 rows."}, {"role": "assistant", "content": "WITH ranked AS (\n SELECT p2.customer_id,\n p2.policy_number AS current_policy,\n p2.start_date AS current_start,\n p1.policy_number AS prev_policy,\n p1.end_date AS prev_end,\n ROW_NUMBER() OVER (\n PARTITION BY p2.customer_id, p2.policy_number\n ORDER BY p1.end_date DESC\n ) AS rn\n FROM insurance.policies p2\n JOIN insurance.policies p1\n ON p1.customer_id = p2.customer_id\n AND p1.end_date < p2.start_date\n)\nSELECT customer_id,\n prev_policy AS predecessor_policy,\n current_policy,\n prev_end AS predecessor_end_date,\n current_start AS current_start_date\nFROM ranked\nWHERE rn = 1\n AND (current_start - prev_end) < INTERVAL '7 days'\n AND customer_id LIKE 'CUST%'\nORDER BY customer_id, current_start DESC\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 \"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": "For the latest snapshot time, list the total `usd_value` held by CEXes for each distinct `token_symbol` across all chains. Order the results by total value descending."}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT max(snapshot_time) as max_time\n FROM cex_token_balance\n)\nSELECT token_symbol, sum(usd_value) as total_usd_value\nFROM cex_token_balance ctb\nJOIN latest_snapshot ls ON ctb.snapshot_time = ls.max_time\nGROUP BY token_symbol\nORDER BY total_usd_value DESC;"}, {"role": "user", "content": "Now, filter this list to only include tokens where the total `usd_value` across all CEX holdings is greater than $5,000,000."}, {"role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT max(snapshot_time) as max_time\n FROM cex_token_balance\n)\nSELECT token_symbol, sum(usd_value) as total_usd_value\nFROM cex_token_balance ctb\nJOIN latest_snapshot ls ON ctb.snapshot_time = ls.max_time\nGROUP BY token_symbol\nHAVING sum(usd_value) > 5000000.0\nORDER BY total_usd_value DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n", "conversations": [{"role": "user", "content": "For each narrative in token_basic_info, compute the total liquidity and count of tokens from token_dexpool_info. Show narrative, total_liquidity, and token_count."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nGROUP BY tbi.narrative;"}, {"role": "user", "content": "Include only tokens where volume_24h > 500000 and price_change_percentage_6h > 0."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nWHERE td.volume_24h > 500000\n AND td.price_change_percentage_6h > 0\nGROUP BY tbi.narrative;"}, {"role": "user", "content": "Now join narrative_info to also get trend_rank and narrative volume_24h."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n ni.trend_rank,\n ni.volume_24h AS narrative_volume,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nJOIN narrative_info ni\n ON tbi.narrative = ni.narrative\nWHERE td.volume_24h > 500000\n AND td.price_change_percentage_6h > 0\nGROUP BY tbi.narrative, ni.trend_rank, ni.volume_24h;"}, {"role": "user", "content": "Finally, only keep narratives where trend_rank <= 10 and order by total_liquidity descending."}, {"role": "assistant", "content": "SELECT tbi.narrative,\n ni.trend_rank,\n ni.volume_24h AS narrative_volume,\n SUM(td.liquidity) AS total_liquidity,\n COUNT(DISTINCT td.token_symbol) AS token_count\nFROM token_basic_info tbi\nJOIN token_dexpool_info td\n ON tbi.token_address = td.token_address\nJOIN narrative_info ni\n ON tbi.narrative = ni.narrative\nWHERE td.volume_24h > 500000\n AND td.price_change_percentage_6h > 0\n AND ni.trend_rank <= 10\nGROUP BY tbi.narrative, ni.trend_rank, ni.volume_24h\nORDER BY total_liquidity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n", "conversations": [{"role": "user", "content": "What is the average USD value per address for each narrative across all chains?"}, {"role": "assistant", "content": "SELECT\n narrative,\n AVG(usd_value / NULLIF(address_amount, 0)) AS avg_usd_per_address\nFROM smart_money_token_inflow\nGROUP BY narrative;"}]} +{"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 narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\n", "conversations": [{"role": "user", "content": "Show the top 5 narratives ranked by trend_rank (lowest is better). Include the narrative, trend rank, and number of tokens."}, {"role": "assistant", "content": "SELECT narrative, trend_rank, token_num FROM narrative_info ORDER BY trend_rank ASC LIMIT 5;"}, {"role": "user", "content": "Can you also add their 24h and 7d price change percentages in the output?"}, {"role": "assistant", "content": "SELECT narrative, trend_rank, token_num, price_change_percentage_24h, price_change_percentage_7d FROM narrative_info ORDER BY trend_rank ASC LIMIT 5;"}, {"role": "user", "content": "Now, I want to see only those narratives where the total 24h trading volume is above $10 million."}, {"role": "assistant", "content": "SELECT narrative, trend_rank, token_num, price_change_percentage_24h, price_change_percentage_7d, volume_24h FROM narrative_info WHERE volume_24h > 10000000 ORDER BY trend_rank ASC LIMIT 5;"}, {"role": "user", "content": "Can you show trend_rank as the last column?"}, {"role": "assistant", "content": "SELECT narrative, token_num, price_change_percentage_24h, price_change_percentage_7d, volume_24h, trend_rank FROM narrative_info WHERE volume_24h > 10000000 ORDER BY trend_rank ASC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\n", "conversations": [{"role": "user", "content": "For each token, show its token_id, decimals, and the average total_supply of all tokens with the same decimals."}, {"role": "assistant", "content": "SELECT t.token_id,\n t.decimals,\n avg_data.avg_total_supply\nFROM web3.tokens t\nJOIN (\n SELECT decimals,\n AVG(total_supply) AS avg_total_supply\n FROM web3.tokens\n GROUP BY decimals\n) AS avg_data\n ON t.decimals = avg_data.decimals;"}]} +{"system": "You are an 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 hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\n", "conversations": [{"role": "user", "content": "Show me all rooms with their type names and base rates for property 'P001'."}, {"role": "assistant", "content": "SELECT r.room_id, r.room_number, rt.type_name, rt.base_rate\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id AND r.property_id = rt.property_id\nWHERE r.property_id = 'P001';"}, {"role": "user", "content": "Actually, only include rooms on floor 2 and above, and sort by base_rate descending."}, {"role": "assistant", "content": "SELECT r.room_id, r.room_number, rt.type_name, rt.base_rate, r.floor\nFROM hospitality_technology.rooms r\nJOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id AND r.property_id = rt.property_id\nWHERE r.property_id = 'P001' AND r.floor >= 2\nORDER BY rt.base_rate DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\n", "conversations": [{"role": "user", "content": "Show all rooms that are on floor 3."}, {"role": "assistant", "content": "SELECT room_id, property_id, room_number FROM hospitality_technology.rooms WHERE floor = 3;"}, {"role": "user", "content": "For these rooms, include the property name and room number."}, {"role": "assistant", "content": "SELECT r.room_number, p.property_name FROM hospitality_technology.rooms AS r JOIN hospitality_technology.properties AS p ON r.property_id = p.property_id WHERE r.floor = 3;"}, {"role": "user", "content": "Also, include the type name and current status for each room."}, {"role": "assistant", "content": "SELECT r.room_number, p.property_name, rt.type_name, r.status FROM hospitality_technology.rooms AS r JOIN hospitality_technology.properties AS p ON r.property_id = p.property_id JOIN hospitality_technology.room_types AS rt ON r.room_type_id = rt.room_type_id AND r.property_id = rt.property_id WHERE r.floor = 3;"}]} +{"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 hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\n", "conversations": [{"role": "user", "content": "List all available services in the 'Housekeeping' department that cost less than 20."}, {"role": "assistant", "content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20;"}, {"role": "user", "content": "Sort the results by service_name in ascending order."}, {"role": "assistant", "content": "SELECT service_id, service_name, price\nFROM hospitality_technology.services\nWHERE department = 'Housekeeping' AND is_available = true AND price < 20\nORDER BY service_name ASC;"}]} +{"system": "You are an 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 hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\nCREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "List all service orders for spa services in the last month, including the guest ID and total price."}, {"role": "assistant", "content": "SELECT order_id, guest_id, total_price FROM hospitality_technology.service_orders WHERE service_id LIKE 'SPA%' AND order_timestamp >= NOW() - INTERVAL '1 month';"}, {"role": "user", "content": "Now, include only orders with a total price over $100 and order them by total price in descending order."}, {"role": "assistant", "content": "SELECT order_id, guest_id, total_price FROM hospitality_technology.service_orders WHERE service_id LIKE 'SPA%' AND order_timestamp >= NOW() - INTERVAL '1 month' AND total_price > 100 ORDER BY total_price DESC;"}, {"role": "user", "content": "The query is missing the property ID. Can you include that as well?"}, {"role": "assistant", "content": "SELECT so.order_id, so.guest_id, so.total_price, r.property_id FROM hospitality_technology.service_orders so JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id WHERE so.service_id LIKE 'SPA%' AND so.order_timestamp >= NOW() - INTERVAL '1 month' AND so.total_price > 100 ORDER BY so.total_price DESC;"}, {"role": "user", "content": "Actually, I need to see the service description too, and order by guest ID."}, {"role": "assistant", "content": "SELECT so.order_id, so.guest_id, so.total_price, r.property_id, so.notes AS service_description FROM hospitality_technology.service_orders so JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id WHERE so.service_id LIKE 'SPA%' AND so.order_timestamp >= NOW() - INTERVAL '1 month' AND so.total_price > 100 ORDER BY so.guest_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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 food and beverage services (category = 'Food & Beverage') with their names, prices, and units, where the price is less than $20."}, {"role": "assistant", "content": "SELECT service_name, price, unit FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20;"}, {"role": "user", "content": "Now, filter these results to only include services that are priced per item (unit = 'Per Item')."}, {"role": "assistant", "content": "SELECT service_name, price, unit FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20 AND unit = 'Per Item';"}, {"role": "user", "content": "The query is missing the department information. Can you include that as well?"}, {"role": "assistant", "content": "SELECT service_name, price, unit, department FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20 AND unit = 'Per Item';"}, {"role": "user", "content": "Actually, I only need services from the 'F&B' department, and order them by price in ascending order."}, {"role": "assistant", "content": "SELECT service_name, price, unit, department FROM hospitality_technology.services WHERE category = 'Food & Beverage' AND price < 20 AND unit = 'Per Item' AND department = 'F&B' ORDER BY price ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "List each payment's currency_code, total amount paid, and the number of service orders placed by the same guest for the same reservation."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.currency_code,\n p.amount AS payment_amount,\n COUNT(so.order_id) AS order_count\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.service_orders so\n ON p.reservation_id = so.reservation_id\n AND p.guest_id = so.guest_id\nGROUP BY p.payment_id, p.currency_code, p.amount;"}, {"role": "user", "content": "Actually, I want the earliest service order date for each reservation and include it in the results."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.currency_code,\n p.amount AS payment_amount,\n COUNT(so.order_id) AS order_count,\n MIN(so.order_timestamp) AS first_order_timestamp\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.service_orders so\n ON p.reservation_id = so.reservation_id\n AND p.guest_id = so.guest_id\nGROUP BY p.payment_id, p.currency_code, p.amount;"}, {"role": "user", "content": "Also, only include payments with status = 'Succeeded' and service orders with status = 'Delivered'."}, {"role": "assistant", "content": "SELECT p.payment_id,\n p.currency_code,\n p.amount AS payment_amount,\n COUNT(so.order_id) AS order_count,\n MIN(so.order_timestamp) AS first_order_timestamp\nFROM hospitality_technology.payments p\nLEFT JOIN hospitality_technology.service_orders so\n ON p.reservation_id = so.reservation_id\n AND p.guest_id = so.guest_id\n AND so.status = 'Delivered'\nWHERE p.status = 'Succeeded'\nGROUP BY p.payment_id, p.currency_code, p.amount;"}]} +{"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 hospitality_technology.rooms ( room_id.text, property_id.text, room_number.text, room_type_id.text, floor.integer, status.text, is_smoking.boolean, features.text, current_condition.text, last_cleaned_at.timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id.text, property_id.text, type_name.text, description.text, base_rate.numeric, max_occupancy.integer, bed_type.text, area_sqft.numeric, amenities.text )\nCREATE TABLE hospitality_technology.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id.text, property_id.text, first_name.text, last_name.text, position.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, is_active.boolean, access_level.integer, manager_id.text, created_at.timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )\nCREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )\nCREATE TABLE hospitality_technology.reviews ( review_id.text, property_id.text, reservation_id.text, guest_id.text, rating_overall.integer, rating_cleanliness.integer, rating_service.integer, rating_location.integer, rating_value.integer, comment.text, review_source.text, review_date.timestamp, is_public.boolean, staff_response.text, response_staff_id.text, response_date.timestamp )\n", "conversations": [{"role": "user", "content": "List all rooms that have a 'Jacuzzi' feature, including the room_number, property_id, type_name, and base_rate."}, {"role": "assistant", "content": "SELECT r.room_number,\n r.property_id,\n rt.type_name,\n rt.base_rate\nFROM hospitality_technology.rooms AS r\nJOIN hospitality_technology.room_types AS rt\n ON r.room_type_id = rt.room_type_id\n AND r.property_id = rt.property_id\nWHERE r.features ILIKE '%Jacuzzi%';"}]} +{"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 hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.reservations ( reservation_id text, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults integer, num_children integer, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\n", "conversations": [{"role": "user", "content": "Show me all staff members along with their positions and the names of the properties they work at."}, {"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;"}, {"role": "user", "content": "Only include staff who are not currently active."}, {"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 = FALSE;"}]} +{"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 hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n", "conversations": [{"role": "user", "content": "Find guests who ordered the same service more than once on the same reservation and date. Return guest_id, reservation_id, service_id, and the date."}, {"role": "assistant", "content": "SELECT so1.guest_id,\n so1.reservation_id,\n so1.service_id,\n DATE(so1.order_timestamp) AS order_date\nFROM hospitality_technology.service_orders so1\nJOIN hospitality_technology.service_orders so2\n ON so1.guest_id = so2.guest_id\n AND so1.reservation_id = so2.reservation_id\n AND so1.service_id = so2.service_id\n AND DATE(so1.order_timestamp) = DATE(so2.order_timestamp)\n AND so1.order_id < so2.order_id\nGROUP BY so1.guest_id, so1.reservation_id, so1.service_id, DATE(so1.order_timestamp);"}, {"role": "user", "content": "Actually, consider only orders where status = 'Delivered'."}, {"role": "assistant", "content": "SELECT so1.guest_id,\n so1.reservation_id,\n so1.service_id,\n DATE(so1.order_timestamp) AS order_date\nFROM hospitality_technology.service_orders so1\nJOIN hospitality_technology.service_orders so2\n ON so1.guest_id = so2.guest_id\n AND so1.reservation_id = so2.reservation_id\n AND so1.service_id = so2.service_id\n AND DATE(so1.order_timestamp) = DATE(so2.order_timestamp)\n AND so1.order_id < so2.order_id\nWHERE so1.status = 'Delivered'\n AND so2.status = 'Delivered'\nGROUP BY so1.guest_id, so1.reservation_id, so1.service_id, DATE(so1.order_timestamp);"}, {"role": "user", "content": "Also, count how many times each service was reordered per date and sort by that count descending."}, {"role": "assistant", "content": "SELECT so1.guest_id,\n so1.reservation_id,\n so1.service_id,\n DATE(so1.order_timestamp) AS order_date,\n COUNT(*) AS reorder_count\nFROM hospitality_technology.service_orders so1\nJOIN hospitality_technology.service_orders so2\n ON so1.guest_id = so2.guest_id\n AND so1.reservation_id = so2.reservation_id\n AND so1.service_id = so2.service_id\n AND DATE(so1.order_timestamp) = DATE(so2.order_timestamp)\n AND so1.order_id < so2.order_id\nWHERE so1.status = 'Delivered'\n AND so2.status = 'Delivered'\nGROUP BY so1.guest_id, so1.reservation_id, so1.service_id, DATE(so1.order_timestamp)\nORDER BY reorder_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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 character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id.text, reservation_id.text, guest_id.text, bill_id.text, amount.numeric, currency_code.text, payment_method.text, card_type.text, card_last_four.text, transaction_ref.text, payment_timestamp.timestamp, status.text, staff_id_processed.text, notes.text )\nCREATE TABLE hospitality_technology.reviews ( review_id text PRIMARY KEY, property_id text, reservation_id text, guest_id text, rating_overall int, rating_cleanliness int, rating_service int, rating_location int, rating_value int, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n", "conversations": [{"role": "user", "content": "Show all public reviews that have a comment."}, {"role": "assistant", "content": "SELECT review_id, property_id, guest_id, rating_overall, comment FROM reviews WHERE is_public = TRUE AND comment IS NOT NULL AND comment != '';"}, {"role": "user", "content": "From those, only show reviews with an overall rating of 5."}, {"role": "assistant", "content": "SELECT review_id, property_id, guest_id, rating_overall, comment FROM reviews WHERE is_public = TRUE AND comment IS NOT NULL AND comment != '' AND rating_overall = 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text PRIMARY KEY, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text )\nCREATE TABLE government_services.services ( service_id text, 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 character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n", "conversations": [{"role": "user", "content": "List the appointment IDs and statuses for all appointments scheduled at locations in the city of 'San Francisco'."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.status\nFROM government_services.appointments a\nJOIN government_services.service_locations l ON a.location_id = l.location_id\nWHERE l.city = 'San Francisco';"}]} +{"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 government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text )\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "Show the application ID, payment amount, and payment method for all payments that have a status of 'Completed' and are related to services in the 'Licensing' category."}, {"role": "assistant", "content": "SELECT p.application_id, p.amount, p.payment_method\nFROM government_services.payments p\nJOIN government_services.services s ON p.service_id = s.service_id\nWHERE p.status = 'Completed' AND s.category = 'Licensing';"}]} +{"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 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.applications (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\nCREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\nCREATE TABLE government_services.appointments ( appointment_id text, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n", "conversations": [{"role": "user", "content": "How many total documents are recorded in the system?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM government_services.documents;"}, {"role": "user", "content": "Show me the count of documents for each verification_status."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) FROM government_services.documents GROUP BY verification_status;"}, {"role": "user", "content": "Exclude any documents where the verification_status is 'Pending' or 'Rejected'."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) FROM government_services.documents WHERE verification_status NOT IN ('Pending', 'Rejected') GROUP BY verification_status;"}, {"role": "user", "content": "And order the results by the count in descending order."}, {"role": "assistant", "content": "SELECT verification_status, COUNT(*) FROM government_services.documents WHERE verification_status NOT IN ('Pending', 'Rejected') GROUP BY verification_status ORDER BY COUNT(*) DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\n", "conversations": [{"role": "user", "content": "List all agencies that do not have a website URL specified. Return their agency_id, agency_name, and main_phone_number."}, {"role": "assistant", "content": "SELECT agency_id, agency_name, main_phone_number FROM government_services.agencies WHERE website_url IS NULL OR website_url = '';"}]} +{"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 government_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n application_id character varying(64), -- FK to applications table (optional)\n message_subject character varying(255),\n message_body text NOT NULL,\n channel character varying(30) NOT NULL, -- e.g., Email, SMS, Portal Message, Mail\n sent_at timestamp NOT NULL,\n status character varying(30) NOT NULL, -- e.g., Queued, Sent, Delivered, Failed, Read\n related_entity_type character varying(50), -- e.g., Application, Appointment, Document Request\n related_entity_id character varying(64), -- ID of the related entity\n PRIMARY KEY (notification_id)\n)\n", "conversations": [{"role": "user", "content": "List the full names and job titles of all employees who have not verified any documents."}, {"role": "assistant", "content": "SELECT e.first_name, e.last_name, e.job_title FROM government_services.employees AS e LEFT JOIN government_services.documents AS d ON e.employee_id = d.verified_by_employee_id WHERE d.document_id IS NULL;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\n", "conversations": [{"role": "user", "content": "Find all document types uploaded by citizens whose documents have an expiry date in 2024 and were uploaded at locations located in the state of 'Nevada'. List the document_id, document_type, and location_name."}, {"role": "assistant", "content": "SELECT d.document_id, d.document_type, sl.location_name\nFROM government_services.documents d\nJOIN government_services.service_locations sl\n ON d.application_id = sl.location_id\nWHERE d.expiry_date BETWEEN '2024-01-01' AND '2024-12-31'\n AND sl.state = 'Nevada';"}]} +{"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 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 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 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 government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )\n", "conversations": [{"role": "user", "content": "Find pairs of active services within the same category provided by the same agency, where one service has an average processing time more than double the other's. Display the agency ID, category, the first service name and its processing time, and the second service name and its processing time."}, {"role": "assistant", "content": "SELECT s1.agency_id, s1.category, s1.service_name AS service1_name, s1.average_processing_time_days AS service1_processing_time_days, s2.service_name AS service2_name, s2.average_processing_time_days AS service2_processing_time_days FROM government_services.services AS s1 JOIN government_services.services AS s2 ON s1.agency_id = s2.agency_id AND s1.category = s2.category AND s1.service_id < s2.service_id WHERE s1.is_active = TRUE AND s2.is_active = TRUE AND s1.average_processing_time_days IS NOT NULL AND s2.average_processing_time_days IS NOT NULL AND (s1.average_processing_time_days > 2 * s2.average_processing_time_days OR s2.average_processing_time_days > 2 * s1.average_processing_time_days);"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\n", "conversations": [{"role": "user", "content": "List the service name, category, and standard fee for all services offered by agencies that have at least one accessible service location in the state of 'California'."}, {"role": "assistant", "content": "SELECT DISTINCT T1.service_name, T1.category, T1.standard_fee FROM government_services.services AS T1 JOIN government_services.service_locations AS T2 ON T1.agency_id = T2.agency_id WHERE T2.is_accessible = TRUE AND T2.state = 'California';"}]} +{"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 government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.applications (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the government employee\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(150) NOT NULL,\n department character varying(100),\n work_email character varying(128) NOT NULL UNIQUE,\n work_phone character varying(32),\n hire_date date NOT NULL,\n termination_date date, -- null if currently employed\n access_level character varying(50), -- Role or permission level\n manager_employee_id character varying(64), -- FK to self for reporting structure\n PRIMARY KEY (employee_id)\n)\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Show me all upcoming appointments in July 2024, the citizen's full name, the name of the service, and the agency responsible for the service."}, {"role": "assistant", "content": "SELECT a.appointment_id, a.scheduled_start_time, c.first_name || ' ' || c.last_name AS citizen_full_name, s.service_name, ag.agency_name\nFROM government_services.appointments a\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nJOIN government_services.services s ON a.service_id = s.service_id\nJOIN government_services.agencies ag ON s.agency_id = ag.agency_id\nWHERE a.scheduled_start_time >= '2024-07-01' AND a.scheduled_start_time < '2024-08-01'\nORDER BY a.scheduled_start_time ASC;"}, {"role": "user", "content": "Could you also include the status of each appointment and only show those which are still 'Scheduled'?"}, {"role": "assistant", "content": "SELECT a.appointment_id, a.scheduled_start_time, c.first_name || ' ' || c.last_name AS citizen_full_name, s.service_name, ag.agency_name, a.status\nFROM government_services.appointments a\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nJOIN government_services.services s ON a.service_id = s.service_id\nJOIN government_services.agencies ag ON s.agency_id = ag.agency_id\nWHERE a.scheduled_start_time >= '2024-07-01' AND a.scheduled_start_time < '2024-08-01'\n AND a.status = 'Scheduled'\nORDER BY a.scheduled_start_time ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 )\n", "conversations": [{"role": "user", "content": "List agency_id, agency_name, and main_phone_number for agencies that do not have a main phone number specified."}, {"role": "assistant", "content": "SELECT agency_id, agency_name, main_phone_number\nFROM government_services.agencies\nWHERE main_phone_number IS NULL;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.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.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Give me a list of all passengers with an email address on file, showing their first name, last name, and the date their record was created."}, {"role": "assistant", "content": "SELECT first_name, last_name, created_at\nFROM transportation.passengers\nWHERE email IS NOT NULL;"}, {"role": "user", "content": "Narrow the results to only include passengers who joined in 2022."}, {"role": "assistant", "content": "SELECT first_name, last_name, created_at\nFROM transportation.passengers\nWHERE email IS NOT NULL AND EXTRACT(YEAR FROM created_at) = 2022;"}]} +{"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 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": "What are the average and maximum fare amounts for each booking status?"}, {"role": "assistant", "content": "SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare\nFROM transportation.bookings\nGROUP BY status;"}, {"role": "user", "content": "Only include statuses where the average fare is greater than 50."}, {"role": "assistant", "content": "SELECT status, AVG(fare) AS avg_fare, MAX(fare) AS max_fare\nFROM transportation.bookings\nGROUP BY status\nHAVING AVG(fare) > 50;"}]} +{"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 transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.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.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n", "conversations": [{"role": "user", "content": "Can you show the fuel_log_id, vehicle make, and quantity for all fuel logs where the quantity is greater than 100?"}, {"role": "assistant", "content": "SELECT f.fuel_log_id, v.make, f.quantity\nFROM transportation.fuel_logs f\nJOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id\nWHERE f.quantity > 100;"}, {"role": "user", "content": "Also display the fuel type and order the results by quantity in descending order."}, {"role": "assistant", "content": "SELECT f.fuel_log_id, v.make, f.quantity, f.fuel_type\nFROM transportation.fuel_logs f\nJOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id\nWHERE f.quantity > 100\nORDER BY f.quantity DESC;"}, {"role": "user", "content": "Only include records from fuel logs that happened in 2023."}, {"role": "assistant", "content": "SELECT f.fuel_log_id, v.make, f.quantity, f.fuel_type\nFROM transportation.fuel_logs f\nJOIN transportation.vehicles v ON f.vehicle_id = v.vehicle_id\nWHERE f.quantity > 100\n AND EXTRACT(YEAR FROM f.log_timestamp) = 2023\nORDER BY f.quantity DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.passengers ( passenger_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Show me the log timestamp, fuel type, quantity, and the name of the location for all fuel logs recorded at locations with type 'Warehouse'."}, {"role": "assistant", "content": "SELECT f.log_timestamp, f.fuel_type, f.quantity, l.name FROM transportation.fuel_logs f JOIN transportation.locations l ON f.location_id = l.location_id WHERE l.type = 'Warehouse';"}, {"role": "user", "content": "Filter these fuel logs to only include entries from the year 2024 and also include the total cost for each entry."}, {"role": "assistant", "content": "SELECT f.log_timestamp, f.fuel_type, f.quantity, f.total_cost, l.name FROM transportation.fuel_logs f JOIN transportation.locations l ON f.location_id = l.location_id WHERE l.type = 'Warehouse' AND EXTRACT(YEAR FROM f.log_timestamp) = 2024;"}, {"role": "user", "content": "For these 'Warehouse' fuel logs from 2024, calculate the average quantity and average cost_per_unit for each fuel type."}, {"role": "assistant", "content": "SELECT f.fuel_type, AVG(f.quantity) AS average_quantity, AVG(f.cost_per_unit) AS average_cost_per_unit FROM transportation.fuel_logs f JOIN transportation.locations l ON f.location_id = l.location_id WHERE l.type = 'Warehouse' AND EXTRACT(YEAR FROM f.log_timestamp) = 2024 GROUP BY f.fuel_type;"}]} +{"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 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": "For each vehicle, find the vehicle acquired immediately before it in the same depot. Show current vehicle_id, acquisition_date, previous_vehicle_id, and previous_acquisition_date."}, {"role": "assistant", "content": "SELECT v.vehicle_id,\n v.acquisition_date,\n prev.vehicle_id AS previous_vehicle_id,\n prev.acquisition_date AS previous_acquisition_date\nFROM transportation.vehicles v\nLEFT JOIN transportation.vehicles prev\n ON v.depot_id = prev.depot_id\n AND prev.acquisition_date = (\n SELECT MAX(acquisition_date)\n FROM transportation.vehicles\n WHERE depot_id = v.depot_id\n AND acquisition_date < v.acquisition_date\n );"}]} +{"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 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.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.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n", "conversations": [{"role": "user", "content": "Show the booking ID and seat number for all bookings that have a fare equal to 50."}, {"role": "assistant", "content": "SELECT booking_id, seat_number\nFROM transportation.bookings\nWHERE fare = 50;"}, {"role": "user", "content": "Also include the booking status and order the results by booking time ascending."}, {"role": "assistant", "content": "SELECT booking_id, seat_number, status\nFROM transportation.bookings\nWHERE fare = 50\nORDER BY booking_time ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n", "conversations": [{"role": "user", "content": "Retrieve the daily total fare collected for bookings with status 'Completed' in March 2024. Display the booking_date and total_fare."}, {"role": "assistant", "content": "SELECT\n DATE(booking_time) AS booking_date,\n SUM(fare) AS total_fare\nFROM transportation.bookings\nWHERE status = 'Completed'\n AND booking_time >= '2024-03-01'\n AND booking_time < '2024-04-01'\nGROUP BY DATE(booking_time);"}, {"role": "user", "content": "Now include only days where the total_fare exceeds 1000."}, {"role": "assistant", "content": "SELECT\n DATE(booking_time) AS booking_date,\n SUM(fare) AS total_fare\nFROM transportation.bookings\nWHERE status = 'Completed'\n AND booking_time >= '2024-03-01'\n AND booking_time < '2024-04-01'\nGROUP BY DATE(booking_time)\nHAVING SUM(fare) > 1000;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE 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 (\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 ( 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.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 )\n", "conversations": [{"role": "user", "content": "Show me all maintenance logs for vehicles of make 'Toyota' performed after January 1, 2024. Include the log ID, vehicle ID, service date, and service type."}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, ml.service_type\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nWHERE v.make = 'Toyota' AND ml.service_date > '2024-01-01';"}, {"role": "user", "content": "Can you add the maintenance cost and mechanic name to each entry and sort the results by service date descending?"}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, ml.service_type, ml.cost, ml.mechanic_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nWHERE v.make = 'Toyota' AND ml.service_date > '2024-01-01'\nORDER BY ml.service_date DESC;"}, {"role": "user", "content": "Actually, only show logs where the maintenance cost is greater than 1000."}, {"role": "assistant", "content": "SELECT ml.log_id, ml.vehicle_id, ml.service_date, ml.service_type, ml.cost, ml.mechanic_name\nFROM transportation.maintenance_logs ml\nJOIN transportation.vehicles v ON ml.vehicle_id = v.vehicle_id\nWHERE v.make = 'Toyota' AND ml.service_date > '2024-01-01' AND ml.cost > 1000\nORDER BY ml.service_date DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\n", "conversations": [{"role": "user", "content": "Could you provide the number of vehicles for each fuel_type?"}, {"role": "assistant", "content": "SELECT fuel_type, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY fuel_type;"}, {"role": "user", "content": "Filter out fuel types having fewer than 10 vehicles."}, {"role": "assistant", "content": "SELECT fuel_type, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Now order the result by vehicle_count descending and limit to the top 5 entries."}, {"role": "assistant", "content": "SELECT fuel_type, COUNT(*) AS vehicle_count\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10\nORDER BY vehicle_count DESC\nLIMIT 5;"}, {"role": "user", "content": "Also add the average capacity for each fuel_type."}, {"role": "assistant", "content": "SELECT fuel_type,\n COUNT(*) AS vehicle_count,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10\nORDER BY vehicle_count DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.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.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n", "conversations": [{"role": "user", "content": "List the number of bookings made by each passenger, including passenger_id, first_name, last_name, and booking_count."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name;"}, {"role": "user", "content": "Actually, only include passengers who have made at least 2 bookings."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name\nHAVING COUNT(b.booking_id) >= 2;"}, {"role": "user", "content": "Also include the average fare per passenger."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count,\n AVG(b.fare) AS average_fare\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name\nHAVING COUNT(b.booking_id) >= 2;"}, {"role": "user", "content": "Sort the results by average_fare descending and limit to the top 5."}, {"role": "assistant", "content": "SELECT p.passenger_id,\n p.first_name,\n p.last_name,\n COUNT(b.booking_id) AS booking_count,\n AVG(b.fare) AS average_fare\nFROM transportation.passengers p\nLEFT JOIN transportation.bookings b\n ON p.passenger_id = b.passenger_id\nGROUP BY p.passenger_id,\n p.first_name,\n p.last_name\nHAVING COUNT(b.booking_id) >= 2\nORDER BY average_fare DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\n", "conversations": [{"role": "user", "content": "Find pairs of distinct routes that share the same destination location but start from different origins. Include the route ID and route number for both routes and the shared destination location ID."}, {"role": "assistant", "content": "SELECT\n r1.route_id AS route1_id,\n r1.route_number AS route1_number,\n r2.route_id AS route2_id,\n r2.route_number AS route2_number,\n r1.destination_location_id AS shared_destination_location_id\nFROM transportation.routes AS r1\nJOIN transportation.routes AS r2\n ON r1.destination_location_id = r2.destination_location_id\n AND r1.route_id < r2.route_id\nWHERE\n r1.origin_location_id != r2.origin_location_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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 booking with its previous booking time for the same passenger."}, {"role": "assistant", "content": "SELECT b.booking_id,\n b.passenger_id,\n b.booking_time,\n LAG(b.booking_time) OVER (PARTITION BY b.passenger_id ORDER BY b.booking_time) AS previous_booking_time\nFROM transportation.bookings b;"}, {"role": "user", "content": "I only want records where the gap between bookings is more than 7 days."}, {"role": "assistant", "content": "SELECT booking_id,\n passenger_id,\n booking_time,\n previous_booking_time\nFROM (\n SELECT booking_id,\n passenger_id,\n booking_time,\n LAG(booking_time) OVER (PARTITION BY passenger_id ORDER BY booking_time) AS previous_booking_time\n FROM transportation.bookings\n) t\nWHERE previous_booking_time IS NOT NULL\n AND booking_time - previous_booking_time > INTERVAL '7 days';"}, {"role": "user", "content": "Also include the total number of bookings for each passenger."}, {"role": "assistant", "content": "SELECT booking_id,\n passenger_id,\n booking_time,\n previous_booking_time,\n COUNT(*) OVER (PARTITION BY passenger_id) AS total_bookings\nFROM (\n SELECT booking_id,\n passenger_id,\n booking_time,\n LAG(booking_time) OVER (PARTITION BY passenger_id ORDER BY booking_time) AS previous_booking_time\n FROM transportation.bookings\n) t\nWHERE previous_booking_time IS NOT NULL\n AND booking_time - previous_booking_time > INTERVAL '7 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "For each user, what is the average time difference in days between their wallet creations? Return user_id and avg_diff_days."}, {"role": "assistant", "content": "WITH diffs AS (\n SELECT\n user_id,\n EXTRACT(EPOCH FROM (created_at - LAG(created_at) OVER (PARTITION BY user_id ORDER BY created_at))) / 86400 AS diff_days\n FROM web3.wallets\n)\nSELECT\n user_id,\n AVG(diff_days) AS avg_diff_days\nFROM diffs\nWHERE diff_days IS NOT NULL\nGROUP BY user_id;"}, {"role": "user", "content": "Actually, only include users who have created more than 2 wallets."}, {"role": "assistant", "content": "WITH diffs AS (\n SELECT\n user_id,\n EXTRACT(EPOCH FROM (created_at - LAG(created_at) OVER (PARTITION BY user_id ORDER BY created_at))) / 86400 AS diff_days\n FROM web3.wallets\n)\nSELECT\n user_id,\n AVG(diff_days) AS avg_diff_days\nFROM diffs\nWHERE diff_days IS NOT NULL\nGROUP BY user_id\nHAVING COUNT(diff_days) > 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id text PRIMARY KEY, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.tokens ( token_id.text, contract_address.text, token_name.text, token_symbol.text, decimals.integer, total_supply.numeric )\nCREATE TABLE web3.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all failed transactions along with the from and to addresses, and the gas used."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used FROM web3.transactions WHERE status = 'failed';"}, {"role": "user", "content": "Actually, I also need to see the block number and timestamp for these failed transactions."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used, block_number, timestamp FROM web3.transactions WHERE status = 'failed';"}, {"role": "user", "content": "There's a typo in your SQL, it should be 'timestamp' not 'timestamp'. Also, sort the results by block number in descending order."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used, block_number, timestamp FROM web3.transactions WHERE status = 'failed' ORDER BY block_number DESC;"}, {"role": "user", "content": "Now filter to only show transactions with gas used greater than 100,000."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, gas_used, block_number, timestamp FROM web3.transactions WHERE status = 'failed' AND gas_used > 100000 ORDER BY block_number DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )\n", "conversations": [{"role": "user", "content": "For each transaction, show its transaction_id and the count of tokens transferred within that transaction."}, {"role": "assistant", "content": "SELECT transaction_id, COUNT(token_id) AS tokens_transferred FROM web3.token_transfers GROUP BY transaction_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Find pairs of wallets that were created at the exact same timestamp but are owned by different users. List the IDs of both wallets and the shared creation timestamp."}, {"role": "assistant", "content": "SELECT\n w1.wallet_id AS wallet1_id,\n w2.wallet_id AS wallet2_id,\n w1.created_at\nFROM\n web3.wallets w1\nJOIN\n web3.wallets w2 ON w1.created_at = w2.created_at\nWHERE\n w1.wallet_id < w2.wallet_id\n AND w1.user_id != w2.user_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Find pairs of users who registered on the same weekday but in different years. List the user ID and registration date for both users, and the weekday name."}, {"role": "assistant", "content": "SELECT u1.user_id, u1.created_at AS user1_created_at, u2.user_id, u2.created_at AS user2_created_at, TO_CHAR(u1.created_at, 'Day') AS registration_weekday FROM web3.users u1 JOIN web3.users u2 ON TO_CHAR(u1.created_at, 'Day') = TO_CHAR(u2.created_at, 'Day') AND EXTRACT(YEAR FROM u1.created_at) <> EXTRACT(YEAR FROM u2.created_at) AND u1.user_id < u2.user_id ORDER BY TO_CHAR(u1.created_at, 'D'), u1.created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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": "For each user, find the previous user by registration time. List current user_id and username, previous user_id and username, and the time difference in minutes between their registrations."}, {"role": "assistant", "content": "SELECT u.user_id AS current_user_id,\n u.username AS current_username,\n p.user_id AS previous_user_id,\n p.username AS previous_username,\n EXTRACT(EPOCH FROM (u.created_at - p.created_at)) / 60 AS diff_minutes\nFROM web3.users u\nJOIN web3.users p\n ON p.created_at = (\n SELECT MAX(created_at)\n FROM web3.users\n WHERE created_at < u.created_at\n )\nORDER BY u.created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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": "Calculate the total transfer volume and number of transfers for each Avalanche token tick over the past 7 days."}, {"role": "assistant", "content": "SELECT ta.tick,\n SUM(ta.amt) AS total_volume,\n COUNT(*) AS transfer_count\nFROM token_activities_avalanche ta\nWHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY ta.tick;"}, {"role": "user", "content": "Now include the creator from token_info and filter to tokens with total_volume > 500."}, {"role": "assistant", "content": "SELECT sub.tick,\n sub.total_volume,\n sub.transfer_count,\n ti.creator\nFROM (\n SELECT ta.tick,\n SUM(ta.amt) AS total_volume,\n COUNT(*) AS transfer_count\n FROM token_activities_avalanche ta\n WHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\n GROUP BY ta.tick\n) sub\nJOIN token_info ti ON sub.tick = ti.tick\nWHERE sub.total_volume > 500;"}, {"role": "user", "content": "Also add the current total_supply from token_balances_avalanche for each tick."}, {"role": "assistant", "content": "SELECT sub.tick,\n sub.total_volume,\n sub.transfer_count,\n ti.creator,\n tb.total_supply\nFROM (\n SELECT ta.tick,\n SUM(ta.amt) AS total_volume,\n COUNT(*) AS transfer_count\n FROM token_activities_avalanche ta\n WHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\n GROUP BY ta.tick\n) sub\nJOIN token_info ti ON sub.tick = ti.tick\nJOIN token_balances_avalanche tb ON sub.tick = tb.tick\nWHERE sub.total_volume > 500;"}]} +{"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 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": "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 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 social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\n", "conversations": [{"role": "user", "content": "Compute the co-occurrence count for each hashtag pair across all posts."}, {"role": "assistant", "content": "SELECT ph1.hashtag_id AS tag_a, ph2.hashtag_id AS tag_b, COUNT(DISTINCT ph1.post_id) AS co_occurrence_count\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id\nGROUP BY ph1.hashtag_id, ph2.hashtag_id;"}, {"role": "user", "content": "Only include pairs with co_occurrence_count >= 3."}, {"role": "assistant", "content": "SELECT ph1.hashtag_id AS tag_a, ph2.hashtag_id AS tag_b, COUNT(DISTINCT ph1.post_id) AS co_occurrence_count\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id\nGROUP BY ph1.hashtag_id, ph2.hashtag_id\nHAVING COUNT(DISTINCT ph1.post_id) >= 3;"}, {"role": "user", "content": "Sort the results by co_occurrence_count descending and limit to the top 5 pairs."}, {"role": "assistant", "content": "SELECT ph1.hashtag_id AS tag_a, ph2.hashtag_id AS tag_b, COUNT(DISTINCT ph1.post_id) AS co_occurrence_count\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id\nGROUP BY ph1.hashtag_id, ph2.hashtag_id\nHAVING COUNT(DISTINCT ph1.post_id) >= 3\nORDER BY co_occurrence_count DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\n", "conversations": [{"role": "user", "content": "List all group chats and the total count of messages sent in each one."}, {"role": "assistant", "content": "SELECT T1.group_name, count(T2.message_id) AS message_count FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE GROUP BY T1.group_name;"}, {"role": "user", "content": "Can you refine that to only show group chats that have more than 100 messages?"}, {"role": "assistant", "content": "SELECT T1.group_name, count(T2.message_id) AS message_count FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE GROUP BY T1.group_name HAVING count(T2.message_id) > 100;"}, {"role": "user", "content": "Great, now please also include the creation time of these group chats and order the results by the message count in descending order."}, {"role": "assistant", "content": "SELECT T1.group_name, T1.created_at, count(T2.message_id) AS message_count FROM social_media.conversations AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T1.is_group_chat = TRUE GROUP BY T1.group_name, T1.created_at HAVING count(T2.message_id) > 100 ORDER BY message_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id.text, user_id.text, content.text, media_url.text, media_type.text, created_at.timestamp, updated_at.timestamp, visibility.text, location_lat.numeric, location_lon.numeric )\nCREATE TABLE social_media.comments (\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 character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications ( notification_id.text, recipient_user_id.text, sender_user_id.text, notification_type.text, target_entity_id.text, target_entity_type.text, created_at.timestamp, read_at.timestamp )\n", "conversations": [{"role": "user", "content": "For each user, show their username and how many unique conversations they have sent at least one message in where the conversation is a group chat."}, {"role": "assistant", "content": "SELECT u.username, COUNT(DISTINCT m.conversation_id) AS group_chats_messaged_in\nFROM social_media.users u\nJOIN social_media.messages m ON u.user_id = m.sender_user_id\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY u.username;"}, {"role": "user", "content": "Instead, show only users who have sent messages in more than one group chat, and include their email addresses."}, {"role": "assistant", "content": "SELECT u.username, u.email, COUNT(DISTINCT m.conversation_id) AS group_chats_messaged_in\nFROM social_media.users u\nJOIN social_media.messages m ON u.user_id = m.sender_user_id\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY u.username, u.email\nHAVING COUNT(DISTINCT m.conversation_id) > 1;"}, {"role": "user", "content": "Also add the most recent message time sent by each user in these group chats."}, {"role": "assistant", "content": "SELECT u.username, u.email, COUNT(DISTINCT m.conversation_id) AS group_chats_messaged_in, MAX(m.sent_at) AS last_message_time\nFROM social_media.users u\nJOIN social_media.messages m ON u.user_id = m.sender_user_id\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nWHERE c.is_group_chat = TRUE\nGROUP BY u.username, u.email\nHAVING COUNT(DISTINCT m.conversation_id) > 1;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "How many notifications have been sent by each sender? Show sender_user_id and notification count."}, {"role": "assistant", "content": "SELECT sender_user_id, COUNT(*) AS notification_count\nFROM social_media.notifications\nWHERE sender_user_id IS NOT NULL\nGROUP BY sender_user_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\n", "conversations": [{"role": "user", "content": "Count the number of comments that have been updated since they were first created."}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.comments WHERE updated_at > created_at;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) )\nCREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) )\nCREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, follower_user_id character varying(64) NOT NULL, following_user_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) )\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\nCREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) )\n", "conversations": [{"role": "user", "content": "I need the count of messages each user has sent per conversation, along with the conversation's group_name when it's a group chat."}, {"role": "assistant", "content": "SELECT m.sender_user_id,\n u.username,\n m.conversation_id,\n CASE WHEN c.is_group_chat THEN c.group_name ELSE 'Direct Chat' END AS chat_name,\n COUNT(*) AS total_messages\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nGROUP BY m.sender_user_id, u.username, m.conversation_id, c.is_group_chat, c.group_name;"}, {"role": "user", "content": "Only include conversations where the total messages exceed 5, and alias the count as message_count."}, {"role": "assistant", "content": "SELECT m.sender_user_id,\n u.username,\n m.conversation_id,\n CASE WHEN c.is_group_chat THEN c.group_name ELSE 'Direct Chat' END AS chat_name,\n COUNT(*) AS message_count\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nGROUP BY m.sender_user_id, u.username, m.conversation_id, c.is_group_chat, c.group_name\nHAVING COUNT(*) > 5;"}, {"role": "user", "content": "Exclude messages that have neither content nor media_url."}, {"role": "assistant", "content": "SELECT m.sender_user_id,\n u.username,\n m.conversation_id,\n CASE WHEN c.is_group_chat THEN c.group_name ELSE 'Direct Chat' END AS chat_name,\n COUNT(*) AS message_count\nFROM social_media.messages m\nJOIN social_media.conversations c ON m.conversation_id = c.conversation_id\nJOIN social_media.users u ON m.sender_user_id = u.user_id\nWHERE NOT ((m.content IS NULL OR m.content = '') AND m.media_url IS NULL)\nGROUP BY m.sender_user_id, u.username, m.conversation_id, c.is_group_chat, c.group_name\nHAVING COUNT(*) > 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )\n", "conversations": [{"role": "user", "content": "Show me all conversations that have more than 10 messages, along with the group name and the usernames of their participants."}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, u.username\nFROM social_media.conversations c\nJOIN social_media.messages m ON c.conversation_id = m.conversation_id\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nGROUP BY c.conversation_id, c.group_name, u.username\nHAVING COUNT(m.message_id) > 10;"}, {"role": "user", "content": "Instead, can you only show group chats where the group name contains 'Study' and list the time each participant joined?"}, {"role": "assistant", "content": "SELECT c.conversation_id, c.group_name, u.username, cp.joined_at\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp ON c.conversation_id = cp.conversation_id\nJOIN social_media.users u ON cp.user_id = u.user_id\nWHERE c.is_group_chat = true AND c.group_name ILIKE '%Study%';"}]} +{"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 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": "Show me the usernames and the group names for each user who has sent at least one message in a group chat."}, {"role": "assistant", "content": "SELECT DISTINCT u.username, c.group_name\nFROM social_media.users u\nJOIN social_media.conversation_participants cp ON u.user_id = cp.user_id\nJOIN social_media.conversations c ON cp.conversation_id = c.conversation_id\nJOIN social_media.messages m ON c.conversation_id = m.conversation_id AND u.user_id = m.sender_user_id\nWHERE c.is_group_chat = true;"}, {"role": "user", "content": "Can you include the total number of messages each user has sent in each group chat as well?"}, {"role": "assistant", "content": "SELECT u.username, c.group_name, COUNT(m.message_id) AS message_count\nFROM social_media.users u\nJOIN social_media.conversation_participants cp ON u.user_id = cp.user_id\nJOIN social_media.conversations c ON cp.conversation_id = c.conversation_id\nJOIN social_media.messages m ON c.conversation_id = m.conversation_id AND u.user_id = m.sender_user_id\nWHERE c.is_group_chat = true\nGROUP BY u.username, c.group_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "What is the count of appointments for each lawyer? Display the lawyer ID and the total count."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments GROUP BY lawyer_id;"}, {"role": "user", "content": "Only show lawyers who have more than 5 appointments."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments GROUP BY lawyer_id HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Consider only appointments that were created in the year 2023."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments WHERE created_at BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59' GROUP BY lawyer_id HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Order the results by the appointment count in descending order."}, {"role": "assistant", "content": "SELECT lawyer_id, COUNT(*) AS appointment_count FROM legal_services.appointments WHERE created_at BETWEEN '2023-01-01 00:00:00' AND '2023-12-31 23:59:59' GROUP BY lawyer_id HAVING COUNT(*) > 5 ORDER BY appointment_count DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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 ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )\nCREATE TABLE legal_services.invoices ( invoice_id text PRIMARY KEY, invoice_number text UNIQUE, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "What is the total sum of amounts paid for all invoices?"}, {"role": "assistant", "content": "SELECT SUM(amount_paid) FROM invoices;"}, {"role": "user", "content": "Group this total by the status of the invoice."}, {"role": "assistant", "content": "SELECT status, SUM(amount_paid) FROM invoices GROUP BY status;"}, {"role": "user", "content": "Only show statuses where the total amount paid is greater than 50000."}, {"role": "assistant", "content": "SELECT status, SUM(amount_paid) FROM invoices GROUP BY status HAVING SUM(amount_paid) > 50000;"}, {"role": "user", "content": "Order the results by the total paid amount in descending order."}, {"role": "assistant", "content": "SELECT status, SUM(amount_paid) FROM invoices GROUP BY status HAVING SUM(amount_paid) > 50000 ORDER BY SUM(amount_paid) DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )\n", "conversations": [{"role": "user", "content": "Show me the subject and start times of all appointments along with the corresponding lawyer IDs for each client."}, {"role": "assistant", "content": "SELECT client_id, lawyer_id, subject, start_time FROM legal_services.appointments;"}]} +{"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 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": "Get a list of appointment_id, start_time, and invoice_number for appointments that have a related invoice."}, {"role": "assistant", "content": "SELECT a.appointment_id,\n a.start_time,\n i.invoice_number\nFROM legal_services.appointments a\nJOIN legal_services.invoices i\n ON a.case_id = i.case_id;"}, {"role": "user", "content": "Also include only appointments that are completed and invoices that are fully paid (status 'Paid')."}, {"role": "assistant", "content": "SELECT a.appointment_id,\n a.start_time,\n i.invoice_number\nFROM legal_services.appointments a\nJOIN legal_services.invoices i\n ON a.case_id = i.case_id\nWHERE a.status = 'Completed'\n AND i.status = 'Paid';"}]} +{"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 legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\n", "conversations": [{"role": "user", "content": "Show me all time entries from the last 90 days, including the entry description, hours spent, the name of the case, and the name of the client."}, {"role": "assistant", "content": "SELECT T1.description, T1.hours_spent, T2.case_name, T3.first_name, T3.last_name FROM legal_services.time_entries AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id JOIN clients AS T3 ON T2.client_id = T3.client_id WHERE T1.date_worked >= CURRENT_DATE - INTERVAL '90 days';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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": "I want to see a list of invoice_number and appointment_id for each invoice that has a scheduled appointment."}, {"role": "assistant", "content": "SELECT i.invoice_number,\n a.appointment_id\nFROM legal_services.invoices i\nJOIN legal_services.appointments a\n ON i.case_id = a.case_id\nWHERE a.status = 'Scheduled';"}, {"role": "user", "content": "Only include those invoices whose due_date is still in the future."}, {"role": "assistant", "content": "SELECT i.invoice_number,\n a.appointment_id\nFROM legal_services.invoices i\nJOIN legal_services.appointments a\n ON i.case_id = a.case_id\nWHERE a.status = 'Scheduled'\n AND i.due_date > CURRENT_DATE;"}, {"role": "user", "content": "Finally, sort the results by the invoice issue_date in descending order."}, {"role": "assistant", "content": "SELECT i.invoice_number,\n a.appointment_id\nFROM legal_services.invoices i\nJOIN legal_services.appointments a\n ON i.case_id = a.case_id\nWHERE a.status = 'Scheduled'\n AND i.due_date > CURRENT_DATE\nORDER BY i.issue_date DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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)\n", "conversations": [{"role": "user", "content": "List the document name, type, version, and description for all documents."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents;"}, {"role": "user", "content": "Only include documents where the description is not null."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents WHERE description IS NOT NULL;"}, {"role": "user", "content": "Also, filter to only show documents with a version greater than 2."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents WHERE description IS NOT NULL AND version > 2;"}, {"role": "user", "content": "Order the results by upload timestamp descending."}, {"role": "assistant", "content": "SELECT document_name, document_type, version, description FROM documents WHERE description IS NOT NULL AND version > 2 ORDER BY upload_timestamp DESC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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 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 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 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": "For every customer, show their first name, last name, and the policy number of any policies they own."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.policy_number FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id;"}, {"role": "user", "content": "Only include policies with status 'Active' or 'Pending'. Also add the policy start date to the results."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.policy_number, T2.start_date FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id WHERE T2.status IN ('Active', 'Pending');"}, {"role": "user", "content": "Further filter the customers to only those in California ('CA'). Order the results by the customer's last name and then first name."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, T2.policy_number, T2.start_date FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id WHERE T2.status IN ('Active', 'Pending') AND T1.state = 'CA' ORDER BY T1.last_name, T1.first_name;"}, {"role": "user", "content": "Instead of listing each policy, tell me how many 'Active' or 'Pending' policies each of these California customers has. Show their full name and the count."}, {"role": "assistant", "content": "SELECT T1.first_name, T1.last_name, COUNT(T2.policy_id) FROM insurance.customers AS T1 JOIN insurance.policies AS T2 ON T1.customer_id = T2.customer_id WHERE T2.status IN ('Active', 'Pending') AND T1.state = 'CA' GROUP BY T1.customer_id, T1.first_name, T1.last_name ORDER BY T1.last_name, T1.first_name;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128), -- address of the receiver (can be null for contract deployment)\n value numeric(38,14) NOT NULL, -- value transferred\n gas_used integer NOT NULL, -- amount of gas used by the transaction\n gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction\n block_number integer NOT NULL, -- block number containing the transaction\n timestamp timestamp NOT NULL, -- time when the transaction was mined\n input_data text, -- input data of the transaction (can be null)\n status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)\n nonce integer NOT NULL, -- nonce of the sender at the time of the transaction\n PRIMARY KEY (transaction_id)\n)\n", "conversations": [{"role": "user", "content": "Find the top 5 transactions with the highest gas prices, including the from_address, to_address, and block_number, sorted by gas_price in descending order."}, {"role": "assistant", "content": "SELECT transaction_id, from_address, to_address, block_number, gas_price FROM web3.transactions ORDER BY gas_price DESC LIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE web3.contracts ( contract_id text, address text, abi text, bytecode text, deployer_address text, deployed_at timestamp, network_id text, status text )\nCREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )\nCREATE TABLE web3.tokens ( token_id text, contract_address text, token_name text, token_symbol text, decimals integer, total_supply numeric )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "List all contracts and the number of different tokens associated with each contract address. Show contract_id, contract address, and token_count."}, {"role": "assistant", "content": "SELECT c.contract_id, c.address, COUNT(DISTINCT t.token_id) AS token_count\nFROM web3.contracts c\nLEFT JOIN web3.tokens t ON c.address = t.contract_address\nGROUP BY c.contract_id, c.address;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )\n", "conversations": [{"role": "user", "content": "Which agents, along with their managers' full names, are licensed in 'TX' and are currently active?"}, {"role": "assistant", "content": "SELECT a.agent_id, a.first_name AS agent_first_name, a.last_name AS agent_last_name, m.first_name AS manager_first_name, m.last_name AS manager_last_name\nFROM insurance.agents a\nLEFT JOIN insurance.agents m ON a.manager_id = m.agent_id\nWHERE a.license_state = 'TX' AND a.status = 'Active';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n", "conversations": [{"role": "user", "content": "Show me the total transfer volume and number of transfers for each token tick on Bitcoin in the past 7 days."}, {"role": "assistant", "content": "SELECT tick, SUM(amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities_bitcoin\nWHERE block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY tick;"}, {"role": "user", "content": "Can you also include the creator of each token by joining with token_info_bitcoin?"}, {"role": "assistant", "content": "SELECT ta.tick, ti.creator, SUM(ta.amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities_bitcoin ta\nLEFT JOIN (\n SELECT tick, creator FROM token_info_bitcoin WHERE (tick, block_timestamp) IN (\n SELECT tick, MAX(block_timestamp) FROM token_info_bitcoin GROUP BY tick\n )\n) ti ON ta.tick = ti.tick\nWHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY ta.tick, ti.creator;"}, {"role": "user", "content": "Only include tokens where the total_volume is greater than 1000 and sort by total_volume descending, limit to top 5 tokens."}, {"role": "assistant", "content": "SELECT ta.tick, ti.creator, SUM(ta.amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities_bitcoin ta\nLEFT JOIN (\n SELECT tick, creator FROM token_info_bitcoin WHERE (tick, block_timestamp) IN (\n SELECT tick, MAX(block_timestamp) FROM token_info_bitcoin GROUP BY tick\n )\n) ti ON ta.tick = ti.tick\nWHERE ta.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY ta.tick, ti.creator\nHAVING SUM(ta.amt) > 1000\nORDER BY total_volume DESC\nLIMIT 5;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \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.maintenance_logs ( log_id.text, vehicle_id.text, service_date.date, odometer_reading.integer, service_type.text, description.text, cost.numeric, mechanic_name.text, next_service_due_date.date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\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 the vehicle ID and the total number of fuel logs recorded for each vehicle."}, {"role": "assistant", "content": "SELECT vehicle_id , count(*) FROM transportation.fuel_logs GROUP BY vehicle_id"}, {"role": "user", "content": "Filter this list to only show vehicles with more than 5 fuel log entries."}, {"role": "assistant", "content": "SELECT vehicle_id , count(*) FROM transportation.fuel_logs GROUP BY vehicle_id HAVING count(*) > 5"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n", "conversations": [{"role": "user", "content": "List all partners who have provided a phone number, showing their full name and email."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL;"}, {"role": "user", "content": "Okay, now only include those partners hired between 2020-01-01 and 2022-12-31."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL AND hire_date BETWEEN '2020-01-01' AND '2022-12-31';"}, {"role": "user", "content": "Can you also add their specialization to the output?"}, {"role": "assistant", "content": "SELECT first_name, last_name, email, specialization FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL AND hire_date BETWEEN '2020-01-01' AND '2022-12-31';"}, {"role": "user", "content": "Finally, order the results by specialization in ascending order, then by last name."}, {"role": "assistant", "content": "SELECT first_name, last_name, email, specialization FROM legal_services.lawyers WHERE is_partner = TRUE AND phone IS NOT NULL AND hire_date BETWEEN '2020-01-01' AND '2022-12-31' ORDER BY specialization ASC, last_name ASC;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\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) )\n", "conversations": [{"role": "user", "content": "Show me the email addresses and hire dates for all staff who have a manager."}, {"role": "assistant", "content": "SELECT work_email, hire_date\nFROM hospitality_technology.staff\nWHERE manager_id IS NOT NULL;"}, {"role": "user", "content": "Only include staff who were hired after January 1, 2023."}, {"role": "assistant", "content": "SELECT work_email, hire_date\nFROM hospitality_technology.staff\nWHERE manager_id IS NOT NULL AND hire_date > '2023-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "Get the total number of appointments grouped by status."}, {"role": "assistant", "content": "SELECT status,\n COUNT(*) AS appointment_count\nFROM healthcare.appointments\nGROUP BY status;"}, {"role": "user", "content": "Now filter to include only statuses with more than 50 appointments."}, {"role": "assistant", "content": "SELECT status,\n COUNT(*) AS appointment_count\nFROM healthcare.appointments\nGROUP BY status\nHAVING COUNT(*) > 50;"}]} +{"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 social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\n", "conversations": [{"role": "user", "content": "List all group chats created in 2024, showing the group_name, conversation_id, and creation time."}, {"role": "assistant", "content": "SELECT conversation_id, group_name, created_at\nFROM social_media.conversations\nWHERE is_group_chat = true AND created_at >= '2024-01-01' AND created_at < '2025-01-01';"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_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 (doctor_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.medications ( medication_id 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.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\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": "Which patients have a primary insurance policy and are subscribed to a plan provided by 'Cigna'? List patient ID, full name, policy number, plan ID, and insurance provider."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, pi.policy_number, pi.plan_id, ip.insurance_provider\nFROM healthcare.patient_insurance pi\nJOIN healthcare.patients p ON pi.patient_id = p.patient_id\nJOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id\nWHERE pi.is_primary = true AND ip.insurance_provider = 'Cigna';"}, {"role": "user", "content": "Additionally, only show results where the policy has not expired yet."}, {"role": "assistant", "content": "SELECT p.patient_id, p.first_name, p.last_name, pi.policy_number, pi.plan_id, ip.insurance_provider\nFROM healthcare.patient_insurance pi\nJOIN healthcare.patients p ON pi.patient_id = p.patient_id\nJOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id\nWHERE pi.is_primary = true AND ip.insurance_provider = 'Cigna' AND (pi.expiration_date IS NULL OR pi.expiration_date >= CURRENT_DATE);"}]} +{"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 legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\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.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, 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.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n", "conversations": [{"role": "user", "content": "I need a list showing the name of each law firm and the full name of every lawyer employed by that firm."}, {"role": "assistant", "content": "SELECT T1.firm_name, T2.first_name, T2.last_name FROM law_firms AS T1 JOIN lawyers AS T2 ON T1.firm_id = T2.firm_id;"}]} +{"system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n", "conversations": [{"role": "user", "content": "Show me all customers (customer_id, first_name, last_name, email) who were born after 1985 (date_of_birth > '1985-12-31') and have an email address ending with '@yahoo.com', along with their city and state information."}, {"role": "assistant", "content": "SELECT customer_id, first_name, last_name, email, city, state FROM financial_services.customers WHERE date_of_birth > '1985-12-31' AND email LIKE '%@yahoo.com';"}]} +{"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 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.applications (\n application_id character varying(64) NOT NULL, -- unique identifier for the application\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n service_id character varying(64) NOT NULL, -- FK to services table\n submitted_at timestamp NOT NULL, -- time the application was submitted\n status character varying(50) NOT NULL, -- e.g., Submitted, Processing, Approved, Rejected, Pending Info\n last_updated_at timestamp NOT NULL, -- time the status or details last changed\n assigned_employee_id character varying(64), -- FK to employees table (optional)\n decision_date date, -- date when a final decision was made\n notes text, -- internal notes or citizen-provided comments\n reference_number character varying(100) UNIQUE, -- publicly visible reference number\n PRIMARY KEY (application_id)\n)\n", "conversations": [{"role": "user", "content": "List the number of applications submitted by each citizen."}, {"role": "assistant", "content": "SELECT c.citizen_id, c.first_name, c.last_name, COUNT(a.application_id) AS application_count\nFROM government_services.citizens c\nLEFT JOIN government_services.applications a ON c.citizen_id = a.citizen_id\nGROUP BY c.citizen_id, c.first_name, c.last_name;"}]}