{"conversations": [{"role": "user", "content": "Could you provide the total number of game sessions and the number of distinct players for each game genre? Display the genre, session count, and player count."}, {"role": "assistant", "content": "SELECT g.genre, COUNT(gs.session_id) AS session_count, COUNT(DISTINCT gs.player_id) AS player_count FROM gaming_technology.game_sessions AS gs JOIN gaming_technology.games AS g ON gs.game_id = g.game_id WHERE g.genre IS NOT NULL GROUP BY g.genre ORDER BY g.genre;"}, {"role": "user", "content": "Thanks. Can you modify the query to only include games that were released after the year 2020?"}, {"role": "assistant", "content": "SELECT g.genre, COUNT(gs.session_id) AS session_count, COUNT(DISTINCT gs.player_id) AS player_count FROM gaming_technology.game_sessions AS gs JOIN gaming_technology.games AS g ON gs.game_id = g.game_id WHERE g.genre IS NOT NULL AND g.release_date >= '2021-01-01' GROUP BY g.genre ORDER BY g.genre;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\n"} {"conversations": [{"role": "user", "content": "What are the safety ratings or crash statistics for the Boeing 787 Dreamliner?"}, {"role": "assistant", "content": "I'm sorry, but I don't have access to safety ratings or crash statistics for specific aircraft models like the Boeing 787 Dreamliner. My data is limited to the information in the aircraft_models table, which includes details such as model name, manufacturer, passenger capacity, and technical specifications. For safety-related information, I recommend consulting official aviation authorities or safety reports."}], "system": "You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.aircraft_models ( model_id text, model_name text, manufacturer text, passenger_capacity integer, max_range_km integer, engine_type text, wingspan_m numeric, status text, first_flight_date date )\n"} {"conversations": [{"role": "user", "content": "List all medical records, showing the record ID, record date, and the full name of the doctor who created the record. Include the patient ID as well."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.record_date, mr.patient_id, d.first_name, d.last_name FROM healthcare.medical_records mr JOIN doctors d ON mr.doctor_id = d.doctor_id;"}, {"role": "user", "content": "Refine this to only include records where the chief_complaint is not null or empty and the doctor's specialty is 'Cardiology'."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.record_date, mr.patient_id, d.first_name, d.last_name FROM healthcare.medical_records mr JOIN doctors d ON mr.doctor_id = d.doctor_id WHERE (mr.chief_complaint IS NOT NULL AND mr.chief_complaint != '') AND d.specialty = 'Cardiology';"}, {"role": "user", "content": "Also, sort the results by record_date in descending order and limit the output to the top 10 records."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.record_date, mr.patient_id, d.first_name, d.last_name FROM healthcare.medical_records mr JOIN doctors d ON mr.doctor_id = d.doctor_id WHERE (mr.chief_complaint IS NOT NULL AND mr.chief_complaint != '') AND d.specialty = 'Cardiology' ORDER BY mr.record_date DESC LIMIT 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\n"} {"conversations": [{"role": "user", "content": "List users who have received notifications triggered by another user (non-system notifications). Show the recipient username, notification type, and the sender username."}, {"role": "assistant", "content": "SELECT T1.username AS recipient_username, T2.notification_type, T3.username AS sender_username FROM social_media.users AS T1 JOIN social_media.notifications AS T2 ON T1.user_id = T2.recipient_user_id JOIN social_media.users AS T3 ON T2.sender_user_id = T3.user_id;"}, {"role": "user", "content": "Refine the list from Turn 1 to only include notifications of type 'follow' or 'mention'."}, {"role": "assistant", "content": "SELECT T1.username AS recipient_username, T2.notification_type, T3.username AS sender_username FROM social_media.users AS T1 JOIN social_media.notifications AS T2 ON T1.user_id = T2.recipient_user_id JOIN social_media.users AS T3 ON T2.sender_user_id = T3.user_id WHERE T2.notification_type IN ('follow', 'mention');"}, {"role": "user", "content": "Further filter to only include notifications created in 2024 and order the results by notification creation time descending."}, {"role": "assistant", "content": "SELECT T1.username AS recipient_username, T2.notification_type, T3.username AS sender_username FROM social_media.users AS T1 JOIN social_media.notifications AS T2 ON T1.user_id = T2.recipient_user_id JOIN social_media.users AS T3 ON T2.sender_user_id = T3.user_id WHERE T2.notification_type IN ('follow', 'mention') AND EXTRACT(YEAR FROM T2.created_at) = 2024 ORDER BY T2.created_at DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\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.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n"} {"conversations": [{"role": "user", "content": "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 SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\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": "For each player, calculate the total quantity of items they have acquired. Return player_id and total_quantity."}, {"role": "assistant", "content": "SELECT player_id,\n SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id;"}, {"role": "user", "content": "Exclude players whose total_quantity is less than 50."}, {"role": "assistant", "content": "SELECT player_id,\n SUM(quantity) AS total_quantity\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) >= 50;"}, {"role": "user", "content": "Also include the number of distinct items each player has acquired as distinct_item_count."}, {"role": "assistant", "content": "SELECT player_id,\n SUM(quantity) AS total_quantity,\n COUNT(DISTINCT item_id) AS distinct_item_count\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) >= 50;"}, {"role": "user", "content": "Finally, order the results by total_quantity in descending order."}, {"role": "assistant", "content": "SELECT player_id,\n SUM(quantity) AS total_quantity,\n COUNT(DISTINCT item_id) AS distinct_item_count\nFROM gaming_technology.player_inventory\nGROUP BY player_id\nHAVING SUM(quantity) >= 50\nORDER BY total_quantity DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )\n"} {"conversations": [{"role": "user", "content": "Which route numbers connect locations with a distance less than 80 km and more than 5 words in their description? Include the route type in the results."}, {"role": "assistant", "content": "SELECT route_number, type FROM transportation.routes WHERE distance_km < 80 AND array_length(regexp_split_to_array(description, '\\s+'), 1) > 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens with decimals equal to 18."}, {"role": "assistant", "content": "SELECT name, contract_address, total_supply FROM token_metas WHERE is_erc20 = 1 AND decimals = 18 ORDER BY CAST(total_supply AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Can you join this with the token_prices table to include the current price of each token?"}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply, tp.price FROM token_metas tm JOIN token_prices tp ON tm.contract_address = tp.address WHERE tm.is_erc20 = 1 AND tm.decimals = 18 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Now filter these results to only show tokens where the price is greater than $0.1."}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply, tp.price FROM token_metas tm JOIN token_prices tp ON tm.contract_address = tp.address WHERE tm.is_erc20 = 1 AND tm.decimals = 18 AND tp.price > 0.1 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n token_id varchar NOT NULL, -- The number of the token\n contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n amount bigint NOT NULL, -- amount fields for the functionType in contract\n minter varchar NOT NULL, -- minter fields for the functionType in contract\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract\n mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract\n mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract\n mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract\n token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract\n metadata varchar NOT NULL, -- metadata fields for the functionType in contract\n name varchar NOT NULL, -- name fields for the functionType in contract\n image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n status varchar NOT NULL, -- status fields for the functionType in contract\n rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract\n rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract\n unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(mint_time / 1000 / 86400 / 30))\n)\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_info_bitcoin (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n max_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n lim decimal(38,0) NOT NULL, -- Mint limit: limit per inscription\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\n"} {"conversations": [{"role": "user", "content": "How many documents of type 'Pleading' were uploaded for case 'case_abc'?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM legal_services.documents WHERE document_type = 'Pleading' AND case_id = 'case_abc';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document\n case_id character varying(64) NOT NULL, -- FK to cases table\n document_name character varying(255) NOT NULL, -- name of the document file\n document_type character varying(100), -- e.g., Pleading, Contract, Evidence, Correspondence\n storage_path text NOT NULL, -- path or reference to the document storage location\n uploaded_by_lawyer_id character varying(64), -- FK to lawyers table (who uploaded it)\n upload_timestamp timestamp NOT NULL, -- time the document was uploaded\n version integer DEFAULT 1, -- document version number\n description text, -- brief description or notes about the document\n PRIMARY KEY (document_id)\n)\nCREATE TABLE legal_services.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 all insurance products that have 'auto' in their product type and are currently active, showing their product name and base premium."}, {"role": "assistant", "content": "SELECT product_id, product_name, product_type, base_premium FROM insurance.insurance_products WHERE product_type LIKE '%auto%' AND is_active = true;"}, {"role": "user", "content": "Now order these results by base premium in descending order and include the coverage details."}, {"role": "assistant", "content": "SELECT product_id, product_name, product_type, base_premium, coverage_details FROM insurance.insurance_products WHERE product_type LIKE '%auto%' AND is_active = true ORDER BY base_premium DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.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.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 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 character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n"} {"conversations": [{"role": "user", "content": "Show me the total deposit and withdrawal amounts for each account in February 2024."}, {"role": "assistant", "content": "SELECT account_id, SUM(CASE WHEN transaction_type = 'Deposit' THEN amount ELSE 0 END) AS total_deposit, SUM(CASE WHEN transaction_type = 'Withdrawal' THEN amount ELSE 0 END) AS total_withdrawal FROM financial_services.transactions WHERE transaction_date >= '2024-02-01' AND transaction_date < '2024-03-01' GROUP BY account_id;"}, {"role": "user", "content": "Can you include the account_number and account_type for each account as well?"}, {"role": "assistant", "content": "SELECT a.account_number, a.account_type, t.account_id, SUM(CASE WHEN t.transaction_type = 'Deposit' THEN t.amount ELSE 0 END) AS total_deposit, SUM(CASE WHEN t.transaction_type = 'Withdrawal' THEN t.amount ELSE 0 END) AS total_withdrawal FROM financial_services.transactions t INNER JOIN financial_services.accounts a ON t.account_id = a.account_id WHERE t.transaction_date >= '2024-02-01' AND t.transaction_date < '2024-03-01' GROUP BY a.account_number, a.account_type, t.account_id;"}, {"role": "user", "content": "Actually, only show accounts where the total deposit amount exceeds 10,000."}, {"role": "assistant", "content": "SELECT a.account_number, a.account_type, t.account_id, SUM(CASE WHEN t.transaction_type = 'Deposit' THEN t.amount ELSE 0 END) AS total_deposit, SUM(CASE WHEN t.transaction_type = 'Withdrawal' THEN t.amount ELSE 0 END) AS total_withdrawal FROM financial_services.transactions t INNER JOIN financial_services.accounts a ON t.account_id = a.account_id WHERE t.transaction_date >= '2024-02-01' AND t.transaction_date < '2024-03-01' GROUP BY a.account_number, a.account_type, t.account_id HAVING SUM(CASE WHEN t.transaction_type = 'Deposit' THEN t.amount ELSE 0 END) > 10000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 usernames and their respective group chat names where they are participants."}, {"role": "assistant", "content": "SELECT u.username, c.group_name \nFROM social_media.conversation_participants cp\nJOIN social_media.users u ON cp.user_id = u.user_id\nJOIN social_media.conversations c ON cp.conversation_id = c.conversation_id\nWHERE c.is_group_chat = true;"}, {"role": "user", "content": "I also want to see the group chat creation time. Can you include that?"}, {"role": "assistant", "content": "SELECT u.username, c.group_name, c.created_at \nFROM social_media.conversation_participants cp\nJOIN social_media.users u ON cp.user_id = u.user_id\nJOIN social_media.conversations c ON cp.conversation_id = c.conversation_id\nWHERE c.is_group_chat = true;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n"} {"conversations": [{"role": "user", "content": "Retrieve all pairs of distinct contract IDs that were created by the same creator within an hour of each other. Include the creator address and the timestamps of both contracts."}, {"role": "assistant", "content": "SELECT sc1.creator_address, sc1.contract_id AS contract_id_1, sc1.timestamp AS timestamp_1, sc2.contract_id AS contract_id_2, sc2.timestamp AS timestamp_2 FROM blockchain.smart_contracts sc1 JOIN blockchain.smart_contracts sc2 ON sc1.creator_address = sc2.creator_address AND sc1.contract_id <> sc2.contract_id WHERE ABS(UNIX_TIMESTAMP(sc1.timestamp) - UNIX_TIMESTAMP(sc2.timestamp)) <= 3600 AND sc1.timestamp < sc2.timestamp;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.smart_contracts ( contract_id.text, creator_address.text, code.text, timestamp.timestamp )\n"} {"conversations": [{"role": "user", "content": "List the first and last name of each citizen along with the city and state of the service location for their agency."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, sl.city, sl.state\nFROM government_services.citizens c\nJOIN government_services.payments p ON c.citizen_id = p.citizen_id\nJOIN government_services.employees e ON p.application_id IS NOT NULL AND e.agency_id IS NOT NULL\nJOIN government_services.service_locations sl ON e.agency_id = sl.agency_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text, national_id_number text, first_name text, last_name text, date_of_birth date, gender text, primary_address text, contact_email text, contact_phone text, registration_date timestamp, is_verified boolean )\nCREATE TABLE government_services.payments ( payment_id text, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\n"} {"conversations": [{"role": "user", "content": "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 SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\n"} {"conversations": [{"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 SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )\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": "Retrieve the policy_number, start_date, end_date, premium_amount, and corresponding product_name for policies with a coverage_limit greater than 500000."}, {"role": "assistant", "content": "SELECT p.policy_number, p.start_date, p.end_date, p.premium_amount, ip.product_name\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.coverage_limit > 500000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.insurance_products ( product_id text, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List the application reference numbers, the corresponding message subjects, and the sent dates for notifications related to each application."}, {"role": "assistant", "content": "SELECT a.reference_number, n.message_subject, n.sent_at\nFROM government_services.applications a\nJOIN government_services.notifications n ON a.application_id = n.application_id;"}, {"role": "user", "content": "Only include applications that have a status of 'Approved'."}, {"role": "assistant", "content": "SELECT a.reference_number, n.message_subject, n.sent_at\nFROM government_services.applications a\nJOIN government_services.notifications n ON a.application_id = n.application_id\nWHERE a.status = 'Approved';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.applications ( application_id text, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.notifications ( notification_id text, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n"} {"conversations": [{"role": "user", "content": "Show all medical records with the record_id, record_date, the patient's insurance policy_number, and the doctor's ID, for records linked to a currently active insurance policy."}, {"role": "assistant", "content": "SELECT mr.record_id, mr.record_date, pi.policy_number, mr.doctor_id\nFROM healthcare.medical_records mr\nINNER JOIN healthcare.patient_insurance pi ON mr.patient_id = pi.patient_id\nWHERE pi.expiration_date IS NULL OR pi.expiration_date >= CURRENT_DATE;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.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.json, created_at.timestamp )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n"} {"conversations": [{"role": "user", "content": "Show the tokens with a negative net flow this month on all chains."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now());"}, {"role": "user", "content": "Order them by net flow ascending and only show the bottom 5."}, {"role": "assistant", "content": "SELECT token_symbol, chain, net_flow FROM smart_money_token_performance WHERE net_flow < 0 AND date_trunc('month', CURRENT_DATE) = date_trunc('month', now()) ORDER BY net_flow ASC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\n"} {"conversations": [{"role": "user", "content": "List all reservations where the number of adults is greater than 2, showing reservation_id, guest_id, and the total_amount."}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, total_amount\nFROM hospitality_technology.reservations\nWHERE num_adults > 2;"}, {"role": "user", "content": "Can you also include the room_type_id and the status for each reservation?"}, {"role": "assistant", "content": "SELECT reservation_id, guest_id, room_type_id, status, total_amount\nFROM hospitality_technology.reservations\nWHERE num_adults > 2;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n"} {"conversations": [{"role": "user", "content": "Show me the top 3 tokens by USD value inflow where smart money was buying (type = 1), along with their token symbol and narrative."}, {"role": "assistant", "content": "SELECT token_symbol, narrative, usd_value FROM smart_money_token_inflow WHERE type = 1 ORDER BY usd_value DESC LIMIT 3;"}, {"role": "user", "content": "Actually, I want to see tokens with a USD value over $100,000."}, {"role": "assistant", "content": "SELECT token_symbol, narrative, usd_value FROM smart_money_token_inflow WHERE type = 1 AND usd_value > 100000 ORDER BY usd_value DESC LIMIT 3;"}, {"role": "user", "content": "Can you filter these results to only include tokens from the Ethereum chain?"}, {"role": "assistant", "content": "SELECT token_symbol, narrative, usd_value FROM smart_money_token_inflow WHERE type = 1 AND usd_value > 100000 AND chain = 'Ethereum' ORDER BY usd_value DESC LIMIT 3;"}, {"role": "user", "content": "Now include the 24-hour trading volume for these tokens from the token_dexpool_info table."}, {"role": "assistant", "content": "SELECT smti.token_symbol, smti.narrative, smti.usd_value, tdi.volume_24h FROM smart_money_token_inflow smti LEFT JOIN token_dexpool_info tdi ON smti.token_symbol = tdi.token_symbol AND smti.chain = tdi.chain WHERE smti.type = 1 AND smti.usd_value > 100000 AND smti.chain = 'Ethereum' ORDER BY smti.usd_value DESC LIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE project_fundraising_record (\",\n \"id character varying(32) NOT NULL, -- fundraising record id\",\n \"project_id character varying(32) NOT NULL, -- the invested project's id\",\n \"project_name character varying(128) NOT NULL, -- name of the invested project\",\n \"rounds_name character varying(32), -- name of the fundraising round\",\n \"investment_value numeric(38,14), -- amount of the fundraising in USD\",\n \"investment_date character varying(128), -- the date of the investment happened\",\n \"introduction character varying(128), -- the introduction of the invested project\",\n \"valuation numeric(38,14), -- the valuation of the project in USD when invested\",\n\n \"CREATE TABLE token_basic_info (\",\n \"coin_id character varying(100) NOT NULL, -- the id of the token\",\n \"token_name character varying(100) NOT NULL, -- the token's name\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"chain text, -- the chain that the token resides\",\n \"price double precision, -- the current price of the token\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days\",\n \"highest_price_24h double precision, -- the highest price of the token in 24 hours\",\n \"lowest_price_24h double precision, -- the lowest price of the token in 24 hours\",\n \"market_cap double precision, -- the market cap of the token\",\n \"market_cap_rank bigint, -- the rank of the token market cap in desc\",\n \"market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours\",\n \"total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX)\", \n \"narrative text, -- the category or narrative of the token\",\n \"trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (coin_id, chain));\",\n\n \"CREATE TABLE token_dexpool_info (\",\n \"pair_address character varying(512) NOT NULL, -- the id of dexpool\",\n \"token_name character varying(100) NOT NULL, -- the name of the token in the dexpool\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"chain text, -- the chain that the dexpool resides\",\n \"price double precision, -- the current price of the token\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour\",\n \"price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours\",\n \"makers_24h double precision, -- the makers of the dex pool in 24 hours\",\n \"volume_24h double precision, -- the trade volume of the dex pool in 24 hours\",\n \"liquidity double precision, -- the liquidity of the dex pool\",\n \"market_cap double precision, -- the market cap of the token\",\n \"trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (pair_address, chain);\"\n\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n \"CREATE TABLE smart_money_profit (\",\n \"address character varying(100) NOT NULL, -- the user's address\",\n \"rank INT, -- the rank of the address in trade performance, value 1 expresses the best address.\",\n \"profit numeric(38,6), -- the profit user made in a month\",\n \"roi numeric(38,2), -- the roi of the user in a month\",\n \"realized_ratio numeric(38,2), -- the percentage of the user's realized profit\",\n \"most_profit_token character varying(100), -- the token symbol of the user's most profitable trade\",\n \"last_trade_time character varying(100), -- the last trade time of the user\",\n \"chain character varying(100), -- the chain that the address resides\",\n \"PRIMARY KEY (address, chain));\",\n\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n"} {"conversations": [{"role": "user", "content": "Count the number of law firms founded in each decade. Show the decade (e.g., 1990s, 2000s) and the count."}, {"role": "assistant", "content": "SELECT CONCAT(FLOOR(EXTRACT(YEAR FROM founded_date) / 10) * 10, 's') AS decade, COUNT(*) AS firm_count FROM law_firms WHERE founded_date IS NOT NULL GROUP BY decade ORDER BY decade;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.documents ( document_id text PRIMARY KEY, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version int, description text )\n"} {"conversations": [{"role": "user", "content": "Provide a list of all vehicles and the total quantity of fuel refueled for each vehicle."}, {"role": "assistant", "content": "SELECT T1.license_plate, sum(T2.quantity) FROM transportation.vehicles AS T1 JOIN transportation.fuel_logs AS T2 ON T1.vehicle_id = T2.vehicle_id GROUP BY T1.license_plate"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.trips ( trip_id text PRIMARY KEY, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count int, cargo_manifest_id text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text PRIMARY KEY, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading int, location_id text )\nCREATE TABLE transportation.passengers ( passenger_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Find users who have never followed anyone but have created at least 5 posts. Return user_id and post_count."}, {"role": "assistant", "content": "SELECT u.user_id, COUNT(p.post_id) AS post_count\nFROM social_media.users u\nLEFT JOIN social_media.posts p ON u.user_id = p.user_id\nWHERE NOT EXISTS (\n SELECT 1 FROM social_media.follows f WHERE f.follower_user_id = u.user_id\n)\nGROUP BY u.user_id\nHAVING COUNT(p.post_id) >= 5;"}, {"role": "user", "content": "I want to see their usernames instead of user_ids."}, {"role": "assistant", "content": "SELECT u.username, COUNT(p.post_id) AS post_count\nFROM social_media.users u\nLEFT JOIN social_media.posts p ON u.user_id = p.user_id\nWHERE NOT EXISTS (\n SELECT 1 FROM social_media.follows f WHERE f.follower_user_id = u.user_id\n)\nGROUP BY u.username\nHAVING COUNT(p.post_id) >= 5;"}, {"role": "user", "content": "Also include the timestamp of their oldest post as first_post_time."}, {"role": "assistant", "content": "SELECT u.username,\n COUNT(p.post_id) AS post_count,\n MIN(p.created_at) AS first_post_time\nFROM social_media.users u\nLEFT JOIN social_media.posts p ON u.user_id = p.user_id\nWHERE NOT EXISTS (\n SELECT 1 FROM social_media.follows f WHERE f.follower_user_id = u.user_id\n)\nGROUP BY u.username\nHAVING COUNT(p.post_id) >= 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users ( user_id 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.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.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 pairs of tokens (show token_id for both) that share the same contract address, excluding pairs where the token_id is the same."}, {"role": "assistant", "content": "SELECT t1.token_id AS token_id1, t2.token_id AS token_id2, t1.contract_address FROM web3.tokens AS t1 JOIN web3.tokens AS t2 ON t1.contract_address = t2.contract_address WHERE t1.token_id < t2.token_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, contract_address character varying(128) NOT NULL, token_name character varying(128) NOT NULL, token_symbol character varying(32) NOT NULL, decimals integer NOT NULL, total_supply numeric(38,14) NOT NULL, PRIMARY KEY (token_id) )\n"} {"conversations": [{"role": "user", "content": "For each Avalanche token tick, calculate the total transfer volume and transaction count over the past 7 days using token_activities_avalanche. Include the token tick, total_volume, and tx_count."}, {"role": "assistant", "content": "SELECT\n tick,\n SUM(amt) AS total_volume,\n COUNT(*) AS tx_count\nFROM token_activities_avalanche\nWHERE block_timestamp >= CURRENT_DATE - INTERVAL '7 days'\nGROUP BY tick;"}, {"role": "user", "content": "Also include the creator address from token_info for each tick, and filter where total_volume > 1000 and creator starts with '0x1'."}, {"role": "assistant", "content": "SELECT\n a.tick,\n SUM(a.amt) AS total_volume,\n COUNT(*) AS tx_count,\n i.creator\nFROM token_activities_avalanche a\nJOIN token_info i\n ON a.tick = i.tick\nWHERE a.block_timestamp >= CURRENT_DATE - INTERVAL '7 days'\nGROUP BY a.tick, i.creator\nHAVING SUM(a.amt) > 1000\n AND i.creator LIKE '0x1%';"}, {"role": "user", "content": "Sort the results by total_volume descending and limit to the top 5 tokens."}, {"role": "assistant", "content": "SELECT\n a.tick,\n SUM(a.amt) AS total_volume,\n COUNT(*) AS tx_count,\n i.creator\nFROM token_activities_avalanche a\nJOIN token_info i\n ON a.tick = i.tick\nWHERE a.block_timestamp >= CURRENT_DATE - INTERVAL '7 days'\nGROUP BY a.tick, i.creator\nHAVING SUM(a.amt) > 1000\n AND i.creator LIKE '0x1%'\nORDER BY total_volume DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number / 7200))\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\n"} {"conversations": [{"role": "user", "content": "Show me all policies that expired in the last 60 days, along with their product IDs and premium amounts."}, {"role": "assistant", "content": "SELECT policy_id, product_id, premium_amount, end_date FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' ORDER BY end_date DESC;"}, {"role": "user", "content": "Now include only policies that had a deductible of $1000 or more."}, {"role": "assistant", "content": "SELECT policy_id, product_id, premium_amount, deductible, end_date FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND deductible >= 1000 ORDER BY end_date DESC;"}, {"role": "user", "content": "I also want to see the count of such expired policies per product ID."}, {"role": "assistant", "content": "SELECT product_id, COUNT(*) AS policy_count FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND deductible >= 1000 GROUP BY product_id ORDER BY policy_count DESC;"}, {"role": "user", "content": "Finally, show me the average premium amount for these expired high-deductible policies grouped by product ID."}, {"role": "assistant", "content": "SELECT product_id, AVG(premium_amount) AS average_premium FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND deductible >= 1000 GROUP BY product_id ORDER BY average_premium DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\n"} {"conversations": [{"role": "user", "content": "Count the total number of chronic diagnoses for each code_type."}, {"role": "assistant", "content": "SELECT\n code_type,\n COUNT(*) AS chronic_diagnosis_count\nFROM healthcare.diagnoses\nWHERE is_chronic = TRUE\nGROUP BY code_type;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )\nCREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\n"} {"conversations": [{"role": "user", "content": "Count how many fundraising rounds each project has. Show project_name and round_count."}, {"role": "assistant", "content": "SELECT\n project_name,\n COUNT(*) AS round_count\nFROM project_fundraising_record\nGROUP BY project_name;"}, {"role": "user", "content": "Also filter to include only projects with more than 3 rounds and order by round_count descending."}, {"role": "assistant", "content": "SELECT\n project_name,\n COUNT(*) AS round_count\nFROM project_fundraising_record\nGROUP BY project_name\nHAVING COUNT(*) > 3\nORDER BY round_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 need to identify pairs of verified documents submitted by the same citizen. For each pair, display the citizen_id, the earlier document_id with its verification timestamp, and the later document_id with its verification timestamp."}, {"role": "assistant", "content": "SELECT\n d1.citizen_id,\n d1.document_id AS earlier_document_id,\n d1.verification_timestamp AS earlier_verification,\n d2.document_id AS later_document_id,\n d2.verification_timestamp AS later_verification\nFROM government_services.documents d1\nJOIN government_services.documents d2\n ON d1.citizen_id = d2.citizen_id\n AND d1.verification_timestamp < d2.verification_timestamp\nWHERE d1.verification_status = 'Verified'\n AND d2.verification_status = 'Verified';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, document_type character varying(100) NOT NULL, file_reference text NOT NULL, upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', verified_by_employee_id character varying(64), verification_timestamp timestamp, PRIMARY KEY (document_id) )\n"} {"conversations": [{"role": "user", "content": "Show the full names and contact emails of all citizens who have applied for services with a standard fee greater than 100."}, {"role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS full_name, c.contact_email\nFROM government_services.citizens c\nJOIN government_services.services s ON c.citizen_id IS NOT NULL -- Replace with actual application linking table if exists\nWHERE s.standard_fee > 100;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.services ( service_id.text, agency_id.text, service_name.text, description.text, category.text, eligibility_criteria.text, standard_fee.numeric, average_processing_time_days.integer, is_active.boolean, online_application_url.text )\n"} {"conversations": [{"role": "user", "content": "List all time entries for lawyers specializing in 'Criminal Law'. Show the entry ID, the date worked, hours spent, and the first and last name of the lawyer who performed the work."}, {"role": "assistant", "content": "SELECT te.entry_id, te.date_worked, te.hours_spent, l.first_name, l.last_name FROM legal_services.time_entries te JOIN legal_services.lawyers l ON te.lawyer_id = l.lawyer_id WHERE l.specialization = 'Criminal Law';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\nCREATE TABLE legal_services.time_entries (\n entry_id character varying(64) NOT NULL, -- unique identifier for the time entry\n case_id character varying(64) NOT NULL, -- FK to cases table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (who performed the work)\n date_worked date NOT NULL, -- date the work was performed\n hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), -- duration of work in hours (e.g., 1.5 for 1h 30m)\n billing_rate numeric(10, 2) NOT NULL, -- hourly rate applied for this entry\n description text NOT NULL, -- detailed description of the work performed\n is_billable boolean DEFAULT true, -- whether this time entry is billable to the client\n is_billed boolean DEFAULT false, -- whether this entry has been included in an invoice\n invoice_id character varying(64), -- FK to invoices table (once billed)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the entry was recorded\n PRIMARY KEY (entry_id)\n)\nCREATE TABLE legal_services.invoices (\n invoice_id character varying(64) NOT NULL, -- unique identifier for the invoice\n invoice_number character varying(100) UNIQUE NOT NULL, -- user-facing invoice number\n client_id character varying(64) NOT NULL, -- FK to clients table\n case_id character varying(64), -- FK to cases table (optional, could be general retainer)\n issue_date date NOT NULL, -- date the invoice was generated\n due_date date NOT NULL, -- date the payment is due\n total_amount numeric(12, 2) NOT NULL, -- total amount due on the invoice\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n status character varying(50) NOT NULL, -- e.g., Draft, Sent, Paid, Partially Paid, Overdue, Void\n payment_date timestamp, -- date the invoice was fully paid (nullable)\n notes text, -- additional notes or terms on the invoice\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (invoice_id)\n)\n"} {"conversations": [{"role": "user", "content": "Retrieve each passenger's full name, their email, booking status, and the name of the origin location for all bookings."}, {"role": "assistant", "content": "SELECT p.first_name || ' ' || p.last_name AS full_name, p.email, b.status, l.name AS origin_location_name\nFROM transportation.bookings b\nJOIN transportation.passengers p ON b.passenger_id = p.passenger_id\nJOIN transportation.trips t ON b.trip_id = t.trip_id\nJOIN transportation.locations l ON t.origin_location_id = l.location_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.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) )\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.passengers ( passenger_id character varying(64) NOT NULL, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32) UNIQUE, date_of_birth date, loyalty_program_id character varying(64), created_at timestamp with time zone NOT NULL, PRIMARY KEY (passenger_id) )\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n"} {"conversations": [{"role": "user", "content": "Identify all instances where a vehicle's odometer_reading increased by more than 500 miles between two consecutive fuel log entries."}, {"role": "assistant", "content": "SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n a.log_timestamp AS previous_time,\n b.log_timestamp AS next_time,\n b.odometer_reading - a.odometer_reading AS mile_increase\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500;"}, {"role": "user", "content": "Now restrict these increases to those where the time difference between entries is less than 7 days."}, {"role": "assistant", "content": "SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n a.log_timestamp AS previous_time,\n b.log_timestamp AS next_time,\n b.odometer_reading - a.odometer_reading AS mile_increase,\n EXTRACT(epoch FROM (b.log_timestamp - a.log_timestamp))/3600 AS hours_diff\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500\n AND b.log_timestamp - a.log_timestamp < INTERVAL '7 days';"}, {"role": "user", "content": "Also include both the mile increase and the time difference in hours in the final output columns."}, {"role": "assistant", "content": "SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n b.odometer_reading - a.odometer_reading AS mile_increase,\n EXTRACT(epoch FROM (b.log_timestamp - a.log_timestamp))/3600 AS hours_difference\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500\n AND b.log_timestamp - a.log_timestamp < INTERVAL '7 days';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\n"} {"conversations": [{"role": "user", "content": "List properties and the average base rate of their room types."}, {"role": "assistant", "content": "SELECT T1.property_name , AVG(T2.base_rate) FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id GROUP BY T1.property_name"}, {"role": "user", "content": "Filter to only show properties where the average base rate is above 250."}, {"role": "assistant", "content": "SELECT T1.property_name , AVG(T2.base_rate) FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id GROUP BY T1.property_name HAVING AVG(T2.base_rate) > 250"}, {"role": "user", "content": "Also, only include properties in 'New York' or 'Florida' and order by average base rate descending."}, {"role": "assistant", "content": "SELECT T1.property_name , AVG(T2.base_rate) AS avg_base_rate FROM hospitality_technology.properties AS T1 JOIN hospitality_technology.room_types AS T2 ON T1.property_id = T2.property_id WHERE T1.state IN ('New York', 'Florida') GROUP BY T1.property_name HAVING AVG(T2.base_rate) > 250 ORDER BY avg_base_rate DESC"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 developer names and their founded years, ordered from newest to oldest."}, {"role": "assistant", "content": "SELECT name, founded_year FROM gaming_technology.developers ORDER BY founded_year DESC;"}, {"role": "user", "content": "Show only developers founded after 2015."}, {"role": "assistant", "content": "SELECT name, founded_year FROM gaming_technology.developers WHERE founded_year > 2015 ORDER BY founded_year DESC;"}, {"role": "user", "content": "Can you also include the country of each developer?"}, {"role": "assistant", "content": "SELECT name, country, founded_year FROM gaming_technology.developers WHERE founded_year > 2015 ORDER BY founded_year DESC;"}, {"role": "user", "content": "Only show developers from European countries."}, {"role": "assistant", "content": "SELECT name, country, founded_year FROM gaming_technology.developers WHERE founded_year > 2015 AND country IN ('France','Germany','Spain','Italy','United Kingdom','Netherlands','Sweden','Switzerland','Norway','Finland','Denmark','Belgium','Austria','Ireland','Portugal','Greece','Poland','Hungary','Czech Republic','Romania','Bulgaria','Croatia','Slovakia','Slovenia','Estonia','Latvia','Lithuania','Luxembourg','Iceland','Malta','Cyprus') ORDER BY founded_year DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\n"} {"conversations": [{"role": "user", "content": "For each developer, can you find the next developer in the same country using a self join, returning developer_ids and names?"}, {"role": "assistant", "content": "SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN developers d2\n ON d1.country = d2.country\n AND d2.founded_year > d1.founded_year;"}, {"role": "user", "content": "Exclude developers who don't have a next developer, and ensure we only pick the closest next by founded_year."}, {"role": "assistant", "content": "SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN LATERAL (\n SELECT d2.developer_id, d2.name, d2.founded_year\n FROM developers d2\n WHERE d2.country = d1.country\n AND d2.founded_year > d1.founded_year\n ORDER BY d2.founded_year ASC\n LIMIT 1\n) d2 ON true;"}, {"role": "user", "content": "Finally, only include pairs where the difference in founded years is at most 5 years."}, {"role": "assistant", "content": "SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN LATERAL (\n SELECT d2.developer_id, d2.name, d2.founded_year\n FROM developers d2\n WHERE d2.country = d1.country\n AND d2.founded_year > d1.founded_year\n ORDER BY d2.founded_year ASC\n LIMIT 1\n) d2 ON true\nWHERE (d2.founded_year - d1.founded_year) <= 5\nORDER BY d1.developer_id, years_diff ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\n"} {"conversations": [{"role": "user", "content": "For each claim, show the corresponding product_type of the insurance product for the related policy."}, {"role": "assistant", "content": "SELECT cl.claim_id, ip.product_type\nFROM insurance.claims cl\nJOIN insurance.policies p ON cl.policy_id = p.policy_id\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id;"}, {"role": "user", "content": "Sorry, there is no policies table, I got an error. Can you try joining claims to insurance_products another way?"}, {"role": "assistant", "content": "-- Unable to join directly since there is no 'policies' table connecting claims to insurance_products. If policy_id equals product_id, you may try:\nSELECT claim_id, policy_id, product_type\nFROM insurance.claims\nJOIN insurance.insurance_products ON claims.policy_id = insurance_products.product_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address_line1.text, address_line2.text, city.text, state.text, zip_code.text, country.text, phone_number.text, email.text, created_at.timestamp, updated_at.timestamp, status.text )\nCREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )\nCREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )\n"} {"conversations": [{"role": "user", "content": "Show me the 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 SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.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": "I’d like to find all pairs of securities that belong to the same sector."}, {"role": "assistant", "content": "SELECT a.security_id, a.ticker_symbol, b.security_id AS pair_security_id, b.ticker_symbol AS pair_ticker_symbol, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b ON a.sector = b.sector\nWHERE a.security_id < b.security_id;"}, {"role": "user", "content": "Actually, only include pairs where the two securities are listed on different exchanges."}, {"role": "assistant", "content": "SELECT a.security_id, a.ticker_symbol, a.exchange AS exchange_a, b.security_id AS pair_security_id, b.ticker_symbol AS pair_ticker_symbol, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b ON a.sector = b.sector AND a.security_id < b.security_id\nWHERE a.exchange <> b.exchange;"}, {"role": "user", "content": "Also, I want the results sorted by sector, then by exchange_a."}, {"role": "assistant", "content": "SELECT a.security_id, a.ticker_symbol, a.exchange AS exchange_a, b.security_id AS pair_security_id, b.ticker_symbol AS pair_ticker_symbol, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b ON a.sector = b.sector AND a.security_id < b.security_id\nWHERE a.exchange <> b.exchange\nORDER BY a.sector, a.exchange;"}, {"role": "user", "content": "One more thing: include both exchanges in the ORDER BY so that within each sector it’s sorted by exchange_a then exchange_b."}, {"role": "assistant", "content": "SELECT a.security_id, a.ticker_symbol, a.exchange AS exchange_a, b.security_id AS pair_security_id, b.ticker_symbol AS pair_ticker_symbol, b.exchange AS exchange_b, a.sector\nFROM financial_services.securities a\nJOIN financial_services.securities b ON a.sector = b.sector AND a.security_id < b.security_id\nWHERE a.exchange <> b.exchange\nORDER BY a.sector, a.exchange, b.exchange;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.securities ( 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 the file name and document type for all documents uploaded by the user with ID 'agent456'."}, {"role": "assistant", "content": "SELECT file_name, document_type FROM insurance.claim_documents WHERE uploaded_by = 'agent456';"}, {"role": "user", "content": "Can you also include the file size in bytes and only show documents uploaded in the year 2023?"}, {"role": "assistant", "content": "SELECT file_name, document_type, file_size_bytes FROM insurance.claim_documents WHERE uploaded_by = 'agent456' AND uploaded_at >= '2023-01-01' AND uploaded_at < '2024-01-01';"}, {"role": "user", "content": "Actually, just show the document ID, file name, and uploaded time for all documents uploaded by 'agent456' before 2024, ordered by upload time descending."}, {"role": "assistant", "content": "SELECT document_id, file_name, uploaded_at FROM insurance.claim_documents WHERE uploaded_by = 'agent456' AND uploaded_at < '2024-01-01' ORDER BY uploaded_at DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\n"} {"conversations": [{"role": "user", "content": "Find all pairs of different insurance records that share the same group_number, and show group_number, the patient_insurance_id of both records, and their corresponding patient_ids."}, {"role": "assistant", "content": "SELECT a.group_number,\n a.patient_insurance_id AS pi_id1,\n a.patient_id AS patient1_id,\n b.patient_insurance_id AS pi_id2,\n b.patient_id AS patient2_id\nFROM healthcare.patient_insurance a\nJOIN healthcare.patient_insurance b\n ON a.group_number = b.group_number\n AND a.patient_insurance_id < b.patient_insurance_id\nWHERE a.group_number IS NOT NULL;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n"} {"conversations": [{"role": "user", "content": "List the name, address line 1, and city for all locations located in California."}, {"role": "assistant", "content": "SELECT name, address_line1, city FROM transportation.locations WHERE state_province = 'CA'"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.locations ( location_id.text, name.text, type.text, address_line1.text, city.text, state_province.text, postal_code.text, country.text, latitude.numeric, longitude.numeric, timezone.text )\n"} {"conversations": [{"role": "user", "content": "Find all wallet addresses that don't have an associated user_id."}, {"role": "assistant", "content": "SELECT address_id FROM blockchain.wallets WHERE user_id IS NULL;"}, {"role": "user", "content": "Now show me these addresses along with their private_key and balance."}, {"role": "assistant", "content": "SELECT w.address_id, w.private_key, a.balance FROM blockchain.wallets w JOIN blockchain.addresses a ON w.address_id = a.address_id WHERE w.user_id IS NULL;"}, {"role": "user", "content": "This query is missing some addresses that exist in the addresses table but not in wallets. Can you modify it to include all addresses without user_id associations?"}, {"role": "assistant", "content": "SELECT a.address_id, w.private_key, a.balance FROM blockchain.addresses a LEFT JOIN blockchain.wallets w ON a.address_id = w.address_id WHERE w.user_id IS NULL OR w.user_id = '';"}, {"role": "user", "content": "Now order the results by balance in descending order."}, {"role": "assistant", "content": "SELECT a.address_id, w.private_key, a.balance FROM blockchain.addresses a LEFT JOIN blockchain.wallets w ON a.address_id = w.address_id WHERE w.user_id IS NULL OR w.user_id = '' ORDER BY a.balance DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.addresses ( address_id.text, public_key.text, balance.numeric )\nCREATE TABLE blockchain.wallets ( wallet_id text, user_id text, address_id text, private_key text )\n"} {"conversations": [{"role": "user", "content": "For each event, display its event_id, the event_id of the previous event in the same transaction (if any), and the log_index of both events."}, {"role": "assistant", "content": "SELECT curr.event_id AS current_event_id,\n prev.event_id AS previous_event_id,\n curr.log_index AS current_log_index,\n prev.log_index AS previous_log_index,\n curr.transaction_id\nFROM web3.events curr\nLEFT JOIN web3.events prev\n ON curr.transaction_id = prev.transaction_id\n AND curr.log_index = prev.log_index + 1;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.events ( event_id character varying(64) NOT NULL, contract_id character varying(64) NOT NULL, event_name character varying(128) NOT NULL, data text NOT NULL, emitted_at timestamp NOT NULL, transaction_id character varying(64) NOT NULL, log_index integer NOT NULL, PRIMARY KEY (event_id) )\n"} {"conversations": [{"role": "user", "content": "Show all routes including their number, type, and description."}, {"role": "assistant", "content": "SELECT route_number , type , description FROM transportation.routes"}, {"role": "user", "content": "Only show routes of type 'City Bus'."}, {"role": "assistant", "content": "SELECT route_number , type , description FROM transportation.routes WHERE type = 'City Bus'"}, {"role": "user", "content": "For these 'City Bus' routes, include the origin and destination city names."}, {"role": "assistant", "content": "SELECT T1.route_number , T1.type , T1.description , T2.city AS origin_city , T3.city AS destination_city FROM transportation.routes AS T1 JOIN transportation.locations AS T2 ON T1.origin_location_id = T2.location_id JOIN transportation.locations AS T3 ON T1.destination_location_id = T3.location_id WHERE T1.type = 'City Bus'"}, {"role": "user", "content": "Order the results by route number in ascending order and limit to the first 10."}, {"role": "assistant", "content": "SELECT T1.route_number , T1.type , T1.description , T2.city AS origin_city , T3.city AS destination_city FROM transportation.routes AS T1 JOIN transportation.locations AS T2 ON T1.origin_location_id = T2.location_id JOIN transportation.locations AS T3 ON T1.destination_location_id = T3.location_id WHERE T1.type = 'City Bus' ORDER BY T1.route_number ASC LIMIT 10"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.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.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": "Find all medical records where the recorded temperature in vitals is above 38°C. Return record_id, patient_id, record_date, and the temperature."}, {"role": "assistant", "content": "SELECT\n record_id,\n patient_id,\n record_date,\n (vitals->>'temp')::numeric AS temperature\nFROM healthcare.medical_records\nWHERE (vitals->>'temp')::numeric > 38;"}, {"role": "user", "content": "Also include only those entries created after January 1st, 2024, and only if the assessment contains the word 'infection'."}, {"role": "assistant", "content": "SELECT\n record_id,\n patient_id,\n record_date,\n (vitals->>'temp')::numeric AS temperature\nFROM healthcare.medical_records\nWHERE (vitals->>'temp')::numeric > 38\n AND record_date > '2024-01-01'\n AND assessment ILIKE '%infection%';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\n"} {"conversations": [{"role": "user", "content": "How many unique email domains are there among all registered users?"}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT SUBSTRING(email FROM '@(.*)$')) AS unique_domains FROM blockchain.users;"}, {"role": "user", "content": "Can you list these domains along with the count of users for each domain?"}, {"role": "assistant", "content": "SELECT SUBSTRING(email FROM '@(.*)$') AS domain, COUNT(*) AS user_count FROM blockchain.users GROUP BY domain;"}, {"role": "user", "content": "Now show only domains that have more than 10 users."}, {"role": "assistant", "content": "SELECT SUBSTRING(email FROM '@(.*)$') AS domain, COUNT(*) AS user_count FROM blockchain.users GROUP BY domain HAVING COUNT(*) > 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) )\n"} {"conversations": [{"role": "user", "content": "List the content and creation time of posts made by users who are following user 'U200'."}, {"role": "assistant", "content": "SELECT T1.content, T1.created_at FROM social_media.posts AS T1 JOIN social_media.follows AS T2 ON T1.user_id = T2.follower_user_id WHERE T2.following_user_id = 'U200';"}, {"role": "user", "content": "Filter the posts to only include those where the content mentions 'announcement'."}, {"role": "assistant", "content": "SELECT T1.content, T1.created_at FROM social_media.posts AS T1 JOIN social_media.follows AS T2 ON T1.user_id = T2.follower_user_id WHERE T2.following_user_id = 'U200' AND T1.content ILIKE '%announcement%';"}, {"role": "user", "content": "And only include posts created before July 1, 2024."}, {"role": "assistant", "content": "SELECT T1.content, T1.created_at FROM social_media.posts AS T1 JOIN social_media.follows AS T2 ON T1.user_id = T2.follower_user_id WHERE T2.following_user_id = 'U200' AND T1.content ILIKE '%announcement%' AND T1.created_at < '2024-07-01';"}, {"role": "user", "content": "Order the results by creation time ascending and limit to the first 10 posts."}, {"role": "assistant", "content": "SELECT T1.content, T1.created_at FROM social_media.posts AS T1 JOIN social_media.follows AS T2 ON T1.user_id = T2.follower_user_id WHERE T2.following_user_id = 'U200' AND T1.content ILIKE '%announcement%' AND T1.created_at < '2024-07-01' ORDER BY T1.created_at ASC LIMIT 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "How many likes were given to comments in June 2024?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS comment_likes_count\nFROM social_media.likes\nWHERE comment_id IS NOT NULL \n AND DATE_TRUNC('month', created_at) = '2024-06-01';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.comments ( comment_id 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.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.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 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) )\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 the full name and bar number of all lawyers who were hired before 2015."}, {"role": "assistant", "content": "SELECT first_name || ' ' || last_name AS lawyer_full_name, bar_number\nFROM legal_services.lawyers\nWHERE hire_date < '2015-01-01';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) )\nCREATE TABLE legal_services.lawyers ( lawyer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, bar_number character varying(64) UNIQUE NOT NULL, firm_id character varying(64), email character varying(128) UNIQUE NOT NULL, phone character varying(32), specialization text, hire_date timestamp NOT NULL, is_partner boolean DEFAULT false, PRIMARY KEY (lawyer_id) )\nCREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )\nCREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) )\n"} {"conversations": [{"role": "user", "content": "For each block number, show the highest transaction value and the status of the transaction with the highest value."}, {"role": "assistant", "content": "SELECT t.block_number, t.value AS max_value, t.status\nFROM web3.transactions t\nJOIN (\n SELECT block_number, MAX(value) AS max_value\n FROM web3.transactions\n GROUP BY block_number\n) mv\n ON t.block_number = mv.block_number AND t.value = mv.max_value;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.transactions ( transaction_id.text, from_address.text, to_address.text, value.numeric, gas_used.integer, gas_price.numeric, block_number.integer, timestamp.timestamp, input_data.text, status.text, nonce.integer )\n"} {"conversations": [{"role": "user", "content": "Find all users who registered with a Yahoo email address, along with their registration dates."}, {"role": "assistant", "content": "SELECT user_id, username, email, password_hash FROM blockchain.users WHERE email LIKE '%@yahoo.com';"}, {"role": "user", "content": "This query doesn't show registration dates. Can you modify it to include the registration date?"}, {"role": "assistant", "content": "I notice the users table doesn't have a registration date column. Would you like me to show other available information from the users table?"}, {"role": "user", "content": "Then just show me the count of Yahoo email users instead."}, {"role": "assistant", "content": "SELECT COUNT(*) as yahoo_user_count FROM blockchain.users WHERE email LIKE '%@yahoo.com';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer )\nCREATE TABLE blockchain.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n block_id character varying(64) NOT NULL, -- identifier of the block containing the transaction\n sender_address character varying(128) NOT NULL, -- address of the sender\n receiver_address character varying(128) NOT NULL, -- address of the receiver\n amount numeric(38,14) NOT NULL, -- amount transferred\n timestamp timestamp NOT NULL, -- time when the transaction was created\n signature text NOT NULL, -- digital signature of the transaction\n PRIMARY KEY (transaction_id)\n)\nCREATE TABLE blockchain.addresses ( address_id text PRIMARY KEY, public_key text, balance numeric )\nCREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) )\n"} {"conversations": [{"role": "user", "content": "Provide a count of citizens registered per calendar year."}, {"role": "assistant", "content": "SELECT CAST(EXTRACT(YEAR FROM registration_date) AS INTEGER) AS registration_year, COUNT(*) AS citizen_count FROM government_services.citizens GROUP BY 1 ORDER BY 1;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\n"} {"conversations": [{"role": "user", "content": "List pairs of citizens who share the same email domain."}, {"role": "assistant", "content": "SELECT c1.first_name AS first1,\n c1.last_name AS last1,\n c2.first_name AS first2,\n c2.last_name AS last2,\n SPLIT_PART(c1.contact_email, '@', 2) AS domain\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON SPLIT_PART(c1.contact_email, '@', 2) = SPLIT_PART(c2.contact_email, '@', 2)\n AND c1.citizen_id < c2.citizen_id\nWHERE c1.contact_email IS NOT NULL\n AND c2.contact_email IS NOT NULL;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me all insurance plans where the website includes 'secure'."}, {"role": "assistant", "content": "SELECT * FROM healthcare.insurance_plans WHERE website ILIKE '%secure%';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.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.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 all components associated with a specific supplier. Can you help with that?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE"}, {"role": "user", "content": "Can you also show me the material ID for each of these components?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id"}, {"role": "user", "content": "What if I want to exclude components with a specific material ID?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id\nIF HGET component: material_id != 'mat:TI64' THEN INCLUDE"}, {"role": "user", "content": "Can you add the component name to the result as well?"}, {"role": "assistant", "content": "HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id\nIF HGET component: material_id != 'mat:TI64' THEN INCLUDE\nHGET component: component_name"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nUse Hashes. Key pattern: 'component:'. Example: HSET component:LGSTRUT01 part_number \"PN-5521-A\" component_name \"Landing Gear Strut\" material_id \"mat:TI64\" supplier_id \"sup:ACME_AERO\" ... Consider Sets for reverse lookups (e.g., 'material_components:' -> Set).\n"} {"conversations": [{"role": "user", "content": "I need to compare consecutive daily close_prices for each security to find when the close_price increased compared to the previous day."}, {"role": "assistant", "content": "SELECT a.security_id, b.data_timestamp AS prev_date, b.close_price AS prev_close, a.data_timestamp AS curr_date, a.close_price AS curr_close\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nWHERE a.close_price > b.close_price;"}, {"role": "user", "content": "Now, restrict this to only securities whose average volume over the past 30 days exceeds 1,000,000."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id, b.data_timestamp AS prev_date, b.close_price AS prev_close, a.data_timestamp AS curr_date, a.close_price AS curr_close\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE a.close_price > b.close_price;"}, {"role": "user", "content": "Also, only include those increases where the percentage change between days is greater than 2%."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id,\n b.data_timestamp AS prev_date,\n b.close_price AS prev_close,\n a.data_timestamp AS curr_date,\n a.close_price AS curr_close,\n ROUND((a.close_price - b.close_price) / b.close_price * 100, 2) AS pct_change\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE (a.close_price - b.close_price) / b.close_price * 100 > 2;"}, {"role": "user", "content": "Finally, add the adjusted_close_price for both current and previous days to the result."}, {"role": "assistant", "content": "WITH high_vol AS (\n SELECT security_id\n FROM financial_services.market_data\n WHERE data_timestamp >= NOW() - INTERVAL '30 days'\n GROUP BY security_id\n HAVING AVG(volume) > 1000000\n)\nSELECT a.security_id,\n b.data_timestamp AS prev_date,\n b.close_price AS prev_close,\n b.adjusted_close_price AS prev_adj_close,\n a.data_timestamp AS curr_date,\n a.close_price AS curr_close,\n a.adjusted_close_price AS curr_adj_close,\n ROUND((a.close_price - b.close_price) / b.close_price * 100, 2) AS pct_change\nFROM financial_services.market_data a\nJOIN financial_services.market_data b\n ON a.security_id = b.security_id\n AND CAST(a.data_timestamp AS date) = CAST(b.data_timestamp + INTERVAL '1 day' AS date)\nJOIN high_vol h\n ON a.security_id = h.security_id\nWHERE (a.close_price - b.close_price) / b.close_price * 100 > 2;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.market_data ( data_point_id bigint, security_id text, data_timestamp timestamp, open_price numeric, high_price numeric, low_price numeric, close_price numeric, adjusted_close_price numeric, volume bigint, source text )\n"} {"conversations": [{"role": "user", "content": "Find the contract address and name for all NFT collections listed on the 'Ethereum' blockchain."}, {"role": "assistant", "content": "SELECT contract_address, name FROM nft_collections WHERE blockchain = 'Ethereum'"}, {"role": "user", "content": "For these collections, can you show the count of unique wallet addresses holding NFTs in each collection by joining with nft_holders?"}, {"role": "assistant", "content": "SELECT T1.contract_address, T1.name, COUNT(DISTINCT T2.wallet_address) AS unique_holder_count FROM nft_collections AS T1 JOIN nft_holders AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'Ethereum' GROUP BY T1.contract_address, T1.name"}, {"role": "user", "content": "Please filter the results to only include collections that have more than 100 unique holders."}, {"role": "assistant", "content": "SELECT T1.contract_address, T1.name, COUNT(DISTINCT T2.wallet_address) AS unique_holder_count FROM nft_collections AS T1 JOIN nft_holders AS T2 ON T1.contract_address = T2.contract_address WHERE T1.blockchain = 'Ethereum' GROUP BY T1.contract_address, T1.name HAVING COUNT(DISTINCT T2.wallet_address) > 100"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )\n"} {"conversations": [{"role": "user", "content": "Show me a list of all properties along with their average overall review rating."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, AVG(r.rating_overall) AS avg_rating\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.reviews r ON p.property_id = r.property_id\nGROUP BY p.property_id, p.property_name;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.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 the total value and count of transactions for each status, ordered by total value descending."}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS transaction_count, SUM(value) AS total_value\nFROM web3.transactions\nGROUP BY status\nORDER BY total_value DESC;"}, {"role": "user", "content": "Actually, can you also include the average value per transaction for each status?"}, {"role": "assistant", "content": "SELECT status, COUNT(*) AS transaction_count, SUM(value) AS total_value, AVG(value) AS avg_value\nFROM web3.transactions\nGROUP BY status\nORDER BY total_value DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.transactions ( transaction_id.text, from_address.text, to_address.text, value.numeric, gas_used.integer, gas_price.numeric, block_number.integer, timestamp.timestamp, input_data.text, status.text, nonce.integer )\n"} {"conversations": [{"role": "user", "content": "Provide a count of how many peers were last seen on each distinct day recorded in the system."}, {"role": "assistant", "content": "SELECT DATE(last_seen), COUNT(*) FROM trading_platform.peers GROUP BY DATE(last_seen) ORDER BY DATE(last_seen);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\nCREATE TABLE trading_platform.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id text, transaction_id text, output_index integer, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id text, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id text, ip_address text, port integer, last_seen timestamp )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text, user_id text, action text, details text, logged_at timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List the medication_name and manufacturer for all medications where the description is null or an empty string."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer FROM healthcare.medications WHERE description IS NULL OR description = '';"}, {"role": "user", "content": "Now, refine the query to only include medications whose ndc_code starts with '5'."}, {"role": "assistant", "content": "SELECT medication_name, manufacturer FROM healthcare.medications WHERE (description IS NULL OR description = '') AND ndc_code LIKE '5%';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n"} {"conversations": [{"role": "user", "content": "Give me the total number of reservations and the sum of total_amount by month for the year 2023."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', check_in_date) AS month,\n COUNT(*) AS reservation_count,\n SUM(total_amount) AS total_revenue\nFROM hospitality_technology.reservations\nWHERE EXTRACT(YEAR FROM check_in_date) = 2023\nGROUP BY DATE_TRUNC('month', check_in_date)\nORDER BY month;"}, {"role": "user", "content": "Actually, I only want reservations with status 'CheckedOut' or 'Completed'."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', check_in_date) AS month,\n COUNT(*) AS reservation_count,\n SUM(total_amount) AS total_revenue\nFROM hospitality_technology.reservations\nWHERE EXTRACT(YEAR FROM check_in_date) = 2023\n AND status IN ('CheckedOut', 'Completed')\nGROUP BY DATE_TRUNC('month', check_in_date)\nORDER BY month;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Which games have achievements where the points value is exactly 0? List the game title and the achievement name."}, {"role": "assistant", "content": "SELECT g.title AS game_title, a.name AS achievement_name\nFROM gaming_technology.achievements a\nJOIN gaming_technology.games g ON a.game_id = g.game_id\nWHERE a.points = 0;"}, {"role": "user", "content": "Show also the achievement's description and whether it is hidden."}, {"role": "assistant", "content": "SELECT g.title AS game_title, a.name AS achievement_name, a.description, a.hidden\nFROM gaming_technology.achievements a\nJOIN gaming_technology.games g ON a.game_id = g.game_id\nWHERE a.points = 0;"}, {"role": "user", "content": "Only show achievements released in games before 2020."}, {"role": "assistant", "content": "SELECT g.title AS game_title, a.name AS achievement_name, a.description, a.hidden\nFROM gaming_technology.achievements a\nJOIN gaming_technology.games g ON a.game_id = g.game_id\nWHERE a.points = 0 AND g.release_date < '2020-01-01';"}, {"role": "user", "content": "Sort the results by game_title ascending, then achievement_name ascending."}, {"role": "assistant", "content": "SELECT g.title AS game_title, a.name AS achievement_name, a.description, a.hidden\nFROM gaming_technology.achievements a\nJOIN gaming_technology.games g ON a.game_id = g.game_id\nWHERE a.points = 0 AND g.release_date < '2020-01-01'\nORDER BY g.title ASC, a.name ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory (\n inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry\n player_id uuid NOT NULL, -- FK linking to the player owning the item\n item_id uuid NOT NULL, -- FK linking to the item definition\n quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)\n acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired\n instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)\n PRIMARY KEY (inventory_id),\n -- Optional unique constraint if items are non-stackable or unique instances\n -- UNIQUE (player_id, item_id) -- Use if quantity is always 1\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)\n)\n"} {"conversations": [{"role": "user", "content": "List all agents who have been terminated, showing their full name, agency name, and termination date."}, {"role": "assistant", "content": "SELECT first_name, last_name, agency_name, termination_date\nFROM insurance.agents\nWHERE status <> 'Active';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )\n"} {"conversations": [{"role": "user", "content": "Show each citizen's first and last notification IDs based on sent_at."}, {"role": "assistant", "content": "WITH bounds AS (\n SELECT citizen_id,\n MIN(sent_at) AS first_sent,\n MAX(sent_at) AS last_sent\n FROM government_services.notifications\n GROUP BY citizen_id\n)\nSELECT n1.citizen_id,\n n1.notification_id AS first_notification_id,\n n2.notification_id AS last_notification_id\nFROM bounds b\nJOIN government_services.notifications n1\n ON n1.citizen_id = b.citizen_id\n AND n1.sent_at = b.first_sent\nJOIN government_services.notifications n2\n ON n2.citizen_id = b.citizen_id\n AND n2.sent_at = b.last_sent;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.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": "Count the number of trips for each route type."}, {"role": "assistant", "content": "SELECT R.type, COUNT(T.trip_id) FROM transportation.trips AS T JOIN transportation.routes AS R ON T.route_id = R.route_id GROUP BY R.type;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )\nCREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.passengers ( passenger_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, loyalty_program_id.text, created_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "Show the top 5 properties by average overall review rating."}, {"role": "assistant", "content": "SELECT p.property_name, AVG(r.rating_overall) AS avg_rating\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.reviews r\n ON p.property_id = r.property_id\nGROUP BY p.property_name\nORDER BY avg_rating DESC\nLIMIT 5;"}, {"role": "user", "content": "Only consider reviews that are publicly visible."}, {"role": "assistant", "content": "SELECT p.property_name, AVG(r.rating_overall) AS avg_rating\nFROM hospitality_technology.properties p\nJOIN hospitality_technology.reviews r\n ON p.property_id = r.property_id\nWHERE r.is_public = true\nGROUP BY p.property_name\nORDER BY avg_rating DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.guests (\n guest_id character varying(64) NOT NULL, -- unique identifier for the guest profile\n first_name character varying(100) NOT NULL, -- guest's first name\n last_name character varying(100) NOT NULL, -- guest's last name\n email character varying(255) UNIQUE, -- guest's email address (unique identifier?)\n phone_number character varying(30), -- guest's phone number\n date_of_birth date, -- guest's date of birth\n address_line1 character varying(255), -- guest's home address\n city character varying(100),\n state_province character varying(100),\n postal_code character varying(20),\n country_code character varying(3),\n preferences text, -- notes on guest preferences (e.g., allergies, room location)\n loyalty_member_id character varying(64) UNIQUE, -- FK to loyalty_members table\n communication_consent boolean DEFAULT true, -- consent for marketing communications\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (guest_id)\n)\nCREATE TABLE hospitality_technology.staff (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\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": "Which states have the highest number of customers? Provide the top 5 states along with their customer counts, ordered by count descending."}, {"role": "assistant", "content": "SELECT\n state,\n COUNT(*) AS customer_count\nFROM insurance.customers\nGROUP BY state\nORDER BY customer_count DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me all transactions (transaction_id, amount, transaction_type) where the transaction_type is 'Transfer' and the status is 'Completed', along with the account_id and related_account_id."}, {"role": "assistant", "content": "SELECT transaction_id, amount, transaction_type, account_id, related_account_id FROM financial_services.transactions WHERE transaction_type = 'Transfer' AND status = 'Completed';"}, {"role": "user", "content": "Now modify the query to include only transfers with amounts greater than $1,000 and sort them by transaction_date in descending order."}, {"role": "assistant", "content": "SELECT transaction_id, amount, transaction_type, account_id, related_account_id FROM financial_services.transactions WHERE transaction_type = 'Transfer' AND status = 'Completed' AND amount > 1000 ORDER BY transaction_date DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.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 )\n"} {"conversations": [{"role": "user", "content": "For each event recorded, list its ID, name, and the status and value of the transaction in which it occurred."}, {"role": "assistant", "content": "SELECT E.event_id, E.event_name, E.transaction_id, T.status, T.value FROM web3.events AS E JOIN web3.transactions AS T ON E.transaction_id = T.transaction_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\nCREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "What is the total sum of all amounts for all UTXOs in the system, regardless of whether they are spent or unspent?"}, {"role": "assistant", "content": "SELECT SUM(amount) FROM trading_platform.utxos"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp )\nCREATE TABLE trading_platform.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.assets (\n asset_id character varying(64) NOT NULL, -- unique identifier for the asset\n name character varying(128) NOT NULL, -- name of the asset\n symbol character varying(32) NOT NULL, -- symbol of the asset\n type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)\n PRIMARY KEY (asset_id)\n)\nCREATE TABLE trading_platform.utxos (\n utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO\n output_index integer NOT NULL, -- index of the output in the transaction\n address character varying(128) NOT NULL, -- address that can spend the UTXO\n amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO\n spent boolean NOT NULL, -- whether the UTXO has been spent\n PRIMARY KEY (utxo_id)\n)\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id.text, user_id.text, status.text, reviewed_at.timestamp )\nCREATE TABLE trading_platform.logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the log entry\n user_id character varying(64), -- identifier of the user associated with the log entry\n action character varying(128) NOT NULL, -- action performed\n details text NOT NULL, -- details of the action\n logged_at timestamp NOT NULL, -- time when the log entry was created\n PRIMARY KEY (log_id)\n)\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 users who have interacted with DApps, along with the count of distinct DApps they interacted with and their wallet addresses."}, {"role": "assistant", "content": "SELECT w.user_id, COUNT(DISTINCT d.dapp_id) AS dapp_count, w.address FROM trading_platform.wallets w JOIN trading_platform.dapps d ON 1=1 GROUP BY w.user_id, w.address ORDER BY dapp_count DESC LIMIT 5;"}, {"role": "user", "content": "This query doesn't properly show DApp interactions. Please modify it to correctly join with a table that records user-DApp interactions."}, {"role": "assistant", "content": "I notice there's no interaction table in the provided schema. Without a table recording user-DApp interactions, I cannot generate this query accurately. Would you like to see users who have wallets and DApps separately instead?"}, {"role": "user", "content": "You're right. Instead, show me users who have wallets but have never interacted with any DApps, along with their wallet addresses."}, {"role": "assistant", "content": "SELECT w.user_id, w.address FROM trading_platform.wallets w WHERE NOT EXISTS (SELECT 1 FROM trading_platform.dapps d WHERE 1=1) GROUP BY w.user_id, w.address;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\nCREATE TABLE trading_platform.assets ( asset_id.text, name.text, symbol.text, type.text )\nCREATE TABLE trading_platform.dapps (\n dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp\n name character varying(128) NOT NULL, -- name of the DApp\n description text NOT NULL, -- description of the DApp\n url character varying(256) NOT NULL, -- URL of the DApp\n PRIMARY KEY (dapp_id)\n)\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\n"} {"conversations": [{"role": "user", "content": "Calculate the total PNL and total Net Flow for all tokens recorded on the 'Arbitrum' chain."}, {"role": "assistant", "content": "SELECT SUM(pnl) as total_pnl, SUM(net_flow) as total_net_flow FROM smart_money_token_performance WHERE chain = 'Arbitrum';"}, {"role": "user", "content": "Can you calculate the total PNL and total Net Flow for *all* chains? Show the chain, total PNL, and total Net Flow, ordered by total PNL in descending order."}, {"role": "assistant", "content": "SELECT chain, SUM(pnl) as total_pnl, SUM(net_flow) as total_net_flow FROM smart_money_token_performance GROUP BY chain ORDER BY total_pnl DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_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 names and policy numbers of all insured patients whose policy is currently expired."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, pi.policy_number, pi.expiration_date\nFROM healthcare.patients p\nJOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id\nWHERE pi.expiration_date IS NOT NULL AND pi.expiration_date < CURRENT_DATE;"}, {"role": "user", "content": "Please also return the insurance plan name and sort the results by the expiration_date in ascending order."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, pi.policy_number, ip.plan_name, pi.expiration_date\nFROM healthcare.patients p\nJOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id\nJOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id\nWHERE pi.expiration_date IS NOT NULL AND pi.expiration_date < CURRENT_DATE\nORDER BY pi.expiration_date ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.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.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n"} {"conversations": [{"role": "user", "content": "For each asset, show its name and symbol, and the total number of completed orders that have resulted in at least one trade."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COUNT(DISTINCT o.order_id) AS completed_order_count\nFROM trading_platform.assets a\nJOIN trading_platform.orders o ON o.asset_id = a.asset_id AND o.status = 'filled'\nJOIN trading_platform.trades t ON t.order_id = o.order_id\nGROUP BY a.asset_id, a.name, a.symbol;"}, {"role": "user", "content": "Only include assets where the total number of completed orders with trades is greater than 5, and sort the results by completed_order_count descending."}, {"role": "assistant", "content": "SELECT a.name, a.symbol, COUNT(DISTINCT o.order_id) AS completed_order_count\nFROM trading_platform.assets a\nJOIN trading_platform.orders o ON o.asset_id = a.asset_id AND o.status = 'filled'\nJOIN trading_platform.trades t ON t.order_id = o.order_id\nGROUP BY a.asset_id, a.name, a.symbol\nHAVING COUNT(DISTINCT o.order_id) > 5\nORDER BY completed_order_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\nCREATE TABLE trading_platform.orders ( order_id.text, user_id.text, wallet_id.text, asset_id.text, order_type.text, quantity.numeric, price.numeric, status.text, created_at.timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text )\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "For each player, list the total number of 'Legendary' rarity items they have in their inventory, along with the titles of the respective games those items belong to."}, {"role": "assistant", "content": "SELECT pi.player_id, g.game_id, g.title, COUNT(*) AS legendary_item_count\nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE i.rarity = 'Legendary'\nGROUP BY pi.player_id, g.game_id, g.title;"}, {"role": "user", "content": "Please modify the query to only include players who have more than 2 'Legendary' items per game."}, {"role": "assistant", "content": "SELECT pi.player_id, g.game_id, g.title, COUNT(*) AS legendary_item_count\nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE i.rarity = 'Legendary'\nGROUP BY pi.player_id, g.game_id, g.title\nHAVING COUNT(*) > 2;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\nCREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\n"} {"conversations": [{"role": "user", "content": "For all NFT collections on the Ethereum blockchain, show me the collection name and the current floor price. Sort by floor price descending."}, {"role": "assistant", "content": "SELECT name, floor_price FROM nft_collections WHERE blockchain = 'Ethereum' ORDER BY CAST(floor_price AS FLOAT) DESC;"}, {"role": "user", "content": "Include also the collection symbol and the number of tokens in each collection."}, {"role": "assistant", "content": "SELECT name, symbol, floor_price, token_count FROM nft_collections WHERE blockchain = 'Ethereum' ORDER BY CAST(floor_price AS FLOAT) DESC;"}, {"role": "user", "content": "Can you also show the owner of each collection in the result?"}, {"role": "assistant", "content": "SELECT name, symbol, floor_price, token_count, owner FROM nft_collections WHERE blockchain = 'Ethereum' ORDER BY CAST(floor_price AS FLOAT) DESC;"}, {"role": "user", "content": "Now only include collections whose floor price is greater than 1 ETH."}, {"role": "assistant", "content": "SELECT name, symbol, floor_price, token_count, owner FROM nft_collections WHERE blockchain = 'Ethereum' AND CAST(floor_price AS FLOAT) > 1 AND floor_price_symbol = 'ETH' ORDER BY CAST(floor_price AS FLOAT) DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )\n"} {"conversations": [{"role": "user", "content": "List all document IDs and document types for documents that have been verified by an employee, along with the verification timestamp and the ID of the verifying employee."}, {"role": "assistant", "content": "SELECT document_id, document_type, verification_timestamp, verified_by_employee_id FROM government_services.documents WHERE verified_by_employee_id IS NOT NULL;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Show me all active policies with coverage limits above $500,000, along with the customer names and agent names."}, {"role": "assistant", "content": "SELECT p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, c.name AS customer_name, a.name AS agent_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 > 500000;"}, {"role": "user", "content": "Actually, I only want to see policies that started in the last year and have a deductible of $1000 or more."}, {"role": "assistant", "content": "SELECT p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, p.deductible, c.name AS customer_name, a.name AS agent_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 > 500000 AND p.start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND p.deductible >= 1000;"}, {"role": "user", "content": "Now include the count of claims each of these policies has had."}, {"role": "assistant", "content": "SELECT p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, p.deductible, c.name AS customer_name, a.name AS agent_name, COUNT(cl.claim_id) AS claim_count 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 > 500000 AND p.start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND p.deductible >= 1000 GROUP BY p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, p.deductible, c.name, a.name;"}, {"role": "user", "content": "Finally, order the results by claim count in descending order and then by coverage limit in descending order."}, {"role": "assistant", "content": "SELECT p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, p.deductible, c.name AS customer_name, a.name AS agent_name, COUNT(cl.claim_id) AS claim_count 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 > 500000 AND p.start_date >= DATE_SUB(CURRENT_DATE, INTERVAL 1 YEAR) AND p.deductible >= 1000 GROUP BY p.policy_id, p.customer_id, p.agent_id, p.coverage_limit, p.deductible, c.name, a.name ORDER BY claim_count DESC, p.coverage_limit DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\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.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": "Find all medical records where the treatment plan includes 'physical therapy' and the patient has an active primary insurance plan, showing the patient ID, record date, and insurance provider details."}, {"role": "assistant", "content": "SELECT mr.patient_id, mr.record_date, ip.insurance_provider, ip.plan_name, pi.policy_number FROM healthcare.medical_records mr JOIN healthcare.patients p ON mr.patient_id = p.patient_id JOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id AND pi.is_primary = true JOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id WHERE mr.treatment_plan LIKE '%physical therapy%' AND (pi.expiration_date IS NULL OR pi.expiration_date > CURRENT_DATE);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n"} {"conversations": [{"role": "user", "content": "Can you show me each user's address and the date their wallet was created?"}, {"role": "assistant", "content": "SELECT user_id, address, created_at FROM trading_platform.wallets;"}, {"role": "user", "content": "Now, can you show only wallets created after '2024-01-01' and include the user_id and address?"}, {"role": "assistant", "content": "SELECT user_id, address, created_at FROM trading_platform.wallets WHERE created_at > '2024-01-01';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me each player's last_login and the end_time of their most recent game session."}, {"role": "assistant", "content": "SELECT p.player_id,\n p.username,\n p.last_login,\n gs.last_end_time\nFROM gaming_technology.players p\nLEFT JOIN (\n SELECT player_id, MAX(end_time) AS last_end_time\n FROM gaming_technology.game_sessions\n GROUP BY player_id\n) gs ON p.player_id = gs.player_id;"}, {"role": "user", "content": "Only list players whose status is 'active'."}, {"role": "assistant", "content": "SELECT p.player_id,\n p.username,\n p.last_login,\n gs.last_end_time\nFROM gaming_technology.players p\nLEFT JOIN (\n SELECT player_id, MAX(end_time) AS last_end_time\n FROM gaming_technology.game_sessions\n GROUP BY player_id\n) gs ON p.player_id = gs.player_id\nWHERE p.status = 'active';"}, {"role": "user", "content": "Also include the title of the game from that most recent session."}, {"role": "assistant", "content": "WITH latest AS (\n SELECT DISTINCT ON (player_id) player_id, end_time, game_id\n FROM gaming_technology.game_sessions\n WHERE end_time IS NOT NULL\n ORDER BY player_id, end_time DESC\n)\nSELECT p.player_id,\n p.username,\n p.last_login,\n l.end_time AS last_end_time,\n g.title AS last_game_title\nFROM gaming_technology.players p\nLEFT JOIN latest l ON p.player_id = l.player_id\nLEFT JOIN gaming_technology.games g ON l.game_id = g.game_id\nWHERE p.status = 'active';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\n"} {"conversations": [{"role": "user", "content": "What are the top 5 tokens by 7-day price change percentage? Show token_symbol, token_name, narrative, and chain, ordered by price_change_percentage_7d descending."}, {"role": "assistant", "content": "```sql\nSELECT\n token_symbol,\n token_name,\n narrative,\n chain\nFROM token_basic_info\nORDER BY price_change_percentage_7d DESC\nLIMIT 5;\n```"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n"} {"conversations": [{"role": "user", "content": "List all service orders for spa services with their guest names and total prices, ordered by total price in descending order."}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, so.order_id, so.total_price FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id WHERE so.service_id LIKE 'SPA%' ORDER BY so.total_price DESC;"}, {"role": "user", "content": "Now, include only orders with a total price over $100 and show the property ID where the service was ordered."}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, so.order_id, so.total_price, r.property_id FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id WHERE so.service_id LIKE 'SPA%' AND so.total_price > 100 ORDER BY so.total_price DESC;"}, {"role": "user", "content": "The query is missing the service name. Can you include that as well?"}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, so.order_id, so.total_price, r.property_id, s.service_name FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id JOIN hospitality_technology.services s ON so.service_id = s.service_id WHERE so.service_id LIKE 'SPA%' AND so.total_price > 100 ORDER BY so.total_price DESC;"}, {"role": "user", "content": "Actually, I only need orders from properties in California, and order by property ID first, then by total price."}, {"role": "assistant", "content": "SELECT g.first_name, g.last_name, so.order_id, so.total_price, r.property_id, s.service_name FROM hospitality_technology.service_orders so JOIN hospitality_technology.guests g ON so.guest_id = g.guest_id JOIN hospitality_technology.reservations r ON so.reservation_id = r.reservation_id JOIN hospitality_technology.services s ON so.service_id = s.service_id JOIN hospitality_technology.properties p ON r.property_id = p.property_id WHERE so.service_id LIKE 'SPA%' AND so.total_price > 100 AND p.state_province = 'California' ORDER BY r.property_id, so.total_price DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.guests (\n guest_id character varying(64) NOT NULL, -- unique identifier for the guest profile\n first_name character varying(100) NOT NULL, -- guest's first name\n last_name character varying(100) NOT NULL, -- guest's last name\n email character varying(255) UNIQUE, -- guest's email address (unique identifier?)\n phone_number character varying(30), -- guest's phone number\n date_of_birth date, -- guest's date of birth\n address_line1 character varying(255), -- guest's home address\n city character varying(100),\n state_province character varying(100),\n postal_code character varying(20),\n country_code character varying(3),\n preferences text, -- notes on guest preferences (e.g., allergies, room location)\n loyalty_member_id character varying(64) UNIQUE, -- FK to loyalty_members table\n communication_consent boolean DEFAULT true, -- consent for marketing communications\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (guest_id)\n)\nCREATE TABLE hospitality_technology.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.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 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 all asset types along with the count of distinct assets and the count of log actions for each type."}, {"role": "assistant", "content": "SELECT a.type, COUNT(DISTINCT a.asset_id) AS asset_count, COUNT(l.log_id) AS action_count FROM trading_platform.assets a LEFT JOIN trading_platform.logs l ON a.asset_id = l.details->>'asset_id' GROUP BY a.type ORDER BY action_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text )\nCREATE TABLE trading_platform.logs ( log_id text, user_id text, action text, details text, logged_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Who are the top three users by total uploaded file size? Return uploaded_by and their cumulative file_size_bytes."}, {"role": "assistant", "content": "SELECT uploaded_by,\n SUM(file_size_bytes) AS total_size\nFROM insurance.claim_documents\nWHERE file_size_bytes IS NOT NULL\nGROUP BY uploaded_by\nORDER BY total_size DESC\nLIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Which chain has the highest total USD inflow from buy transactions (type=1), and how many distinct tokens were involved in that inflow?"}, {"role": "assistant", "content": "SELECT chain, SUM(usd_value) AS total_inflow, COUNT(DISTINCT token_symbol) AS distinct_tokens\nFROM smart_money_token_inflow\nWHERE type = 1\nGROUP BY chain\nORDER BY total_inflow DESC\nLIMIT 1;"}, {"role": "user", "content": "I also want to see the average price at which those tokens were bought for that chain."}, {"role": "assistant", "content": "WITH inflow AS (\n SELECT chain, SUM(usd_value) AS total_inflow\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY chain\n), top_chain AS (\n SELECT chain FROM inflow ORDER BY total_inflow DESC LIMIT 1\n)\nSELECT i.chain, AVG(i.avg_price) AS avg_buy_price\nFROM smart_money_token_inflow i\nJOIN top_chain t ON i.chain = t.chain\nWHERE i.type = 1;"}, {"role": "user", "content": "Actually, filter to narratives where the total USD inflow is above 50000."}, {"role": "assistant", "content": "SELECT narrative, SUM(usd_value) AS total_inflow, COUNT(DISTINCT token_symbol) AS distinct_tokens\nFROM smart_money_token_inflow\nWHERE type = 1\nGROUP BY narrative\nHAVING SUM(usd_value) > 50000;"}, {"role": "user", "content": "Please order the results by average price descending and show the top 2 chains."}, {"role": "assistant", "content": "SELECT chain, SUM(usd_value) AS total_inflow, COUNT(DISTINCT token_symbol) AS distinct_tokens, AVG(avg_price) AS avg_buy_price\nFROM smart_money_token_inflow\nWHERE type = 1\nGROUP BY chain\nORDER BY avg_buy_price DESC\nLIMIT 2;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n"} {"conversations": [{"role": "user", "content": "Which games have at least one achievement worth exactly 75 points, and what are the names and descriptions of those achievements?"}, {"role": "assistant", "content": "SELECT g.title, a.name AS achievement_name, a.description\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a ON g.game_id = a.game_id\nWHERE a.points = 75;"}, {"role": "user", "content": "Also include the release date of each game in the output."}, {"role": "assistant", "content": "SELECT g.title, g.release_date, a.name AS achievement_name, a.description\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a ON g.game_id = a.game_id\nWHERE a.points = 75;"}, {"role": "user", "content": "Now, only show results for games released after 2021-01-01."}, {"role": "assistant", "content": "SELECT g.title, g.release_date, a.name AS achievement_name, a.description\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a ON g.game_id = a.game_id\nWHERE a.points = 75 AND g.release_date > '2021-01-01';"}, {"role": "user", "content": "Order the list by game release date ascending, then achievement name ascending."}, {"role": "assistant", "content": "SELECT g.title, g.release_date, a.name AS achievement_name, a.description\nFROM gaming_technology.games g\nJOIN gaming_technology.achievements a ON g.game_id = a.game_id\nWHERE a.points = 75 AND g.release_date > '2021-01-01'\nORDER BY g.release_date ASC, a.name ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid, 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 PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )\n"} {"conversations": [{"role": "user", "content": "List games that have servers deployed in more than one geographical region. Show the game title and the count of regions."}, {"role": "assistant", "content": "SELECT g.title, count(DISTINCT s.region) AS region_count FROM games AS g JOIN servers AS s ON g.game_id = s.game_id GROUP BY g.game_id, g.title HAVING count(DISTINCT s.region) > 1;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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, 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 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 )\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 all employees who are currently active and were hired before 2022. Show employee_id, first_name, last_name, job_title, department, and hire_date."}, {"role": "assistant", "content": "SELECT\n employee_id,\n first_name,\n last_name,\n job_title,\n department,\n hire_date\nFROM financial_services.employees\nWHERE\n status = 'Active' AND hire_date < '2022-01-01';"}, {"role": "user", "content": "Also, only include employees from the 'IT' or 'Operations' departments."}, {"role": "assistant", "content": "SELECT\n employee_id,\n first_name,\n last_name,\n job_title,\n department,\n hire_date\nFROM financial_services.employees\nWHERE\n status = 'Active' AND hire_date < '2022-01-01' AND department IN ('IT', 'Operations');"}, {"role": "user", "content": "Sort the results by hire date ascending and limit to the first 5."}, {"role": "assistant", "content": "SELECT\n employee_id,\n first_name,\n last_name,\n job_title,\n department,\n hire_date\nFROM financial_services.employees\nWHERE\n status = 'Active' AND hire_date < '2022-01-01' AND department IN ('IT', 'Operations')\nORDER BY\n hire_date ASC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.securities ( security_id.text, ticker_symbol.text, isin_code.text, cusip_code.text, security_name.text, security_type.text, exchange.text, currency.text, issuer_name.text, sector.text, last_updated.timestamp )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data ( data_point_id.bigint, security_id.text, data_timestamp.timestamp, open_price.numeric, high_price.numeric, low_price.numeric, close_price.numeric, adjusted_close_price.numeric, volume.bigint, source.text )\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\n"} {"conversations": [{"role": "user", "content": "Find the top 5 ERC20 tokens by number of approval events in `erc20_approval`. Show `contract_address`, `symbol`, and `total_approvals`."}, {"role": "assistant", "content": "SELECT ea.contract_address,\n tm.symbol,\n COUNT(*) AS total_approvals\nFROM erc20_approval ea\nJOIN token_metas tm ON ea.contract_address = tm.contract_address\nWHERE tm.is_erc20 = 1\nGROUP BY ea.contract_address, tm.symbol\nORDER BY total_approvals DESC\nLIMIT 5;"}, {"role": "user", "content": "Also include `decimals` for each token."}, {"role": "assistant", "content": "SELECT ea.contract_address,\n tm.symbol,\n tm.decimals,\n COUNT(*) AS total_approvals\nFROM erc20_approval ea\nJOIN token_metas tm ON ea.contract_address = tm.contract_address\nWHERE tm.is_erc20 = 1\nGROUP BY ea.contract_address, tm.symbol, tm.decimals\nORDER BY total_approvals DESC\nLIMIT 5;"}, {"role": "user", "content": "Only include tokens where `is_proxy = 0`."}, {"role": "assistant", "content": "SELECT ea.contract_address,\n tm.symbol,\n tm.decimals,\n COUNT(*) AS total_approvals\nFROM erc20_approval ea\nJOIN token_metas tm ON ea.contract_address = tm.contract_address\nWHERE tm.is_erc20 = 1\n AND tm.is_proxy = 0\nGROUP BY ea.contract_address, tm.symbol, tm.decimals\nORDER BY total_approvals DESC\nLIMIT 5;"}, {"role": "user", "content": "Now add the latest USD price for each token by joining `token_prices` using the most recent timestamp per address."}, {"role": "assistant", "content": "SELECT ea.contract_address,\n tm.symbol,\n tm.decimals,\n COUNT(*) AS total_approvals,\n tp.price AS latest_price\nFROM erc20_approval ea\nJOIN token_metas tm ON ea.contract_address = tm.contract_address\nLEFT JOIN token_prices tp\n ON tp.address = tm.contract_address\n AND tp.timestamp = (\n SELECT MAX(tp2.timestamp)\n FROM token_prices tp2\n WHERE tp2.address = tm.contract_address\n )\nWHERE tm.is_erc20 = 1\n AND tm.is_proxy = 0\nGROUP BY ea.contract_address, tm.symbol, tm.decimals, tp.price\nORDER BY total_approvals DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE 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 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 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_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 )\n"} {"conversations": [{"role": "user", "content": "List the content and comment ID for all comments made by users with private profiles."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content FROM social_media.comments AS c JOIN social_media.user_settings AS us ON c.user_id = us.user_id WHERE us.private_profile = TRUE;"}, {"role": "user", "content": "Only show comments created in the year 2024."}, {"role": "assistant", "content": "SELECT c.comment_id, c.content FROM social_media.comments AS c JOIN social_media.user_settings AS us ON c.user_id = us.user_id WHERE us.private_profile = TRUE AND c.created_at >= '2024-01-01' AND c.created_at < '2025-01-01';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.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": "What is the average age of verified citizens as of today?"}, {"role": "assistant", "content": "SELECT AVG(EXTRACT(YEAR FROM AGE(NOW(), date_of_birth))) AS average_age_verified\nFROM government_services.citizens\nWHERE is_verified = TRUE;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id text 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.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 all payments processed in the last 90 days, showing payment ID, amount, currency, method, and status."}, {"role": "assistant", "content": "SELECT payment_id, amount, currency_code, payment_method, status FROM hospitality_technology.payments WHERE payment_timestamp >= CURRENT_DATE - INTERVAL '90 day';"}, {"role": "user", "content": "Now, only show payments with status 'Failed' or 'Canceled'."}, {"role": "assistant", "content": "SELECT payment_id, amount, currency_code, payment_method, status FROM hospitality_technology.payments WHERE payment_timestamp >= CURRENT_DATE - INTERVAL '90 day' AND (status = 'Failed' OR status = 'Canceled');"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text PRIMARY KEY, property_id text, room_number text, room_type_id text, floor int, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, property_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.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 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 SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patient_insurance (\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": "Which policies have a premium amount greater than the base premium of their respective insurance product? Please show the policy_number, premium_amount, product_name, and base_premium."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium;"}, {"role": "user", "content": "Now, only include policies where the coverage_limit is above 500,000."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium\n AND p.coverage_limit > 500000;"}, {"role": "user", "content": "Actually, I also want to see only active policies."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium\n AND p.coverage_limit > 500000\n AND p.status = 'Active';"}, {"role": "user", "content": "Could you sort the results by premium_amount in descending order?"}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nINNER JOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.premium_amount > ip.base_premium\n AND p.coverage_limit > 500000\n AND p.status = 'Active'\nORDER BY p.premium_amount DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.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 contracts deployed on the 'ethereum' network along with their deployer wallet addresses and creation dates, sorted by the most recent deployments first."}, {"role": "assistant", "content": "SELECT c.contract_id, c.address, c.deployer_address, w.address AS deployer_wallet_address, c.deployed_at FROM web3.contracts c JOIN web3.wallets w ON c.deployer_address = w.address WHERE c.network_id = 'ethereum' ORDER BY c.deployed_at DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show the invoice_id and total hours logged for each invoice."}, {"role": "assistant", "content": "SELECT invoice_id, SUM(hours_spent) AS total_hours FROM legal_services.time_entries WHERE invoice_id IS NOT NULL GROUP BY invoice_id;"}, {"role": "user", "content": "Only include invoices with more than 10 total hours."}, {"role": "assistant", "content": "SELECT invoice_id, SUM(hours_spent) AS total_hours FROM legal_services.time_entries WHERE invoice_id IS NOT NULL GROUP BY invoice_id HAVING SUM(hours_spent) > 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 all ERC20 tokens where the price is greater than $10, including their names, symbols, and contract addresses."}, {"role": "assistant", "content": "SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tpl.price > 10 AND tm.is_erc20 = 1;"}, {"role": "user", "content": "I think there's an error in your query - it should be 'tpl.price > 10' not 'tpl.price > 10'. Also, can you add the current price to the results?"}, {"role": "assistant", "content": "SELECT tm.name, tm.symbol, tm.contract_address, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tpl.price > 10 AND tm.is_erc20 = 1;"}, {"role": "user", "content": "Now sort these results by price in descending order and limit to the top 10."}, {"role": "assistant", "content": "SELECT tm.name, tm.symbol, tm.contract_address, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tpl.price > 10 AND tm.is_erc20 = 1 ORDER BY tpl.price DESC LIMIT 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol 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_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n"} {"conversations": [{"role": "user", "content": "How many documents are there for each document_type? Show document_type and count ordered by the count in descending order."}, {"role": "assistant", "content": "SELECT document_type,\n COUNT(*) AS count\nFROM legal_services.documents\nGROUP BY document_type\nORDER BY count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 NFT collections with the highest floor price on Ethereum, along with their names and contract addresses, but only include collections with more than 5000 tokens."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.floor_price FROM nft_collections nc WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Can you join this with the nft_metadata table to include the average rarity score for these collections?"}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.floor_price, AVG(nm.rarity_score) as avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 GROUP BY nc.name, nc.contract_address, nc.floor_price ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "Now filter these results to only show collections with an average rarity score above 75."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, nc.floor_price, AVG(nm.rarity_score) as avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 GROUP BY nc.name, nc.contract_address, nc.floor_price HAVING AVG(nm.rarity_score) > 75 ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata ( object_id varchar NOT NULL, coin_type varchar NOT NULL, status varchar NOT NULL, decimals bigint NOT NULL, description varchar NOT NULL, icon_url varchar NOT NULL, symbol varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id varchar NOT NULL, status varchar NOT NULL, collection_type varchar NOT NULL, package_id varchar NOT NULL, previous_transaction varchar NOT NULL, display varchar NOT NULL, owner varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )\n"} {"conversations": [{"role": "user", "content": "Can you help me retrieve the details of all bookings for a specific route with route_id 'RT789', including the passenger names and the scheduled departure times?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nWHERE s.route_id = 'RT789';"}, {"role": "user", "content": "Can you modify the query to include only bookings with a status of 'Pending'?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending';"}, {"role": "user", "content": "Can you also add the route name and origin station ID to the results?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price, r.route_name, r.origin_station_id\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nJOIN train_station_management.routes r ON s.route_id = r.route_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending';"}, {"role": "user", "content": "Can you sort the results by departure datetime in descending order?"}, {"role": "assistant", "content": "SELECT b.booking_id, p.first_name, p.last_name, s.departure_datetime, b.status, b.total_price, r.route_name, r.origin_station_id\nFROM train_station_management.bookings b\nJOIN train_station_management.passengers p ON b.passenger_id = p.passenger_id\nJOIN train_station_management.schedules s ON b.schedule_id = s.schedule_id\nJOIN train_station_management.routes r ON s.route_id = r.route_id\nWHERE s.route_id = 'RT789' AND b.status = 'Pending'\nORDER BY s.departure_datetime DESC;"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE train_station_management.train_cars (\n car_id character varying(64) NOT NULL, -- Unique identifier for the train car\n train_id character varying(64) NOT NULL, -- Foreign key referencing trains\n car_number character varying(10) NOT NULL, -- Identifier of the car within the train set\n car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage\n class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars)\n capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars)\n features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom')\n PRIMARY KEY (car_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id)\n)\nCREATE TABLE train_station_management.routes (\n route_id character varying(64) NOT NULL, -- Unique identifier for the route\n route_name character varying(128) NOT NULL, -- Name of the route (e.g., 'Northeast Corridor')\n description text, -- Description of the route\n origin_station_id character varying(64) NOT NULL, -- Starting station\n destination_station_id character varying(64) NOT NULL, -- Final station\n is_active boolean NOT NULL DEFAULT true, -- Is the route currently operational?\n PRIMARY KEY (route_id),\n FOREIGN KEY (origin_station_id) REFERENCES train_station_management.stations(station_id),\n FOREIGN KEY (destination_station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.route_stations (\n route_station_id character varying(64) NOT NULL, -- Unique ID for this route-station link\n route_id character varying(64) NOT NULL, -- Foreign key referencing routes\n station_id character varying(64) NOT NULL, -- Foreign key referencing stations\n sequence_order integer NOT NULL, -- Order of the station in the route (1 for origin, 2, 3...)\n distance_from_previous_km numeric(10, 2), -- Distance from the previous station in the sequence\n typical_stop_duration_minutes integer, -- Typical dwell time at this station\n PRIMARY KEY (route_station_id),\n UNIQUE (route_id, station_id),\n UNIQUE (route_id, sequence_order),\n FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id),\n FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id)\n)\nCREATE TABLE train_station_management.schedules (\n schedule_id character varying(64) NOT NULL, -- Unique identifier for a specific scheduled trip\n train_id character varying(64) NOT NULL, -- Foreign key referencing the train used\n route_id character varying(64) NOT NULL, -- Foreign key referencing the route taken\n departure_datetime timestamp with time zone NOT NULL, -- Scheduled departure time from origin station\n arrival_datetime timestamp with time zone NOT NULL, -- Scheduled arrival time at destination station\n status character varying(32) NOT NULL DEFAULT 'Scheduled', -- e.g., Scheduled, On Time, Delayed, Cancelled, Arrived\n notes text, -- Any notes regarding this specific trip (e.g., reason for delay)\n PRIMARY KEY (schedule_id),\n FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id),\n FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id)\n)\nCREATE TABLE train_station_management.passengers (\n passenger_id character varying(64) NOT NULL, -- Unique identifier for the passenger\n first_name character varying(100) NOT NULL, -- Passenger's first name\n last_name character varying(100) NOT NULL, -- Passenger's last name\n email character varying(128) UNIQUE, -- Passenger's email address\n phone_number character varying(32) UNIQUE, -- Passenger's phone number\n date_of_birth date, -- Passenger's date of birth\n loyalty_program_id character varying(64), -- ID for loyalty program, if applicable\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE train_station_management.bookings (\n booking_id character varying(64) NOT NULL, -- Unique identifier for the booking\n passenger_id character varying(64) NOT NULL, -- Foreign key referencing the passenger\n schedule_id character varying(64) NOT NULL, -- Foreign key referencing the scheduled trip\n booking_datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the booking was made\n status character varying(32) NOT NULL DEFAULT 'Confirmed', -- e.g., Confirmed, Cancelled, Pending\n total_price numeric(12, 2) NOT NULL, -- Total price for all tickets in this booking\n currency_code character varying(3) NOT NULL DEFAULT 'USD', -- Currency of the price\n special_requests text, -- Any special requests (e.g., wheelchair assistance)\n PRIMARY KEY (booking_id),\n FOREIGN KEY (passenger_id) REFERENCES train_station_management.passengers(passenger_id),\n FOREIGN KEY (schedule_id) REFERENCES train_station_management.schedules(schedule_id)\n)\nCREATE TABLE train_station_management.staff (\n staff_id character varying(64) NOT NULL, -- Unique identifier for the staff member\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n role character varying(64) NOT NULL, -- e.g., Station Master, Ticket Agent, Conductor, Engineer, Maintenance Crew\n primary_station_id character varying(64), -- Base station for the staff member (nullable for mobile staff)\n employee_number character varying(32) UNIQUE NOT NULL, -- Unique employee identifier\n hire_date date NOT NULL,\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n is_active boolean NOT NULL DEFAULT true, -- Is the staff member currently employed?\n PRIMARY KEY (staff_id),\n FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id)\n)\n"} {"conversations": [{"role": "user", "content": "List all pairs of wallets that were created within 10 minutes of each other, showing both wallet IDs, the user_id, and both creation timestamps."}, {"role": "assistant", "content": "SELECT\n w1.wallet_id AS wallet1_id,\n w2.wallet_id AS wallet2_id,\n w1.user_id,\n w1.created_at AS created_at1,\n w2.created_at AS created_at2\nFROM web3.wallets w1\nJOIN web3.wallets w2\n ON w1.user_id = w2.user_id\n AND w1.wallet_id < w2.wallet_id\n AND ABS(EXTRACT(EPOCH FROM (w1.created_at - w2.created_at))) <= 600;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Find the security name and ticker symbol for all securities that have a market data entry with a trading volume greater than 5,000,000."}, {"role": "assistant", "content": "SELECT DISTINCT T1.security_name, T1.ticker_symbol FROM financial_services.securities AS T1 JOIN financial_services.market_data AS T2 ON T1.security_id = T2.security_id WHERE T2.volume > 5000000"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.transactions ( transaction_id text, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )\nCREATE TABLE financial_services.securities ( security_id text, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.market_data ( data_point_id bigint, security_id text, data_timestamp timestamp, open_price numeric, high_price numeric, low_price numeric, close_price numeric, adjusted_close_price numeric, volume bigint, source text )\n"} {"conversations": [{"role": "user", "content": "For each vehicle, count how many maintenance logs exist."}, {"role": "assistant", "content": "SELECT v.vehicle_id, v.make, v.model, COUNT(ml.log_id) AS maintenance_log_count FROM transportation.vehicles v JOIN transportation.maintenance_logs ml ON v.vehicle_id = ml.vehicle_id GROUP BY v.vehicle_id, v.make, v.model ORDER BY maintenance_log_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\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.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) )\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.passengers ( passenger_id character varying(64) NOT NULL, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32) UNIQUE, date_of_birth date, loyalty_program_id character varying(64), created_at timestamp with time zone NOT NULL, PRIMARY KEY (passenger_id) )\n"} {"conversations": [{"role": "user", "content": "Show me a list of all doctors who have made at least one diagnosis along with the total number of diagnoses they have made."}, {"role": "assistant", "content": "SELECT d.doctor_id, d.first_name, d.last_name, COUNT(di.diagnosis_id) AS diagnosis_count\nFROM healthcare.doctors d\nJOIN healthcare.diagnoses di ON d.doctor_id = di.doctor_id\nGROUP BY d.doctor_id, d.first_name, d.last_name\nHAVING COUNT(di.diagnosis_id) > 0;"}, {"role": "user", "content": "Now, limit the list to doctors with fewer than 10 diagnoses and order them by diagnosis_count ascending."}, {"role": "assistant", "content": "SELECT d.doctor_id, d.first_name, d.last_name, COUNT(di.diagnosis_id) AS diagnosis_count\nFROM healthcare.doctors d\nJOIN healthcare.diagnoses di ON d.doctor_id = di.doctor_id\nGROUP BY d.doctor_id, d.first_name, d.last_name\nHAVING COUNT(di.diagnosis_id) > 0 AND COUNT(di.diagnosis_id) < 10\nORDER BY diagnosis_count ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id.text, 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.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 )\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 auto loans (loan_id, principal_amount, interest_rate) where the current principal balance is less than 40% of the original principal amount, along with the account_id and the difference between principal_amount and current_principal_balance."}, {"role": "assistant", "content": "SELECT loan_id, principal_amount, interest_rate, account_id, (principal_amount - current_principal_balance) AS amount_paid FROM financial_services.loans WHERE loan_type = 'Auto' AND current_principal_balance < (0.4 * principal_amount);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )\n"} {"conversations": [{"role": "user", "content": "Count the total number of cases that are currently marked as 'Open'."}, {"role": "assistant", "content": "SELECT COUNT(*) FROM cases WHERE status = 'Open'"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.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": "Find all chronic diagnoses made by Cardiology doctors in the last year, including patient ID, diagnosis description, and doctor's full name."}, {"role": "assistant", "content": "SELECT di.patient_id, di.description, d.first_name || ' ' || d.last_name AS doctor_name, di.diagnosis_date FROM healthcare.diagnoses di JOIN healthcare.doctors d ON di.doctor_id = d.doctor_id WHERE di.is_chronic = true AND d.specialty = 'Cardiology' AND di.diagnosis_date >= CURRENT_DATE - INTERVAL '1 year' ORDER BY di.diagnosis_date DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\n"} {"conversations": [{"role": "user", "content": "List the full names and dates of birth for all patients who do not have a phone number on record."}, {"role": "assistant", "content": "SELECT first_name, last_name, date_of_birth FROM healthcare.patients WHERE phone_number IS NULL OR TRIM(phone_number) = '';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )\n"} {"conversations": [{"role": "user", "content": "List each citizen's first and last name along with the first and last name of another citizen who shares the same last name. Show each pair only once."}, {"role": "assistant", "content": "SELECT c1.first_name || ' ' || c1.last_name AS citizen_name,\n c2.first_name || ' ' || c2.last_name AS other_citizen_name\nFROM government_services.citizens c1\nJOIN government_services.citizens c2\n ON c1.last_name = c2.last_name\n AND c1.citizen_id < c2.citizen_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\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": "List the usernames and emails of all users who registered on '2023-03-15'."}, {"role": "assistant", "content": "SELECT username, email FROM web3.users WHERE DATE(created_at) = '2023-03-15';"}, {"role": "user", "content": "Instead of the list, can you just give me the total number of users who registered on '2023-03-15'?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM web3.users WHERE DATE(created_at) = '2023-03-15';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "I want to know, for each conversation participant, how many unread messages they have. Return participant_id, conversation_id, and unread_count."}, {"role": "assistant", "content": "SELECT cp.participant_id,\n cp.conversation_id,\n COUNT(m.message_id) AS unread_count\nFROM social_media.conversation_participants cp\nJOIN social_media.messages m\n ON m.conversation_id = cp.conversation_id\nWHERE m.sent_at > COALESCE(cp.last_read_at, '1970-01-01'::timestamp)\nGROUP BY cp.participant_id, cp.conversation_id;"}, {"role": "user", "content": "Can you filter the results to only include participants who joined the conversation before the earliest unread message was sent?"}, {"role": "assistant", "content": "SELECT cp.participant_id,\n cp.conversation_id,\n COUNT(m.message_id) AS unread_count\nFROM social_media.conversation_participants cp\nJOIN social_media.messages m\n ON m.conversation_id = cp.conversation_id\nWHERE m.sent_at > COALESCE(cp.last_read_at, '1970-01-01'::timestamp)\nGROUP BY cp.participant_id, cp.conversation_id\nHAVING cp.joined_at < MIN(m.sent_at);"}, {"role": "user", "content": "Also, include the timestamp of the most recent unread message for each participant as last_unread_at."}, {"role": "assistant", "content": "SELECT cp.participant_id,\n cp.conversation_id,\n COUNT(m.message_id) AS unread_count,\n MAX(m.sent_at) AS last_unread_at\nFROM social_media.conversation_participants cp\nJOIN social_media.messages m\n ON m.conversation_id = cp.conversation_id\nWHERE m.sent_at > COALESCE(cp.last_read_at, '1970-01-01'::timestamp)\nGROUP BY cp.participant_id, cp.conversation_id\nHAVING cp.joined_at < MIN(m.sent_at);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "For each reservation, list the guest ID, property name, and the total amount booked. Only include reservations where the total amount is greater than 300."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.guest_id, p.property_name, r.total_amount\nFROM hospitality_technology.reservations r\nJOIN hospitality_technology.properties p ON r.property_id = p.property_id\nWHERE r.total_amount > 300;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.reservations ( reservation_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, guest_id character varying(64) NOT NULL, room_id character varying(64), room_type_id character varying(64) NOT NULL, check_in_date date NOT NULL, check_out_date date NOT NULL, actual_check_in_ts timestamp with time zone, actual_check_out_ts timestamp with time zone, num_adults integer NOT NULL, num_children integer DEFAULT 0, status character varying(50) NOT NULL, booking_source character varying(100), rate_plan_id character varying(64), total_amount numeric(12, 2), amount_paid numeric(12, 2) DEFAULT 0.00, special_requests text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (reservation_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n"} {"conversations": [{"role": "user", "content": "List all achievements (name and ID) that have not been unlocked by any player."}, {"role": "assistant", "content": "SELECT a.achievement_id, a.name FROM gaming_technology.achievements a LEFT JOIN gaming_technology.player_achievements pa ON a.achievement_id = pa.achievement_id WHERE pa.player_achievement_id IS NULL;"}, {"role": "user", "content": "Also include the points for these achievements."}, {"role": "assistant", "content": "SELECT a.achievement_id, a.name, a.points FROM gaming_technology.achievements a LEFT JOIN gaming_technology.player_achievements pa ON a.achievement_id = pa.achievement_id WHERE pa.player_achievement_id IS NULL;"}, {"role": "user", "content": "Order the results by points in descending order."}, {"role": "assistant", "content": "SELECT a.achievement_id, a.name, a.points FROM gaming_technology.achievements a LEFT JOIN gaming_technology.player_achievements pa ON a.achievement_id = pa.achievement_id WHERE pa.player_achievement_id IS NULL ORDER BY a.points DESC;"}, {"role": "user", "content": "Only show achievements with points greater than 0."}, {"role": "assistant", "content": "SELECT a.achievement_id, a.name, a.points FROM gaming_technology.achievements a LEFT JOIN gaming_technology.player_achievements pa ON a.achievement_id = pa.achievement_id WHERE pa.player_achievement_id IS NULL AND a.points > 0 ORDER BY a.points DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\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": "For each sector, could you show the sum of volume and the average close price from market_data, including the sector name?"}, {"role": "assistant", "content": "SELECT s.sector, SUM(md.volume) AS total_volume, AVG(md.close_price) AS avg_close_price\nFROM financial_services.securities s\nJOIN financial_services.market_data md ON s.security_id = md.security_id\nGROUP BY s.sector;"}, {"role": "user", "content": "Could you also include the maximum high price for each sector in the result?"}, {"role": "assistant", "content": "SELECT s.sector, SUM(md.volume) AS total_volume, AVG(md.close_price) AS avg_close_price, MAX(md.high_price) AS max_high_price\nFROM financial_services.securities s\nJOIN financial_services.market_data md ON s.security_id = md.security_id\nGROUP BY s.sector;"}, {"role": "user", "content": "Now, only include sectors where the total_volume is at least 1000000, and sort by max_high_price descending."}, {"role": "assistant", "content": "SELECT s.sector, SUM(md.volume) AS total_volume, AVG(md.close_price) AS avg_close_price, MAX(md.high_price) AS max_high_price\nFROM financial_services.securities s\nJOIN financial_services.market_data md ON s.security_id = md.security_id\nGROUP BY s.sector\nHAVING SUM(md.volume) >= 1000000\nORDER BY max_high_price DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.securities ( security_id.text, ticker_symbol.text, isin_code.text, cusip_code.text, security_name.text, security_type.text, exchange.text, currency.text, issuer_name.text, sector.text, last_updated.timestamp )\nCREATE TABLE financial_services.market_data ( data_point_id 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": "List each narrative along with the token that has the highest current price and the token that has the lowest current price from the token_basic_info table."}, {"role": "assistant", "content": "WITH ranked_high AS (\n SELECT narrative, token_symbol, price,\n ROW_NUMBER() OVER (PARTITION BY narrative ORDER BY price DESC) AS rn\n FROM token_basic_info\n),\nranked_low AS (\n SELECT narrative, token_symbol, price,\n ROW_NUMBER() OVER (PARTITION BY narrative ORDER BY price ASC) AS rn\n FROM token_basic_info\n)\nSELECT h.narrative,\n h.token_symbol AS max_price_token,\n l.token_symbol AS min_price_token,\n h.price AS max_price,\n l.price AS min_price\nFROM ranked_high h\nJOIN ranked_low l\n ON h.narrative = l.narrative\nWHERE h.rn = 1\n AND l.rn = 1;"}, {"role": "user", "content": "Please only include narratives where the price difference between max and min price exceeds $50."}, {"role": "assistant", "content": "WITH ranked_high AS (\n SELECT narrative, token_symbol, price,\n ROW_NUMBER() OVER (PARTITION BY narrative ORDER BY price DESC) AS rn\n FROM token_basic_info\n),\nranked_low AS (\n SELECT narrative, token_symbol, price,\n ROW_NUMBER() OVER (PARTITION BY narrative ORDER BY price ASC) AS rn\n FROM token_basic_info\n)\nSELECT h.narrative,\n h.token_symbol AS max_price_token,\n l.token_symbol AS min_price_token,\n h.price AS max_price,\n l.price AS min_price\nFROM ranked_high h\nJOIN ranked_low l\n ON h.narrative = l.narrative\nWHERE h.rn = 1\n AND l.rn = 1\n AND (h.price - l.price) > 50;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 all fuel refueling events with the refueled vehicle's make and model, the fuel type used, and the fueling location ID."}, {"role": "assistant", "content": "SELECT fl.fuel_log_id, fl.log_timestamp, v.make, v.model, fl.fuel_type, fl.quantity, fl.unit, fl.total_cost, fl.location_id\nFROM transportation.fuel_logs fl\nJOIN transportation.vehicles v ON fl.vehicle_id = v.vehicle_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.trips ( trip_id text, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count integer, cargo_manifest_id text )\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\nCREATE TABLE transportation.fuel_logs (\n fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled\n trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred\n log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred\n fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type)\n quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh)\n unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh)\n cost_per_unit numeric(8, 4), -- price per unit of fuel\n total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase\n odometer_reading integer, -- vehicle mileage at time of fueling\n location_id character varying(64), -- identifier of the fueling station/location\n PRIMARY KEY (fuel_log_id)\n)\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n"} {"conversations": [{"role": "user", "content": "Show me all loans (loan_id, loan_type, principal_amount) where the current principal balance is less than 30% of the original principal amount, along with their account_id and status."}, {"role": "assistant", "content": "SELECT loan_id, loan_type, principal_amount, account_id, status FROM financial_services.loans WHERE current_principal_balance < 0.3 * principal_amount;"}, {"role": "user", "content": "Now modify the query to only include active loans (status = 'Active') and sort them by principal_amount in descending order."}, {"role": "assistant", "content": "SELECT loan_id, loan_type, principal_amount, account_id, status FROM financial_services.loans WHERE current_principal_balance < 0.3 * principal_amount AND status = 'Active' ORDER BY principal_amount DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.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 properties in California with their star ratings and the total number of rooms they have, ordered by the room count in descending order."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, p.star_rating, COUNT(r.room_id) AS room_count FROM hospitality_technology.properties p LEFT JOIN hospitality_technology.rooms r ON p.property_id = r.property_id WHERE p.state_province = 'California' GROUP BY p.property_id, p.property_name, p.star_rating ORDER BY room_count DESC;"}, {"role": "user", "content": "Now, include only properties with a star rating of 4.0 or higher and show the average base rate of their room types."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, p.star_rating, COUNT(r.room_id) AS room_count, AVG(rt.base_rate) AS avg_base_rate FROM hospitality_technology.properties p LEFT JOIN hospitality_technology.rooms r ON p.property_id = r.property_id LEFT JOIN hospitality_technology.room_types rt ON p.property_id = rt.property_id WHERE p.state_province = 'California' AND p.star_rating >= 4.0 GROUP BY p.property_id, p.property_name, p.star_rating ORDER BY room_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, room_number character varying(10) NOT NULL, room_type_id character varying(64) NOT NULL, floor integer, status character varying(50) NOT NULL, is_smoking boolean NOT NULL DEFAULT false, features text, current_condition text, last_cleaned_at timestamp with time zone, PRIMARY KEY (room_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id) )\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.reservations (\n reservation_id character varying(64) NOT NULL, -- unique identifier for the booking\n property_id character varying(64) NOT NULL, -- FK to properties table\n guest_id character varying(64) NOT NULL, -- FK to guests table (primary guest)\n room_id character varying(64), -- FK to rooms table (assigned room, might be null initially)\n room_type_id character varying(64) NOT NULL, -- FK to room_types table (booked room type)\n check_in_date date NOT NULL, -- scheduled check-in date\n check_out_date date NOT NULL, -- scheduled check-out date\n actual_check_in_ts timestamp with time zone, -- actual check-in time\n actual_check_out_ts timestamp with time zone, -- actual check-out time\n num_adults integer NOT NULL, -- number of adults\n num_children integer DEFAULT 0, -- number of children\n status character varying(50) NOT NULL, -- e.g., Pending, Confirmed, CheckedIn, CheckedOut, Cancelled, NoShow\n booking_source character varying(100), -- e.g., Website, OTA (Expedia, Booking.com), Phone, WalkIn\n rate_plan_id character varying(64), -- FK to rate_plans table (optional)\n total_amount numeric(12, 2), -- estimated or final total cost\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n special_requests text, -- specific guest requests for this booking\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (reservation_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.payments ( payment_id text PRIMARY KEY, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n"} {"conversations": [{"role": "user", "content": "List every diagnosis description paired with every insurance plan's website."}, {"role": "assistant", "content": "SELECT T1.description, T2.website FROM healthcare.diagnoses AS T1 CROSS JOIN healthcare.insurance_plans AS T2;"}, {"role": "user", "content": "Only include chronic diagnoses and plans whose website ends with '.org'."}, {"role": "assistant", "content": "SELECT T1.description, T2.website FROM healthcare.diagnoses AS T1 CROSS JOIN healthcare.insurance_plans AS T2 WHERE T1.is_chronic = true AND T2.website LIKE '%.org';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n"} {"conversations": [{"role": "user", "content": "Calculate for each player the timespan between their earliest and latest achievement unlocks."}, {"role": "assistant", "content": "SELECT pa_min.player_id,\n pa_max.max_time - pa_min.min_time AS span\nFROM (\n SELECT player_id,\n MIN(unlocked_at) AS min_time\n FROM gaming_technology.player_achievements\n GROUP BY player_id\n) pa_min\nJOIN (\n SELECT player_id,\n MAX(unlocked_at) AS max_time\n FROM gaming_technology.player_achievements\n GROUP BY player_id\n) pa_max\n ON pa_min.player_id = pa_max.player_id;"}, {"role": "user", "content": "Exclude players who only have one achievement."}, {"role": "assistant", "content": "WITH extremes AS (\n SELECT player_id,\n MIN(unlocked_at) AS min_time,\n MAX(unlocked_at) AS max_time,\n COUNT(*) AS cnt\n FROM gaming_technology.player_achievements\n GROUP BY player_id\n HAVING COUNT(*) > 1\n)\nSELECT player_id,\n max_time - min_time AS span\nFROM extremes;"}, {"role": "user", "content": "Also only keep players where the span is greater than 30 days."}, {"role": "assistant", "content": "WITH extremes AS (\n SELECT player_id,\n MIN(unlocked_at) AS min_time,\n MAX(unlocked_at) AS max_time,\n COUNT(*) AS cnt\n FROM gaming_technology.player_achievements\n GROUP BY player_id\n HAVING COUNT(*) > 1\n)\nSELECT player_id,\n max_time - min_time AS span\nFROM extremes\nWHERE max_time - min_time > INTERVAL '30 days';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me the total number of trades and total volume for each buyer-seller pair where the same two users traded multiple assets."}, {"role": "assistant", "content": "SELECT buyer_id, seller_id, COUNT(DISTINCT asset_id) AS asset_count, COUNT(*) AS trade_count, SUM(quantity * price) AS total_volume FROM trading_platform.trades GROUP BY buyer_id, seller_id HAVING COUNT(DISTINCT asset_id) > 1;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\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 SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\nCREATE TABLE insurance.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": "What is the average ROI and average realized_ratio for each chain?"}, {"role": "assistant", "content": "SELECT chain,\n AVG(roi) AS avg_roi,\n AVG(realized_ratio) AS avg_realized_ratio\nFROM smart_money_token_performance\nGROUP BY chain;"}, {"role": "user", "content": "Now filter to only include chains where average ROI is above 0.5."}, {"role": "assistant", "content": "WITH stats AS (\n SELECT chain,\n AVG(roi) AS avg_roi,\n AVG(realized_ratio) AS avg_realized_ratio\n FROM smart_money_token_performance\n GROUP BY chain\n)\nSELECT chain, avg_roi, avg_realized_ratio\nFROM stats\nWHERE avg_roi > 0.5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\n"} {"conversations": [{"role": "user", "content": "Retrieve all documents uploaded in 2024, showing document_id, uploaded_by, and uploaded_at."}, {"role": "assistant", "content": "SELECT document_id,\n uploaded_by,\n uploaded_at\nFROM insurance.claim_documents\nWHERE uploaded_at >= '2024-01-01'\n AND uploaded_at < '2025-01-01';"}, {"role": "user", "content": "Actually, please only include documents larger than 1MB."}, {"role": "assistant", "content": "SELECT document_id,\n uploaded_by,\n uploaded_at,\n file_size_bytes\nFROM insurance.claim_documents\nWHERE uploaded_at >= '2024-01-01'\n AND uploaded_at < '2025-01-01'\n AND file_size_bytes > 1048576;"}, {"role": "user", "content": "And sort them by file_size_bytes descending."}, {"role": "assistant", "content": "SELECT document_id,\n uploaded_by,\n uploaded_at,\n file_size_bytes\nFROM insurance.claim_documents\nWHERE uploaded_at >= '2024-01-01'\n AND uploaded_at < '2025-01-01'\n AND file_size_bytes > 1048576\nORDER BY file_size_bytes DESC;"}, {"role": "user", "content": "Limit the results to the first 5 entries."}, {"role": "assistant", "content": "SELECT document_id,\n uploaded_by,\n uploaded_at,\n file_size_bytes\nFROM insurance.claim_documents\nWHERE uploaded_at >= '2024-01-01'\n AND uploaded_at < '2025-01-01'\n AND file_size_bytes > 1048576\nORDER BY file_size_bytes DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id.text, claim_id.text, document_type.text, file_name.text, file_path.text, file_size_bytes.integer, mime_type.text, uploaded_by.text, uploaded_at.timestamp, description.text )\n"} {"conversations": [{"role": "user", "content": "Show me all players, listing their player_id, username, and registration_date."}, {"role": "assistant", "content": "SELECT player_id, username, registration_date FROM gaming_technology.players;"}, {"role": "user", "content": "Filter the list to only include players who registered in the year 2023."}, {"role": "assistant", "content": "SELECT player_id, username, registration_date FROM gaming_technology.players WHERE registration_date >= '2023-01-01' AND registration_date < '2024-01-01';"}, {"role": "user", "content": "Exclude any players whose status is 'banned'."}, {"role": "assistant", "content": "SELECT player_id, username, registration_date FROM gaming_technology.players WHERE registration_date >= '2023-01-01' AND registration_date < '2024-01-01' AND status != 'banned';"}, {"role": "user", "content": "Order the results by registration date descending."}, {"role": "assistant", "content": "SELECT player_id, username, registration_date FROM gaming_technology.players WHERE registration_date >= '2023-01-01' AND registration_date < '2024-01-01' AND status != 'banned' ORDER BY registration_date DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.developers ( 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, 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) )\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n"} {"conversations": [{"role": "user", "content": "List the make, model, year, and the depot_id for all vehicles acquired before 2020."}, {"role": "assistant", "content": "SELECT make, model, year, depot_id FROM transportation.vehicles WHERE acquisition_date < '2020-01-01';"}, {"role": "user", "content": "Add the vehicle_id and filter to only include vehicles where status is 'Active'."}, {"role": "assistant", "content": "SELECT vehicle_id, make, model, year, depot_id FROM transportation.vehicles WHERE acquisition_date < '2020-01-01' AND status = 'Active';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Show me all securities (security_id, ticker_symbol, security_name) that are traded on the NASDAQ exchange and have a daily trading volume exceeding 1 million shares, along with the account details (account_id, account_number, balance) of customers who hold these securities in their accounts."}, {"role": "assistant", "content": "SELECT s.security_id, s.ticker_symbol, s.security_name, a.account_id, a.account_number, a.balance FROM financial_services.securities s JOIN financial_services.market_data md ON s.security_id = md.security_id JOIN financial_services.accounts a ON s.currency = a.currency WHERE s.exchange = 'NASDAQ' AND md.volume > 1000000 AND a.status = 'Open' GROUP BY s.security_id, s.ticker_symbol, s.security_name, a.account_id, a.account_number, a.balance;"}, {"role": "user", "content": "Now modify the query to only include accounts with a balance greater than $50,000 and sort them by balance in descending order."}, {"role": "assistant", "content": "SELECT s.security_id, s.ticker_symbol, s.security_name, a.account_id, a.account_number, a.balance FROM financial_services.securities s JOIN financial_services.market_data md ON s.security_id = md.security_id JOIN financial_services.accounts a ON s.currency = a.currency WHERE s.exchange = 'NASDAQ' AND md.volume > 1000000 AND a.status = 'Open' AND a.balance > 50000 GROUP BY s.security_id, s.ticker_symbol, s.security_name, a.account_id, a.account_number, a.balance ORDER BY a.balance DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.securities ( security_id text, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\nCREATE TABLE financial_services.market_data ( data_point_id bigint, security_id text, data_timestamp timestamp, open_price numeric, high_price numeric, low_price numeric, close_price numeric, adjusted_close_price numeric, volume bigint, source text )\nCREATE TABLE financial_services.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 route type, show the total number of trips taken and the total distance covered across all trips for that type."}, {"role": "assistant", "content": "SELECT T1.type, COUNT(T2.trip_id), SUM(T1.distance_km) FROM transportation.routes AS T1 JOIN transportation.trips AS T2 ON T1.route_id = T2.route_id GROUP BY T1.type;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\nCREATE TABLE transportation.routes ( route_id.text, route_number.text, description.text, origin_location_id.text, destination_location_id.text, distance_km.numeric, estimated_duration_minutes.integer, type.text )\nCREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens where the price is greater than $0.10."}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply FROM token_metas tm WHERE tm.is_erc20 = 1 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "I think there's a typo in your query - it should be 'total_supply' not 'total_supply'. Also, can you join this with the token_prices_latest table to include the current price of each token?"}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}, {"role": "user", "content": "The token_prices_latest table isn't in the schema. Can you modify the query to use the erc20_balances table instead to show the total balance held across all wallets for each token?"}, {"role": "assistant", "content": "SELECT tm.name, tm.contract_address, tm.total_supply, SUM(CAST(eb.amount AS decimal)) AS total_balance FROM token_metas tm JOIN erc20_balances eb ON tm.contract_address = eb.contract_address WHERE tm.is_erc20 = 1 GROUP BY tm.name, tm.contract_address, tm.total_supply ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas (\n block_timestamp timestamp(6) NOT NULL, -- Timestamp of the block when token metadata was recorded\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n transaction_hash varchar NOT NULL, -- Hash value of the transaction\n transaction_index bigint NOT NULL, -- Index of the transaction within the block\n from_address varchar NOT NULL, -- Address from which the transaction originated\n contract_address varchar NOT NULL, -- Address of the token contract\n symbol varchar NOT NULL, -- Symbol of the token\n total_supply varchar NOT NULL, -- erc20 contract total supply\n name varchar NOT NULL, -- Name of the token\n decimals bigint NOT NULL, -- Number of decimal places for the token\n is_erc20 integer NOT NULL, -- Flag indicating if the token is an ERC-20 token (0 or 1)\n is_erc721 integer NOT NULL, -- Flag indicating if the token is an ERC-721 token (0 or 1)\n is_erc1155 integer NOT NULL, -- Flag indicating if the token is an ERC-1155 token (0 or 1)\n is_proxy integer NOT NULL, -- Flag indicating if the token is a proxy (0 or 1)\n extra_info varchar NOT NULL, -- Additional information about the token\n pk integer NOT NULL -- Partition key for the table(floor(block_number / 5760))\n)\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- Number of held NFTs\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar NOT NULL, -- mint | transfer | burn\n tick varchar NOT NULL, -- Token tick\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Mint amount\n from_address varchar(42) NOT NULL, -- Address sending the inscription (matches from_address in transactions table)\n to_address varchar(42) NOT NULL -- Address receiving the inscription (match to_address in transactions table)\n)\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\n"} {"conversations": [{"role": "user", "content": "For all chains, which token held by centralized exchanges (CEX) has the highest ROI according to smart money token performance? Show token symbol, chain, exchange, total USD value held on CEX, and the smart money ROI."}, {"role": "assistant", "content": "SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi\nFROM cex_token_balance c\nJOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\nGROUP BY c.token_symbol, c.chain, c.exchange, s.roi\nORDER BY s.roi DESC\nLIMIT 1;"}, {"role": "user", "content": "Instead of just the top one, show the top 3 tokens by ROI, and only include cases where the total USD value held on CEX is greater than $2,000,000."}, {"role": "assistant", "content": "SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi\nFROM cex_token_balance c\nJOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\nGROUP BY c.token_symbol, c.chain, c.exchange, s.roi\nHAVING SUM(c.usd_value) > 2000000\nORDER BY s.roi DESC\nLIMIT 3;"}, {"role": "user", "content": "Add the last recorded price for each token, and sort by total_usd_value in descending order."}, {"role": "assistant", "content": "SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi, MAX(c.price) AS last_price\nFROM cex_token_balance c\nJOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\nGROUP BY c.token_symbol, c.chain, c.exchange, s.roi\nHAVING SUM(c.usd_value) > 2000000\nORDER BY total_usd_value DESC\nLIMIT 3;"}, {"role": "user", "content": "I got duplicate tokens across exchanges. Can you show only the top exchange (with the greatest USD value) per token and chain combination?"}, {"role": "assistant", "content": "WITH cex_totals AS (\n SELECT c.token_symbol, c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, s.roi, MAX(c.price) AS last_price,\n ROW_NUMBER() OVER (PARTITION BY c.token_symbol, c.chain ORDER BY SUM(c.usd_value) DESC) as rn\n FROM cex_token_balance c\n JOIN smart_money_token_performance s ON c.token_symbol = s.token_symbol AND c.chain = s.chain\n GROUP BY c.token_symbol, c.chain, c.exchange, s.roi\n HAVING SUM(c.usd_value) > 2000000\n)\nSELECT token_symbol, chain, exchange, total_usd_value, roi, last_price\nFROM cex_totals\nWHERE rn = 1\nORDER BY total_usd_value DESC\nLIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, top_3_coins text, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, market_cap double precision, volume_24h double precision, trend_rank bigint, token_num bigint )\nCREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, chain character varying(128) NOT NULL, address character varying(128) NOT NULL, exchange character varying(512) NOT NULL, token_address character varying(128) NOT NULL, token_symbol character varying(512), balance numeric(38,10), usd_value numeric(38,14), price double precision )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, token_symbol character varying(100), token_amount numeric(38,2), usd_value numeric(38,2), avg_price numeric(38,6), type int, address_amount integer, narrative character varying(100), chain character varying(100) )\n"} {"conversations": [{"role": "user", "content": "Can you provide a breakdown of total and average account balance by account_type and currency for each account status?"}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance\nFROM financial_services.accounts\nGROUP BY account_type, currency, status;"}, {"role": "user", "content": "Could you include the minimum and maximum interest rate for each group as well?"}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance, MIN(interest_rate) AS min_interest_rate, MAX(interest_rate) AS max_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, currency, status;"}, {"role": "user", "content": "Only show groups where the total_accounts is greater than 20."}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance, MIN(interest_rate) AS min_interest_rate, MAX(interest_rate) AS max_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, currency, status\nHAVING COUNT(*) > 20;"}, {"role": "user", "content": "Please sort the results by average_balance in descending order."}, {"role": "assistant", "content": "SELECT account_type, currency, status, COUNT(*) AS total_accounts, SUM(balance) AS total_balance, AVG(balance) AS average_balance, MIN(interest_rate) AS min_interest_rate, MAX(interest_rate) AS max_interest_rate\nFROM financial_services.accounts\nGROUP BY account_type, currency, status\nHAVING COUNT(*) > 20\nORDER BY average_balance DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts (\n account_id character varying(64) NOT NULL, -- unique identifier for the account\n customer_id character varying(64) NOT NULL, -- foreign key linking to the customer\n account_number character varying(128) NOT NULL UNIQUE, -- unique account number visible to customer\n account_type character varying(50) NOT NULL, -- e.g., Checking, Savings, Investment, Loan, Credit Card\n balance numeric(19, 4) NOT NULL DEFAULT 0.00, -- current account balance\n currency character varying(3) NOT NULL, -- currency code (e.g., USD, EUR)\n opened_date date NOT NULL, -- date the account was opened\n status character varying(32) NOT NULL, -- e.g., Open, Closed, Frozen\n interest_rate numeric(5, 4), -- annual interest rate, if applicable\n last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last account update\n PRIMARY KEY (account_id),\n FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id)\n)\n"} {"conversations": [{"role": "user", "content": "List all events and any token transfers that occurred in the same transaction, showing event_id, event_name, transfer_id, and token_symbol."}, {"role": "assistant", "content": "SELECT\n e.event_id,\n e.event_name,\n tt.transfer_id,\n tk.token_symbol\nFROM web3.events e\nLEFT JOIN web3.token_transfers tt\n ON e.transaction_id = tt.transaction_id\nLEFT JOIN web3.tokens tk\n ON tt.token_id = tk.token_id\nORDER BY e.transaction_id, e.log_index;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\nCREATE TABLE web3.events ( event_id.text, contract_id.text, event_name.text, data.text, emitted_at.timestamp, transaction_id.text, log_index.integer )\nCREATE TABLE web3.tokens (\n token_id character varying(64) NOT NULL, -- unique identifier for the token\n contract_address character varying(128) NOT NULL, -- address of the token contract\n token_name character varying(128) NOT NULL, -- name of the token\n token_symbol character varying(32) NOT NULL, -- symbol of the token\n decimals integer NOT NULL, -- number of decimals for the token\n total_supply numeric(38,14) NOT NULL, -- total supply of the token\n PRIMARY KEY (token_id)\n)\nCREATE TABLE web3.token_transfers ( transfer_id text PRIMARY KEY, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index int )\nCREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show the total transaction amount for each customer, including their full name and risk profile. Join customers to accounts and then to transactions."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile;"}, {"role": "user", "content": "Filter this report to only include transactions from the last 90 days."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile;"}, {"role": "user", "content": "Also, only include customers whose total transaction amount in this period exceeds 1000."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile\nHAVING\n SUM(T1.amount) > 1000;"}, {"role": "user", "content": "Sort the results by total transaction amount in descending order and limit to the top 10 customers."}, {"role": "assistant", "content": "SELECT\n T2.first_name,\n T2.last_name,\n T2.risk_profile,\n SUM(T1.amount) AS total_transaction_amount\nFROM financial_services.transactions AS T1\nINNER JOIN financial_services.accounts AS T3\n ON T1.account_id = T3.account_id\nINNER JOIN financial_services.customers AS T2\n ON T3.customer_id = T2.customer_id\nWHERE\n T1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\nGROUP BY\n T2.customer_id,\n T2.first_name,\n T2.last_name,\n T2.risk_profile\nHAVING\n SUM(T1.amount) > 1000\nORDER BY\n total_transaction_amount DESC\nLIMIT 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.securities ( security_id.text, ticker_symbol.text, isin_code.text, cusip_code.text, security_name.text, security_type.text, exchange.text, currency.text, issuer_name.text, sector.text, last_updated.timestamp )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data ( data_point_id.bigint, security_id.text, data_timestamp.timestamp, open_price.numeric, high_price.numeric, low_price.numeric, close_price.numeric, adjusted_close_price.numeric, volume.bigint, source.text )\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me the average difficulty for blocks that have a previous block versus those that don't have a previous block."}, {"role": "assistant", "content": "SELECT \n CASE WHEN previous_block_id IS NULL THEN 'No Previous Block' ELSE 'Has Previous Block' END AS block_type,\n AVG(difficulty) AS average_difficulty\nFROM blockchain.blocks\nGROUP BY block_type;"}, {"role": "user", "content": "Now break this down further by year, showing the yearly averages for each block type."}, {"role": "assistant", "content": "SELECT \n EXTRACT(YEAR FROM timestamp) AS year,\n CASE WHEN previous_block_id IS NULL THEN 'No Previous Block' ELSE 'Has Previous Block' END AS block_type,\n AVG(difficulty) AS average_difficulty\nFROM blockchain.blocks\nGROUP BY year, block_type\nORDER BY year, block_type;"}, {"role": "user", "content": "Can you also include the count of blocks for each year and type combination?"}, {"role": "assistant", "content": "SELECT \n EXTRACT(YEAR FROM timestamp) AS year,\n CASE WHEN previous_block_id IS NULL THEN 'No Previous Block' ELSE 'Has Previous Block' END AS block_type,\n COUNT(*) AS block_count,\n AVG(difficulty) AS average_difficulty\nFROM blockchain.blocks\nGROUP BY year, block_type\nORDER BY year, block_type;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer )\n"} {"conversations": [{"role": "user", "content": "Find the diagnosis code and description for all non-chronic diagnoses for patient 'patient_789' made by doctor 'doctor_abc'."}, {"role": "assistant", "content": "SELECT diagnosis_code, description FROM healthcare.diagnoses WHERE patient_id = 'patient_789' AND doctor_id = 'doctor_abc' AND is_chronic = false;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\n"} {"conversations": [{"role": "user", "content": "I want to find total PNL and average ROI of smart money token performance for each narrative category. Only include narratives with average ROI greater than 0.5."}, {"role": "assistant", "content": "SELECT bi.narrative,\n SUM(smtp.pnl) AS total_pnl,\n AVG(smtp.roi) AS avg_roi\nFROM smart_money_token_performance AS smtp\nJOIN token_basic_info AS bi\n ON smtp.token_symbol = bi.token_symbol\nGROUP BY bi.narrative\nHAVING AVG(smtp.roi) > 0.5;"}, {"role": "user", "content": "Exclude narratives with total net_flow below zero and show only the top 3 narratives by total PNL."}, {"role": "assistant", "content": "SELECT bi.narrative,\n SUM(smtp.pnl) AS total_pnl,\n AVG(smtp.roi) AS avg_roi,\n SUM(smtp.net_flow) AS total_net_flow\nFROM smart_money_token_performance AS smtp\nJOIN token_basic_info AS bi\n ON smtp.token_symbol = bi.token_symbol\nGROUP BY bi.narrative\nHAVING AVG(smtp.roi) > 0.5\n AND SUM(smtp.net_flow) >= 0\nORDER BY total_pnl DESC\nLIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )\nCREATE TABLE token_basic_info ( coin_id.text, token_name.text, token_symbol.text, token_address.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, highest_price_24h.numeric, lowest_price_24h.numeric, market_cap.numeric, market_cap_rank.numeric, market_cap_change_percentage_24h.text, total_volume.text, narrative.text, trend_rank.numeric )\nCREATE TABLE token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )\nCREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\nCREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )\n"} {"conversations": [{"role": "user", "content": "Give me the count of clients who registered in each month of 2023."}, {"role": "assistant", "content": "SELECT TO_CHAR(date_registered, 'YYYY-MM') AS reg_month, COUNT(*) AS client_count FROM legal_services.clients WHERE date_registered BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY TO_CHAR(date_registered, 'YYYY-MM') ORDER BY reg_month;"}, {"role": "user", "content": "Filter to show only months with more than five registrations."}, {"role": "assistant", "content": "SELECT TO_CHAR(date_registered, 'YYYY-MM') AS reg_month, COUNT(*) AS client_count FROM legal_services.clients WHERE date_registered BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY TO_CHAR(date_registered, 'YYYY-MM') HAVING COUNT(*) > 5 ORDER BY reg_month;"}, {"role": "user", "content": "Can you include the average days since registration for those clients up to today?"}, {"role": "assistant", "content": "SELECT TO_CHAR(date_registered, 'YYYY-MM') AS reg_month, COUNT(*) AS client_count, ROUND(AVG((CURRENT_DATE - date_registered)::INT), 2) AS avg_days_since_registration FROM legal_services.clients WHERE date_registered BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY TO_CHAR(date_registered, 'YYYY-MM') HAVING COUNT(*) > 5;"}, {"role": "user", "content": "Now order the results by avg_days_since_registration descending."}, {"role": "assistant", "content": "SELECT TO_CHAR(date_registered, 'YYYY-MM') AS reg_month, COUNT(*) AS client_count, ROUND(AVG((CURRENT_DATE - date_registered)::INT), 2) AS avg_days_since_registration FROM legal_services.clients WHERE date_registered BETWEEN '2023-01-01' AND '2023-12-31' GROUP BY TO_CHAR(date_registered, 'YYYY-MM') HAVING COUNT(*) > 5 ORDER BY avg_days_since_registration DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) )\n"} {"conversations": [{"role": "user", "content": "For all claims, show the claim ID, policy ID, incident date, status, and the claim handler ID, only for claims that have both an estimated loss and a settlement amount over 5000."}, {"role": "assistant", "content": "SELECT claim_id, policy_id, incident_date, status, claim_handler_id\nFROM insurance.claims\nWHERE estimated_loss > 5000 AND settlement_amount > 5000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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)\n"} {"conversations": [{"role": "user", "content": "Show me the total quantity and total price for each service ordered by each guest."}, {"role": "assistant", "content": "SELECT guest_id, service_id, SUM(quantity) AS total_quantity, SUM(total_price) AS total_price FROM hospitality_technology.service_orders GROUP BY guest_id, service_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 the message_id, content, sender's username, and group_name for all messages in group chats."}, {"role": "assistant", "content": "SELECT m.message_id, m.content, u.username, c.group_name\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 c.is_group_chat = TRUE;"}, {"role": "user", "content": "Exclude group chats that have fewer than 3 participants."}, {"role": "assistant", "content": "SELECT m.message_id, m.content, u.username, c.group_name\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\nJOIN (\n SELECT conversation_id\n FROM social_media.conversation_participants\n GROUP BY conversation_id\n HAVING COUNT(*) >= 3\n) cp ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = TRUE;"}, {"role": "user", "content": "And only show messages sent after '2024-06-01', ordering by sent_at ascending."}, {"role": "assistant", "content": "SELECT m.message_id, m.content, u.username, c.group_name\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\nJOIN (\n SELECT conversation_id\n FROM social_media.conversation_participants\n GROUP BY conversation_id\n HAVING COUNT(*) >= 3\n) cp ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = TRUE\n AND m.sent_at > '2024-06-01'\nORDER BY m.sent_at ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "List the trip ID, route number, vehicle ID, and the total fuel cost associated with each trip."}, {"role": "assistant", "content": "SELECT t.trip_id, r.route_number, t.vehicle_id, SUM(fl.total_cost) AS total_fuel_cost FROM transportation.trips t JOIN transportation.routes r ON t.route_id = r.route_id JOIN transportation.fuel_logs fl ON t.trip_id = fl.trip_id GROUP BY t.trip_id, r.route_number, t.vehicle_id;"}, {"role": "user", "content": "Only include trips where the total fuel cost is greater than 1000."}, {"role": "assistant", "content": "SELECT t.trip_id, r.route_number, t.vehicle_id, SUM(fl.total_cost) AS total_fuel_cost FROM transportation.trips t JOIN transportation.routes r ON t.route_id = r.route_id JOIN transportation.fuel_logs fl ON t.trip_id = fl.trip_id GROUP BY t.trip_id, r.route_number, t.vehicle_id HAVING SUM(fl.total_cost) > 1000;"}, {"role": "user", "content": "Also, order the results by total fuel cost in descending order."}, {"role": "assistant", "content": "SELECT t.trip_id, r.route_number, t.vehicle_id, SUM(fl.total_cost) AS total_fuel_cost FROM transportation.trips t JOIN transportation.routes r ON t.route_id = r.route_id JOIN transportation.fuel_logs fl ON t.trip_id = fl.trip_id GROUP BY t.trip_id, r.route_number, t.vehicle_id HAVING SUM(fl.total_cost) > 1000 ORDER BY total_fuel_cost DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.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": "What is the total market cap for all tokens listed on the 'Polygon' chain?"}, {"role": "assistant", "content": "SELECT SUM(market_cap) FROM token_dexpool_info WHERE chain = 'Polygon';"}, {"role": "user", "content": "Only sum the market cap for tokens on 'Polygon' that have a 24-hour volume greater than 500000."}, {"role": "assistant", "content": "SELECT SUM(market_cap) FROM token_dexpool_info WHERE chain = 'Polygon' AND volume_24h > 500000;"}, {"role": "user", "content": "Also show the number of unique tokens that meet these criteria."}, {"role": "assistant", "content": "SELECT COUNT(DISTINCT token_symbol), SUM(market_cap) FROM token_dexpool_info WHERE chain = 'Polygon' AND volume_24h > 500000;"}, {"role": "user", "content": "Can you show the total market cap and token count for *each* chain that meets these volume criteria, ordered by total market cap descending?"}, {"role": "assistant", "content": "SELECT chain, COUNT(DISTINCT token_symbol) AS token_count, SUM(market_cap) AS total_market_cap FROM token_dexpool_info WHERE volume_24h > 500000 GROUP BY chain ORDER BY total_market_cap DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n"} {"conversations": [{"role": "user", "content": "For each guest, list reservation_id, guest_id, check_in_date, and the next reservation_id and its check_in_date."}, {"role": "assistant", "content": "SELECT r1.reservation_id,\n r1.guest_id,\n r1.check_in_date,\n r2.reservation_id AS next_reservation_id,\n r2.check_in_date AS next_check_in_date\nFROM reservations r1\nLEFT JOIN reservations r2\n ON r1.guest_id = r2.guest_id\n AND r2.check_in_date = (\n SELECT MIN(check_in_date)\n FROM reservations\n WHERE guest_id = r1.guest_id\n AND check_in_date > r1.check_in_date\n );"}, {"role": "user", "content": "Only include guests who have at least two reservations."}, {"role": "assistant", "content": "SELECT r1.reservation_id,\n r1.guest_id,\n r1.check_in_date,\n r2.reservation_id AS next_reservation_id,\n r2.check_in_date AS next_check_in_date\nFROM reservations r1\nLEFT JOIN reservations r2\n ON r1.guest_id = r2.guest_id\n AND r2.check_in_date = (\n SELECT MIN(check_in_date)\n FROM reservations\n WHERE guest_id = r1.guest_id\n AND check_in_date > r1.check_in_date\n )\nWHERE r1.guest_id IN (\n SELECT guest_id\n FROM reservations\n GROUP BY guest_id\n HAVING COUNT(*) >= 2\n);"}, {"role": "user", "content": "Also, only show next reservations that occur within 30 days of the current reservation."}, {"role": "assistant", "content": "SELECT r1.reservation_id,\n r1.guest_id,\n r1.check_in_date,\n r2.reservation_id AS next_reservation_id,\n r2.check_in_date AS next_check_in_date\nFROM reservations r1\nLEFT JOIN reservations r2\n ON r1.guest_id = r2.guest_id\n AND r2.check_in_date = (\n SELECT MIN(check_in_date)\n FROM reservations\n WHERE guest_id = r1.guest_id\n AND check_in_date > r1.check_in_date\n )\n AND r2.check_in_date <= r1.check_in_date + INTERVAL '30 days'\nWHERE r1.guest_id IN (\n SELECT guest_id\n FROM reservations\n GROUP BY guest_id\n HAVING COUNT(*) >= 2\n);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.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": "Show me all bookings for trips going to locations in 'California' state, including the passenger's first name, last name, booking_id, and the city of the destination."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, b.booking_id, l.city AS destination_city\nFROM transportation.bookings b\nJOIN transportation.passengers p ON b.passenger_id = p.passenger_id\nJOIN transportation.trips t ON b.trip_id = t.trip_id\nJOIN transportation.locations l ON t.destination_location_id = l.location_id\nWHERE l.state_province = 'California';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the location\n name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)\n type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address\n address_line1 character varying(255), -- street address\n city character varying(128), -- city name\n state_province character varying(128), -- state or province\n postal_code character varying(32), -- postal code\n country character varying(64) NOT NULL, -- country name\n latitude numeric(9, 6), -- geographic latitude\n longitude numeric(9, 6), -- geographic longitude\n timezone character varying(64), -- IANA timezone name (e.g., America/New_York)\n PRIMARY KEY (location_id)\n)\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": "Find all users whose usernames contain numbers and have email addresses from either Gmail or Yahoo."}, {"role": "assistant", "content": "SELECT user_id, username, email FROM blockchain.users WHERE username ~ '[0-9]' AND (email LIKE '%@gmail.com' OR email LIKE '%@yahoo.com');"}, {"role": "user", "content": "Now, order these results by username length in descending order."}, {"role": "assistant", "content": "SELECT user_id, username, email FROM blockchain.users WHERE username ~ '[0-9]' AND (email LIKE '%@gmail.com' OR email LIKE '%@yahoo.com') ORDER BY LENGTH(username) DESC;"}, {"role": "user", "content": "Can you modify this to only show the top 5 longest usernames?"}, {"role": "assistant", "content": "SELECT user_id, username, email FROM blockchain.users WHERE username ~ '[0-9]' AND (email LIKE '%@gmail.com' OR email LIKE '%@yahoo.com') ORDER BY LENGTH(username) DESC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.nodes ( node_id text, ip_address text, port integer, last_seen timestamp )\nCREATE TABLE blockchain.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 PRIMARY KEY (user_id)\n)\n"} {"conversations": [{"role": "user", "content": "Show me all properties in California with a star rating above 4.0, along with the names of their managers and the count of active staff members at each property."}, {"role": "assistant", "content": "SELECT p.property_name, p.star_rating, s.first_name || ' ' || s.last_name AS manager_name, COUNT(st.staff_id) AS active_staff_count FROM hospitality_technology.properties p JOIN hospitality_technology.staff s ON p.manager_staff_id = s.staff_id JOIN hospitality_technology.staff st ON p.property_id = st.property_id WHERE p.state_province = 'California' AND p.star_rating > 4.0 AND st.is_active = true GROUP BY p.property_name, p.star_rating, manager_name ORDER BY active_staff_count DESC;"}, {"role": "user", "content": "Now, include only properties with more than 5 active staff members and show the average star rating of reviews for each property."}, {"role": "assistant", "content": "SELECT p.property_name, p.star_rating, s.first_name || ' ' || s.last_name AS manager_name, COUNT(st.staff_id) AS active_staff_count, AVG(r.rating_overall) AS avg_review_rating FROM hospitality_technology.properties p JOIN hospitality_technology.staff s ON p.manager_staff_id = s.staff_id JOIN hospitality_technology.staff st ON p.property_id = st.property_id LEFT JOIN hospitality_technology.reviews r ON p.property_id = r.property_id WHERE p.state_province = 'California' AND p.star_rating > 4.0 AND st.is_active = true GROUP BY p.property_name, p.star_rating, manager_name HAVING COUNT(st.staff_id) > 5 ORDER BY active_staff_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( 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.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, position character varying(100) NOT NULL, work_email character varying(255) UNIQUE, work_phone character varying(30), hire_date date NOT NULL, termination_date date, is_active boolean NOT NULL DEFAULT true, access_level integer NOT NULL, manager_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (staff_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.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 patients who have non-primary insurance plans from providers containing 'Care' in their name, including the policy number and expiration date."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.expiration_date FROM healthcare.patient_insurance pi JOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id WHERE pi.is_primary = false AND ip.insurance_provider LIKE '%Care%';"}, {"role": "user", "content": "Actually, I need to see only those plans that will expire within the next 90 days."}, {"role": "assistant", "content": "SELECT pi.patient_id, pi.policy_number, pi.expiration_date FROM healthcare.patient_insurance pi JOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id WHERE pi.is_primary = false AND ip.insurance_provider LIKE '%Care%' AND pi.expiration_date BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL '90 days');"}, {"role": "user", "content": "Can you also include the insurance provider name in the results?"}, {"role": "assistant", "content": "SELECT pi.patient_id, ip.insurance_provider, pi.policy_number, pi.expiration_date FROM healthcare.patient_insurance pi JOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id WHERE pi.is_primary = false AND ip.insurance_provider LIKE '%Care%' AND pi.expiration_date BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL '90 days');"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, 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": "Show me the count of approval-for-all events for each ERC1155 contract."}, {"role": "assistant", "content": "SELECT contract_address, COUNT(*) AS approval_count FROM erc1155_approval_for_all GROUP BY contract_address;"}, {"role": "user", "content": "Now only include contracts with an approval_count greater than 10 and order by approval_count descending."}, {"role": "assistant", "content": "SELECT contract_address, COUNT(*) AS approval_count FROM erc1155_approval_for_all GROUP BY contract_address HAVING COUNT(*) > 10 ORDER BY approval_count DESC;"}, {"role": "user", "content": "Can you provide the number of distinct wallet addresses currently holding NFTs for each of these contracts?"}, {"role": "assistant", "content": "SELECT ea.contract_address, COUNT(*) AS approval_count, COUNT(DISTINCT nh.wallet_address) AS holder_count FROM erc1155_approval_for_all ea JOIN nft_holders nh ON ea.contract_address = nh.contract_address GROUP BY ea.contract_address HAVING COUNT(*) > 10 ORDER BY approval_count DESC;"}, {"role": "user", "content": "Include only those contracts where the holder_count is greater than 20 and show the top 3 by approval_count."}, {"role": "assistant", "content": "SELECT ea.contract_address, COUNT(*) AS approval_count, COUNT(DISTINCT nh.wallet_address) AS holder_count FROM erc1155_approval_for_all ea JOIN nft_holders nh ON ea.contract_address = nh.contract_address GROUP BY ea.contract_address HAVING COUNT(*) > 10 AND COUNT(DISTINCT nh.wallet_address) > 20 ORDER BY approval_count DESC LIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "How many service locations do we have in each state?"}, {"role": "assistant", "content": "SELECT state, COUNT(*) AS location_count FROM government_services.service_locations GROUP BY state;"}, {"role": "user", "content": "Only show states where there are at least 3 locations."}, {"role": "assistant", "content": "SELECT state, COUNT(*) AS location_count FROM government_services.service_locations GROUP BY state HAVING COUNT(*) >= 3;"}, {"role": "user", "content": "Can you also show the number of accessible locations in each of those states?"}, {"role": "assistant", "content": "SELECT state, COUNT(*) AS location_count, SUM(CASE WHEN is_accessible = TRUE THEN 1 ELSE 0 END) AS accessible_location_count FROM government_services.service_locations GROUP BY state HAVING COUNT(*) >= 3;"}, {"role": "user", "content": "Order the results by accessible location count in descending order."}, {"role": "assistant", "content": "SELECT state, COUNT(*) AS location_count, SUM(CASE WHEN is_accessible = TRUE THEN 1 ELSE 0 END) AS accessible_location_count FROM government_services.service_locations GROUP BY state HAVING COUNT(*) >= 3 ORDER BY accessible_location_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Find all users who have placed buy orders but never sell orders, along with their email addresses."}, {"role": "assistant", "content": "SELECT DISTINCT u.user_id, u.email FROM trading_platform.users u JOIN trading_platform.orders o ON u.user_id = o.user_id WHERE o.order_type = 'buy' AND u.user_id NOT IN (SELECT DISTINCT user_id FROM trading_platform.orders WHERE order_type = 'sell');"}, {"role": "user", "content": "Now modify the query to include the total quantity of assets they've ordered and the average order price."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, SUM(o.quantity) AS total_quantity, AVG(o.price) AS avg_price FROM trading_platform.users u JOIN trading_platform.orders o ON u.user_id = o.user_id WHERE o.order_type = 'buy' AND u.user_id NOT IN (SELECT DISTINCT user_id FROM trading_platform.orders WHERE order_type = 'sell') GROUP BY u.user_id, u.email;"}, {"role": "user", "content": "Actually, I want to see only users who have placed more than 5 buy orders and have a total order quantity over 100."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, SUM(o.quantity) AS total_quantity, AVG(o.price) AS avg_price, COUNT(o.order_id) AS order_count FROM trading_platform.users u JOIN trading_platform.orders o ON u.user_id = o.user_id WHERE o.order_type = 'buy' AND u.user_id NOT IN (SELECT DISTINCT user_id FROM trading_platform.orders WHERE order_type = 'sell') GROUP BY u.user_id, u.email HAVING COUNT(o.order_id) > 5 AND SUM(o.quantity) > 100;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\nCREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) )\nCREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )\n"} {"conversations": [{"role": "user", "content": "For each wallet, find the next wallet created by the same user. Return the user_id, the earlier wallet_id, the later wallet_id, and the time difference in minutes between their creation times."}, {"role": "assistant", "content": "SELECT user_id,\n wallet_id AS first_wallet_id,\n next_wallet_id,\n EXTRACT(EPOCH FROM (next_created_at - created_at)) / 60 AS minutes_diff\nFROM (\n SELECT wallet_id,\n user_id,\n created_at,\n LEAD(wallet_id) OVER (PARTITION BY user_id ORDER BY created_at) AS next_wallet_id,\n LEAD(created_at) OVER (PARTITION BY user_id ORDER BY created_at) AS next_created_at\n FROM web3.wallets\n) sub\nWHERE next_wallet_id IS NOT NULL;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me all properties in California with a star rating above 4.0, along with the count of available rooms at each property."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, p.city, p.star_rating, COUNT(r.room_id) AS available_rooms_count FROM hospitality_technology.properties p LEFT JOIN hospitality_technology.rooms r ON p.property_id = r.property_id WHERE p.state_province = 'California' AND p.star_rating > 4.0 AND r.status = 'available' GROUP BY p.property_id, p.property_name, p.city, p.star_rating ORDER BY available_rooms_count DESC;"}, {"role": "user", "content": "Now, include only properties with more than 10 available rooms and show the average base rate of their room types."}, {"role": "assistant", "content": "SELECT p.property_id, p.property_name, p.city, p.star_rating, COUNT(r.room_id) AS available_rooms_count, AVG(rt.base_rate) AS avg_base_rate FROM hospitality_technology.properties p LEFT JOIN hospitality_technology.rooms r ON p.property_id = r.property_id LEFT JOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id WHERE p.state_province = 'California' AND p.star_rating > 4.0 AND r.status = 'available' GROUP BY p.property_id, p.property_name, p.city, p.star_rating HAVING COUNT(r.room_id) > 10 ORDER BY available_rooms_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id character varying(64) NOT NULL, property_name character varying(255) NOT NULL, address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state_province character varying(100), postal_code character varying(20) NOT NULL, country_code character varying(3) NOT NULL, phone_number character varying(30), email_address character varying(255), property_type character varying(50) NOT NULL, star_rating numeric(2,1), timezone character varying(64) NOT NULL, manager_staff_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (property_id) )\nCREATE TABLE hospitality_technology.rooms ( room_id 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.guests ( guest_id text, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id.text, property_id.text, guest_id.text, room_id.text, room_type_id.text, check_in_date.date, check_out_date.date, actual_check_in_ts.timestamp, actual_check_out_ts.timestamp, num_adults.integer, num_children.integer, status.text, booking_source.text, rate_plan_id.text, total_amount.numeric, amount_paid.numeric, special_requests.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.service_orders ( order_id 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.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 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 available services and their categories that have an average processing time above 7 days."}, {"role": "assistant", "content": "SELECT service_name, category\nFROM government_services.services\nWHERE is_active = true AND average_processing_time_days > 7;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "List all trades (trade_id, security_id, quantity) where the settlement_date is within the last 30 days and the trade_type is 'Sell', along with the account_id and total_amount."}, {"role": "assistant", "content": "SELECT trade_id, security_id, quantity, account_id, total_amount FROM financial_services.trades WHERE settlement_date >= CURRENT_DATE - INTERVAL '30 days' AND trade_type = 'Sell';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.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 )\n"} {"conversations": [{"role": "user", "content": "Show the total hours spent by each lawyer across all their time entries. Display the lawyer's first name, last name, and the total hours."}, {"role": "assistant", "content": "SELECT l.first_name, l.last_name, SUM(te.hours_spent) AS total_hours FROM legal_services.time_entries te JOIN legal_services.lawyers l ON te.lawyer_id = l.lawyer_id GROUP BY l.lawyer_id, l.first_name, l.last_name ORDER BY total_hours DESC;"}, {"role": "user", "content": "Modify the previous query to only include time entries that are marked as billable."}, {"role": "assistant", "content": "SELECT l.first_name, l.last_name, SUM(te.hours_spent) AS total_billable_hours FROM legal_services.time_entries te JOIN legal_services.lawyers l ON te.lawyer_id = l.lawyer_id WHERE te.is_billable = true GROUP BY l.lawyer_id, l.first_name, l.last_name ORDER BY total_billable_hours DESC;"}, {"role": "user", "content": "Now, filter the results to only show lawyers who are partners and have logged more than 100 billable hours in total."}, {"role": "assistant", "content": "SELECT l.first_name, l.last_name, SUM(te.hours_spent) AS total_billable_hours FROM legal_services.time_entries te JOIN legal_services.lawyers l ON te.lawyer_id = l.lawyer_id WHERE te.is_billable = true AND l.is_partner = true GROUP BY l.lawyer_id, l.first_name, l.last_name HAVING SUM(te.hours_spent) > 100 ORDER BY total_billable_hours DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers (\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 (\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)\n"} {"conversations": [{"role": "user", "content": "Can you list each developer's name along with the number of games they have published by joining developers and games?"}, {"role": "assistant", "content": "SELECT d.name AS developer_name,\n COUNT(g.game_id) AS games_published\nFROM gaming_technology.developers d\nLEFT JOIN gaming_technology.games g\n ON d.developer_id = g.developer_id\nGROUP BY d.name;"}, {"role": "user", "content": "Also, only include developers who have published more than 3 games and show the latest release_date of their games."}, {"role": "assistant", "content": "SELECT d.name AS developer_name,\n COUNT(g.game_id) AS games_published,\n MAX(g.release_date) AS latest_release\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g\n ON d.developer_id = g.developer_id\nGROUP BY d.name\nHAVING COUNT(g.game_id) > 3\nORDER BY latest_release DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid, 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.games ( game_id uuid, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\n"} {"conversations": [{"role": "user", "content": "I need the average capacity of vehicles for each fuel_type."}, {"role": "assistant", "content": "SELECT fuel_type,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type;"}, {"role": "user", "content": "Only include fuel types where the vehicle count is at least 10."}, {"role": "assistant", "content": "SELECT fuel_type,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Also show the number of vehicles for each of these fuel types."}, {"role": "assistant", "content": "SELECT fuel_type,\n COUNT(*) AS vehicle_count,\n AVG(capacity) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}, {"role": "user", "content": "Please round avg_capacity to one decimal place."}, {"role": "assistant", "content": "SELECT fuel_type,\n COUNT(*) AS vehicle_count,\n ROUND(AVG(capacity)::numeric, 1) AS avg_capacity\nFROM transportation.vehicles\nGROUP BY fuel_type\nHAVING COUNT(*) >= 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\n"} {"conversations": [{"role": "user", "content": "Show all SUI coin types with more than 6 decimals and status 'exists' in the metadata table."}, {"role": "assistant", "content": "SELECT coin_type, symbol, name, decimals\nFROM sui_coins_metadata\nWHERE status = 'exists' AND decimals > 6;"}, {"role": "user", "content": "For each of these, can you show the total balance across all owners by joining sui_coins?"}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, SUM(sc.balance) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND sc.status = 'exists' AND scm.decimals > 6\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals;"}, {"role": "user", "content": "Limit the result to the top 5 coin types by total_balance."}, {"role": "assistant", "content": "SELECT scm.coin_type, scm.symbol, scm.name, scm.decimals, SUM(sc.balance) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'exists' AND sc.status = 'exists' AND scm.decimals > 6\nGROUP BY scm.coin_type, scm.symbol, scm.name, scm.decimals\nORDER BY total_balance DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE 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 nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\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 the appointment ID, start time, and the case number for all appointments that are linked to a case."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.start_time, T2.case_number FROM legal_services.appointments AS T1 JOIN legal_services.cases AS T2 ON T1.case_id = T2.case_id"}, {"role": "user", "content": "Refine this to only show appointments with status 'completed' associated with cases with status 'Closed'."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.start_time, T2.case_number FROM legal_services.appointments AS T1 JOIN legal_services.cases AS T2 ON T1.case_id = T2.case_id WHERE T1.status = 'completed' AND T2.status = 'Closed'"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.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 product_id, product_name, and base_premium for the five most recently created active insurance products."}, {"role": "assistant", "content": "SELECT product_id, product_name, base_premium\nFROM insurance.insurance_products\nWHERE is_active = true\nORDER BY created_at DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.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 number of bookings for each day."}, {"role": "assistant", "content": "SELECT DATE(booking_time) AS booking_date, COUNT(*) AS booking_count\nFROM transportation.bookings\nGROUP BY DATE(booking_time);\n"}, {"role": "user", "content": "Now only include days where booking_count > 10."}, {"role": "assistant", "content": "SELECT DATE(booking_time) AS booking_date, COUNT(*) AS booking_count\nFROM transportation.bookings\nGROUP BY DATE(booking_time)\nHAVING COUNT(*) > 10;\n"}, {"role": "user", "content": "Also include the total fare collected for those days."}, {"role": "assistant", "content": "SELECT DATE(booking_time) AS booking_date,\n COUNT(*) AS booking_count,\n SUM(fare) AS total_fare\nFROM transportation.bookings\nGROUP BY DATE(booking_time)\nHAVING COUNT(*) > 10;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.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 subjects and start times of all appointments for a specific client, along with the assigned lawyer ID."}, {"role": "assistant", "content": "SELECT subject, start_time, lawyer_id FROM legal_services.appointments WHERE client_id = 'CLIENT123';"}, {"role": "user", "content": "Could you narrow it down to only include appointments where the status is 'Rescheduled' or 'Postponed'?"}, {"role": "assistant", "content": "SELECT subject, start_time, lawyer_id FROM legal_services.appointments WHERE client_id = 'CLIENT123' AND status IN ('Rescheduled', 'Postponed');"}, {"role": "user", "content": "Also, please make sure the appointments were created after June 1st, 2024 and order the results by start_time ascending."}, {"role": "assistant", "content": "SELECT subject, start_time, lawyer_id FROM legal_services.appointments WHERE client_id = 'CLIENT123' AND status IN ('Rescheduled', 'Postponed') AND created_at > '2024-06-01' ORDER BY start_time ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id text PRIMARY KEY, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show the document type, verification status, and the full name of the citizen who uploaded each document."}, {"role": "assistant", "content": "SELECT d.document_type, d.verification_status, CONCAT(c.first_name, ' ', c.last_name) AS citizen_full_name FROM government_services.documents d JOIN government_services.citizens c ON d.citizen_id = c.citizen_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.documents (\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)\n"} {"conversations": [{"role": "user", "content": "Which doctors have issued prescriptions with a route of 'Oral'? Please show doctor_id and the number of such prescriptions they have written."}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS oral_prescription_count\nFROM healthcare.prescriptions\nWHERE route = 'Oral'\nGROUP BY doctor_id;"}, {"role": "user", "content": "Now, only include doctors who have written more than 10 oral prescriptions and sort the list by oral_prescription_count descending."}, {"role": "assistant", "content": "SELECT doctor_id, COUNT(*) AS oral_prescription_count\nFROM healthcare.prescriptions\nWHERE route = 'Oral'\nGROUP BY doctor_id\nHAVING COUNT(*) > 10\nORDER BY oral_prescription_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.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)\n"} {"conversations": [{"role": "user", "content": "List the top 5 most used services across all properties. Show service_name and total quantity ordered, ordered by quantity descending."}, {"role": "assistant", "content": "SELECT s.service_name,\n SUM(o.quantity) AS total_quantity\nFROM hospitality_technology.services s\nJOIN hospitality_technology.service_orders o ON s.service_id = o.service_id\nGROUP BY s.service_name\nORDER BY total_quantity DESC\nLIMIT 5;"}, {"role": "user", "content": "Now filter those to only include services in the 'Food & Beverage' category and sort by total_quantity descending."}, {"role": "assistant", "content": "SELECT s.service_name,\n SUM(o.quantity) AS total_quantity\nFROM hospitality_technology.services s\nJOIN hospitality_technology.service_orders o ON s.service_id = o.service_id\nWHERE s.category = 'Food & Beverage'\nGROUP BY s.service_name\nORDER BY total_quantity DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.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) )\n"} {"conversations": [{"role": "user", "content": "Show me all servers and the total number of achievements available in the game they host. Include the server name and region."}, {"role": "assistant", "content": "SELECT s.server_name, s.region, COUNT(a.achievement_id) AS total_achievements\nFROM gaming_technology.servers s\nJOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY s.server_id, s.server_name, s.region;"}, {"role": "user", "content": "Can you also include the server status in the results?"}, {"role": "assistant", "content": "SELECT s.server_name, s.region, s.status, COUNT(a.achievement_id) AS total_achievements\nFROM gaming_technology.servers s\nJOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY s.server_id, s.server_name, s.region, s.status;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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) )\nCREATE TABLE gaming_technology.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\n"} {"conversations": [{"role": "user", "content": "List all contracts along with their deployer address and status for contracts deployed on the same network as '0xabc123...'. Also, include the deployment timestamp."}, {"role": "assistant", "content": "SELECT c1.contract_id, c1.address, c1.deployer_address, c1.status, c1.deployed_at\nFROM web3.contracts c1\nJOIN web3.contracts c2 ON c1.network_id = c2.network_id\nWHERE c2.address = '0xabc123...';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n"} {"conversations": [{"role": "user", "content": "Find reviews that contain the word 'dirty' in the comment section, showing the review ID, comment, and rating."}, {"role": "assistant", "content": "SELECT review_id, comment, rating_overall FROM hospitality_technology.reviews WHERE LOWER(comment) LIKE '%dirty%';"}, {"role": "user", "content": "Also, only include reviews that are marked as public and have a rating_cleanliness of 2 or less."}, {"role": "assistant", "content": "SELECT review_id, comment, rating_overall FROM hospitality_technology.reviews WHERE LOWER(comment) LIKE '%dirty%' AND is_public = TRUE AND rating_cleanliness <= 2;"}, {"role": "user", "content": "Filter this list further to exclude reviews submitted before January 1st, 2023 and sort by review date ascending."}, {"role": "assistant", "content": "SELECT review_id, comment, rating_overall FROM hospitality_technology.reviews WHERE LOWER(comment) LIKE '%dirty%' AND is_public = TRUE AND rating_cleanliness <= 2 AND review_date >= '2023-01-01' ORDER BY review_date ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 all trips along with the vehicle make and the route distance in km."}, {"role": "assistant", "content": "SELECT t.trip_id, v.make, r.distance_km\nFROM transportation.trips t\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nJOIN transportation.routes r ON t.route_id = r.route_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles (\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.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.passengers ( passenger_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List the name and location ID for all locations where the postal code is missing."}, {"role": "assistant", "content": "SELECT name, location_id FROM transportation.locations WHERE postal_code IS NULL;"}, {"role": "user", "content": "Also include the city and order the results by city ascending."}, {"role": "assistant", "content": "SELECT name, location_id, city FROM transportation.locations WHERE postal_code IS NULL ORDER BY city ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.locations ( location_id text 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 pairs of patients where patient A's emergency contact phone matches patient B's phone number, and patient B's emergency contact phone matches patient A's phone number. Include both patient IDs, their full names, patient A's phone, and patient B's phone."}, {"role": "assistant", "content": "SELECT p1.patient_id AS patient_a_id, p1.first_name AS patient_a_first_name, p1.last_name AS patient_a_last_name, p2.patient_id AS patient_b_id, p2.first_name AS patient_b_first_name, p2.last_name AS patient_b_last_name, p1.phone_number AS patient_a_phone, p2.phone_number AS patient_b_phone FROM healthcare.patients p1 JOIN healthcare.patients p2 ON p1.emergency_contact_phone = p2.phone_number AND p2.emergency_contact_phone = p1.phone_number AND p1.patient_id != p2.patient_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Can you show me each doctor and the number of prescriptions they wrote for each patient they treated? Include the doctor's full name, the patient's full name, and the total count of prescriptions."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, p.first_name, p.last_name, COUNT(pr.prescription_id) AS prescription_count FROM healthcare.prescriptions pr JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id JOIN healthcare.patients p ON pr.patient_id = p.patient_id GROUP BY d.doctor_id, d.first_name, d.last_name, p.patient_id, p.first_name, p.last_name;"}, {"role": "user", "content": "Actually, only show combinations where the doctor has written more than 2 prescriptions for that patient."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, p.first_name, p.last_name, COUNT(pr.prescription_id) AS prescription_count FROM healthcare.prescriptions pr JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id JOIN healthcare.patients p ON pr.patient_id = p.patient_id GROUP BY d.doctor_id, d.first_name, d.last_name, p.patient_id, p.first_name, p.last_name HAVING COUNT(pr.prescription_id) > 2;"}, {"role": "user", "content": "Also, include the date of the most recent prescription for each combination, and sort the results by the prescription count in descending order."}, {"role": "assistant", "content": "SELECT d.first_name, d.last_name, p.first_name, p.last_name, COUNT(pr.prescription_id) AS prescription_count, MAX(pr.prescription_date) AS most_recent_prescription_date FROM healthcare.prescriptions pr JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id JOIN healthcare.patients p ON pr.patient_id = p.patient_id GROUP BY d.doctor_id, d.first_name, d.last_name, p.patient_id, p.first_name, p.last_name HAVING COUNT(pr.prescription_id) > 2 ORDER BY prescription_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.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.medications ( medication_id character varying(64) NOT NULL, medication_name character varying(255) NOT NULL, generic_name character varying(255), manufacturer character varying(100), ndc_code character varying(20) UNIQUE, description text, PRIMARY KEY (medication_id) )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\n"} {"conversations": [{"role": "user", "content": "Find all wallets that were created by users with IDs starting with 'admin_' and show their addresses along with creation timestamps."}, {"role": "assistant", "content": "SELECT address, created_at FROM web3.wallets WHERE user_id LIKE 'admin_%';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "How many users in total have a profile picture URL specified?"}, {"role": "assistant", "content": "SELECT COUNT(*) FROM social_media.users WHERE profile_picture_url IS NOT NULL"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.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 names and types of all in-game items that have a rarity of 'Epic'."}, {"role": "assistant", "content": "SELECT item_name, item_type FROM gaming_technology.in_game_items WHERE rarity = 'Epic';"}, {"role": "user", "content": "Further restrict the list to only include items of item_type 'Weapon'."}, {"role": "assistant", "content": "SELECT item_name, item_type FROM gaming_technology.in_game_items WHERE rarity = 'Epic' AND item_type = 'Weapon';"}, {"role": "user", "content": "Order these results by their cost_amount in descending order."}, {"role": "assistant", "content": "SELECT item_name, item_type FROM gaming_technology.in_game_items WHERE rarity = 'Epic' AND item_type = 'Weapon' ORDER BY cost_amount DESC;"}, {"role": "user", "content": "Please also include the cost_currency and cost_amount in the output."}, {"role": "assistant", "content": "SELECT item_name, item_type, cost_currency, cost_amount FROM gaming_technology.in_game_items WHERE rarity = 'Epic' AND item_type = 'Weapon' ORDER BY cost_amount DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\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.achievements ( achievement_id uuid, game_id uuid, name text, description text, icon_url text, points integer, hidden boolean )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid, player_id uuid, item_id uuid, quantity integer, acquired_at timestamp with time zone, instance_data jsonb )\n"} {"conversations": [{"role": "user", "content": "Find all events with name 'Transfer' that were emitted by contracts deployed by address '0x1234', showing the event data and deployment timestamp of the contract."}, {"role": "assistant", "content": "SELECT e.event_id, e.data, c.deployed_at FROM web3.events e JOIN web3.contracts c ON e.contract_id = c.contract_id WHERE e.event_name = 'Transfer' AND c.deployer_address = '0x1234';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts (\n contract_id character varying(64) NOT NULL, -- unique identifier for the contract\n address character varying(128) NOT NULL, -- address of the deployed contract\n abi text NOT NULL, -- application binary interface of the contract\n bytecode text NOT NULL, -- bytecode of the contract\n deployer_address character varying(128) NOT NULL, -- address of the deployer\n deployed_at timestamp NOT NULL, -- time when the contract was deployed\n network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed\n status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)\n PRIMARY KEY (contract_id)\n)\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\n"} {"conversations": [{"role": "user", "content": "List the IDs of citizens who have received notifications related to more than one distinct type of entity."}, {"role": "assistant", "content": "SELECT citizen_id FROM government_services.notifications WHERE related_entity_type IS NOT NULL AND related_entity_type != '' GROUP BY citizen_id HAVING COUNT(DISTINCT related_entity_type) > 1;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "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 SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\n"} {"conversations": [{"role": "user", "content": "Show me the user ID, username, and email for all users."}, {"role": "assistant", "content": "SELECT user_id, username, email FROM blockchain.users;"}, {"role": "user", "content": "Now, only show the users whose username starts with 'alpha'."}, {"role": "assistant", "content": "SELECT user_id, username, email FROM blockchain.users WHERE username LIKE 'alpha%';"}], "system": "You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE blockchain.users ( user_id.text, username.text, email.text, password_hash.text )\n"} {"conversations": [{"role": "user", "content": "I want to find all claim IDs that have both an 'Accident Report' and a 'Police Report' document."}, {"role": "assistant", "content": "SELECT DISTINCT a.claim_id\nFROM insurance.claim_documents a\nJOIN insurance.claim_documents b\n ON a.claim_id = b.claim_id\nWHERE a.document_type = 'Accident Report'\n AND b.document_type = 'Police Report';"}, {"role": "user", "content": "Now, only include those pairs if both documents were uploaded after '2024-06-01'."}, {"role": "assistant", "content": "SELECT DISTINCT a.claim_id\nFROM insurance.claim_documents a\nJOIN insurance.claim_documents b\n ON a.claim_id = b.claim_id\nWHERE a.document_type = 'Accident Report'\n AND b.document_type = 'Police Report'\n AND a.uploaded_at > '2024-06-01'\n AND b.uploaded_at > '2024-06-01';"}, {"role": "user", "content": "Additionally, ensure that both files are larger than 500 KB."}, {"role": "assistant", "content": "SELECT DISTINCT a.claim_id\nFROM insurance.claim_documents a\nJOIN insurance.claim_documents b\n ON a.claim_id = b.claim_id\nWHERE a.document_type = 'Accident Report'\n AND b.document_type = 'Police Report'\n AND a.uploaded_at > '2024-06-01'\n AND b.uploaded_at > '2024-06-01'\n AND a.file_size_bytes > 512000\n AND b.file_size_bytes > 512000;"}, {"role": "user", "content": "Finally, show me the file_name and uploaded_by for both document types in the results."}, {"role": "assistant", "content": "SELECT\n a.claim_id,\n a.file_name AS accident_file_name,\n a.uploaded_by AS accident_uploaded_by,\n b.file_name AS police_file_name,\n b.uploaded_by AS police_uploaded_by\nFROM insurance.claim_documents a\nJOIN insurance.claim_documents b\n ON a.claim_id = b.claim_id\nWHERE a.document_type = 'Accident Report'\n AND b.document_type = 'Police Report'\n AND a.uploaded_at > '2024-06-01'\n AND b.uploaded_at > '2024-06-01'\n AND a.file_size_bytes > 512000\n AND b.file_size_bytes > 512000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id text, claim_id text, document_type text, file_name text, file_path text, file_size_bytes integer, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n"} {"conversations": [{"role": "user", "content": "Which developers have created games that include at least one item of rarity 'Legendary'? Show the developer_id and the item_name."}, {"role": "assistant", "content": "SELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.in_game_items igi ON d.developer_id = igi.game_id /* This assumes developer_id = game_id; adjust join logic as needed */\nWHERE igi.rarity = 'Legendary';"}, {"role": "user", "content": "I think the join is wrong, it should match developers to games and then in_game_items to games. Please revise the SQL."}, {"role": "assistant", "content": "-- Assuming the existence of a 'games' table with columns (game_id, developer_id)\nSELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items igi ON g.game_id = igi.game_id\nWHERE igi.rarity = 'Legendary';"}, {"role": "user", "content": "You can only use the given tables. Is it possible to get a list of developers who have legendary items in their games with the available schema?"}, {"role": "assistant", "content": "-- Based on the given schema alone (without a games table), it's not possible to relate developers to in_game_items directly since there is no relationship between developer_id and game_id in the available tables."}, {"role": "user", "content": "Okay, then just list all 'Legendary' rarity in-game items, including their item_id, item_name, and cost_amount."}, {"role": "assistant", "content": "SELECT item_id, item_name, cost_amount\nFROM gaming_technology.in_game_items\nWHERE rarity = 'Legendary';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n"} {"conversations": [{"role": "user", "content": "Show me all patients who have been prescribed medications with dosage greater than 100mg, along with their full names and the medication details."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, m.medication_name, m.generic_name, pr.dosage, pr.frequency, pr.start_date, pr.end_date FROM healthcare.patients p JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id JOIN healthcare.medications m ON pr.medication_id = m.medication_id WHERE pr.dosage LIKE '%100mg%' OR pr.dosage LIKE '%>100mg%';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id.text, first_name.text, last_name.text, date_of_birth.date, gender.text, address.text, phone_number.text, email.text, emergency_contact_name.text, emergency_contact_phone.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text 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 )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.insurance_plans ( 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": "Show policy numbers and product names for all policies that started in 2023."}, {"role": "assistant", "content": "SELECT p.policy_number, ip.product_name FROM insurance.policies AS p JOIN insurance.insurance_products AS ip ON p.product_id = ip.product_id WHERE date_part('year', p.start_date) = 2023"}, {"role": "user", "content": "Add the policy status and the product type to the list."}, {"role": "assistant", "content": "SELECT p.policy_number, ip.product_name, p.status, ip.product_type FROM insurance.policies AS p JOIN insurance.insurance_products AS ip ON p.product_id = ip.product_id WHERE date_part('year', p.start_date) = 2023"}, {"role": "user", "content": "Filter these policies to only include those where the product is currently active and the policy status is 'active'."}, {"role": "assistant", "content": "SELECT p.policy_number, ip.product_name, p.status, ip.product_type FROM insurance.policies AS p JOIN insurance.insurance_products AS ip ON p.product_id = ip.product_id WHERE date_part('year', p.start_date) = 2023 AND p.status = 'active' AND ip.is_active = TRUE"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.insurance_products ( product_id text, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.claim_documents ( document_id text, claim_id text, document_type text, file_name text, file_path text, file_size_bytes integer, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n"} {"conversations": [{"role": "user", "content": "List all replacement policies where a customer received a new policy starting the day after their previous policy was cancelled. Return customer_id, original_policy_id, original_cancellation_date, new_policy_id, new_start_date."}, {"role": "assistant", "content": "SELECT orig.customer_id,\n orig.policy_id AS original_policy_id,\n orig.cancellation_date AS original_cancellation_date,\n nw.policy_id AS new_policy_id,\n nw.start_date AS new_start_date\nFROM insurance.policies orig\nJOIN insurance.policies nw\n ON orig.customer_id = nw.customer_id\n AND orig.cancellation_date IS NOT NULL\n AND nw.start_date = orig.cancellation_date + INTERVAL '1 day';"}, {"role": "user", "content": "Now include the premium_amount difference as premium_diff and only show cases where the new policy's premium is higher."}, {"role": "assistant", "content": "SELECT orig.customer_id,\n orig.policy_id AS original_policy_id,\n orig.cancellation_date AS original_cancellation_date,\n nw.policy_id AS new_policy_id,\n nw.start_date AS new_start_date,\n (nw.premium_amount - orig.premium_amount) AS premium_diff\nFROM insurance.policies orig\nJOIN insurance.policies nw\n ON orig.customer_id = nw.customer_id\n AND orig.cancellation_date IS NOT NULL\n AND nw.start_date = orig.cancellation_date + INTERVAL '1 day'\nWHERE nw.premium_amount > orig.premium_amount;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 me all appointments along with any diagnoses recorded for the same patient on the same day. Include appointment_id, patient_id, appointment_time, and diagnosis_description."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.patient_id, T1.appointment_time, T2.description FROM healthcare.appointments AS T1 JOIN healthcare.diagnoses AS T2 ON T1.patient_id = T2.patient_id AND DATE(T1.appointment_time) = T2.diagnosis_date;"}, {"role": "user", "content": "Refine this to only include diagnoses that are marked as 'chronic'."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.patient_id, T1.appointment_time, T2.description FROM healthcare.appointments AS T1 JOIN healthcare.diagnoses AS T2 ON T1.patient_id = T2.patient_id AND DATE(T1.appointment_time) = T2.diagnosis_date WHERE T2.is_chronic = true;"}, {"role": "user", "content": "Additionally, filter to only include appointments where the status is 'Completed'."}, {"role": "assistant", "content": "SELECT T1.appointment_id, T1.patient_id, T1.appointment_time, T2.description FROM healthcare.appointments AS T1 JOIN healthcare.diagnoses AS T2 ON T1.patient_id = T2.patient_id AND DATE(T1.appointment_time) = T2.diagnosis_date WHERE T2.is_chronic = true AND T1.status = 'Completed';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id 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.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) )\n"} {"conversations": [{"role": "user", "content": "Show me all in-progress trips with their vehicle IDs and the difference between scheduled and actual departure time in minutes."}, {"role": "assistant", "content": "SELECT trip_id, vehicle_id, EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 AS departure_delay_minutes FROM transportation.trips WHERE status = 'in-progress';"}, {"role": "user", "content": "Can you include the driver ID and filter to only show trips that have been delayed by more than 15 minutes?"}, {"role": "assistant", "content": "SELECT trip_id, vehicle_id, driver_id, EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 AS departure_delay_minutes FROM transportation.trips WHERE status = 'in-progress' AND EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 > 15;"}, {"role": "user", "content": "Now order these results by the delay time in descending order and include the passenger count."}, {"role": "assistant", "content": "SELECT trip_id, vehicle_id, driver_id, EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 AS departure_delay_minutes, passenger_count FROM transportation.trips WHERE status = 'in-progress' AND EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))/60 > 15 ORDER BY departure_delay_minutes DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.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 )\n"} {"conversations": [{"role": "user", "content": "Show me the total fuel cost for each trip along with the trip's route number and the type of the route."}, {"role": "assistant", "content": "SELECT t.trip_id, r.route_number, r.type, SUM(f.total_cost) AS total_fuel_cost\nFROM transportation.trips t\nJOIN transportation.routes r ON t.route_id = r.route_id\nJOIN transportation.fuel_logs f ON t.trip_id = f.trip_id\nGROUP BY t.trip_id, r.route_number, r.type;"}, {"role": "user", "content": "Modify the query to only include trips on routes of type 'Express', and show results ordered by total fuel cost descending."}, {"role": "assistant", "content": "SELECT t.trip_id, r.route_number, r.type, SUM(f.total_cost) AS total_fuel_cost\nFROM transportation.trips t\nJOIN transportation.routes r ON t.route_id = r.route_id\nJOIN transportation.fuel_logs f ON t.trip_id = f.trip_id\nWHERE r.type = 'Express'\nGROUP BY t.trip_id, r.route_number, r.type\nORDER BY total_fuel_cost DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\nCREATE TABLE transportation.trips ( trip_id text, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count integer, cargo_manifest_id text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\n"} {"conversations": [{"role": "user", "content": "List all policies where the premium_amount exceeds the base_premium of its insurance product. Display the policy_number, premium_amount, product_name, and base_premium. Sort the results by premium_amount descending."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nORDER BY p.premium_amount DESC;"}, {"role": "user", "content": "Actually, I only want policies that are active and whose insurance products are also active."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'active'\n AND ip.is_active = TRUE\nORDER BY p.premium_amount DESC;"}, {"role": "user", "content": "Also, limit the output to policies with a coverage_limit greater than 1000000."}, {"role": "assistant", "content": "SELECT p.policy_number, p.premium_amount, ip.product_name, ip.base_premium\nFROM insurance.policies p\nJOIN insurance.insurance_products ip ON p.product_id = ip.product_id\nWHERE p.status = 'active'\n AND ip.is_active = TRUE\n AND p.coverage_limit > 1000000\nORDER BY p.premium_amount DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address_line1 text, address_line2 text, city text, state text, zip_code text, country text, phone_number text, email text, created_at timestamp, updated_at timestamp, status text )\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text PRIMARY KEY, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me all patients who have been prescribed medications with dosage greater than 100mg, along with their full names and the medication details, including the prescribing doctor's last name."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, m.medication_name, m.generic_name, pr.dosage, d.last_name AS doctor_last_name FROM healthcare.patients p JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id JOIN healthcare.medications m ON pr.medication_id = m.medication_id JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id WHERE pr.dosage LIKE '%100mg%' OR CAST(SUBSTRING(pr.dosage FROM '([0-9]+)') AS INTEGER) > 100;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\n"} {"conversations": [{"role": "user", "content": "List pairs of documents uploaded by the same lawyer, showing uploader ID and both document names."}, {"role": "assistant", "content": "SELECT d1.uploaded_by_lawyer_id, d1.document_name AS doc1, d2.document_name AS doc2 FROM legal_services.documents d1 JOIN legal_services.documents d2 ON d1.uploaded_by_lawyer_id = d2.uploaded_by_lawyer_id AND d1.document_id < d2.document_id;"}, {"role": "user", "content": "Only include pairs where the upload timestamps are within 7 days of each other."}, {"role": "assistant", "content": "SELECT d1.uploaded_by_lawyer_id, d1.document_name AS doc1, d2.document_name AS doc2 FROM legal_services.documents d1 JOIN legal_services.documents d2 ON d1.uploaded_by_lawyer_id = d2.uploaded_by_lawyer_id AND d1.document_id < d2.document_id AND ABS(EXTRACT(EPOCH FROM (d1.upload_timestamp - d2.upload_timestamp)))/86400 <= 7;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Show all comments that are replies, including the comment_id, parent_comment_id, and post_id."}, {"role": "assistant", "content": "SELECT comment_id, parent_comment_id, post_id FROM social_media.comments WHERE parent_comment_id IS NOT NULL;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.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 PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )\n"} {"conversations": [{"role": "user", "content": "What is the average ROI for smart money addresses on the Ethereum chain with a realized profit ratio above 50%?"}, {"role": "assistant", "content": "SELECT AVG(roi) as average_roi\nFROM smart_money_token_performance\nWHERE chain = 'Ethereum'\nAND realized_ratio > 0.5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )\nCREATE TABLE token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )\nCREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )\nCREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n"} {"conversations": [{"role": "user", "content": "Show me all invoices where the total_amount is more than 2000, including the invoice number, the associated case name, and the full name of the client."}, {"role": "assistant", "content": "SELECT i.invoice_number, c.case_name, cl.first_name || ' ' || cl.last_name AS client_full_name\nFROM legal_services.invoices i\nJOIN legal_services.cases c ON i.case_id = c.case_id\nJOIN legal_services.clients cl ON i.client_id = cl.client_id\nWHERE i.total_amount > 2000;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) )\nCREATE TABLE legal_services.lawyers ( lawyer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, bar_number character varying(64) UNIQUE NOT NULL, firm_id character varying(64), email character varying(128) UNIQUE NOT NULL, phone character varying(32), specialization text, hire_date timestamp NOT NULL, is_partner boolean DEFAULT false, PRIMARY KEY (lawyer_id) )\nCREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )\nCREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) )\n"} {"conversations": [{"role": "user", "content": "List the count of events for each contract deployed by address '0x123abc...'"}, {"role": "assistant", "content": "SELECT c.address, COUNT(e.event_id) FROM web3.contracts c JOIN web3.events e ON c.contract_id = e.contract_id WHERE c.deployer_address = '0x123abc...' GROUP BY 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 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 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.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 ( 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 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": "Find all pairs of bookings on the same trip, showing both booking IDs, passenger IDs, and booking times."}, {"role": "assistant", "content": "SELECT b1.booking_id AS booking_id1,\n b1.passenger_id AS passenger1,\n b1.booking_time AS time1,\n b2.booking_id AS booking_id2,\n b2.passenger_id AS passenger2,\n b2.booking_time AS time2\nFROM transportation.bookings b1\nJOIN transportation.bookings b2\n ON b1.trip_id = b2.trip_id\n AND b1.booking_id < b2.booking_id;"}, {"role": "user", "content": "Now limit to only those pairs where both fares exceed 100."}, {"role": "assistant", "content": "SELECT b1.booking_id AS booking_id1,\n b1.passenger_id AS passenger1,\n b1.booking_time AS time1,\n b2.booking_id AS booking_id2,\n b2.passenger_id AS passenger2,\n b2.booking_time AS time2\nFROM transportation.bookings b1\nJOIN transportation.bookings b2\n ON b1.trip_id = b2.trip_id\n AND b1.booking_id < b2.booking_id\nWHERE b1.fare > 100\n AND b2.fare > 100;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 users who have made comments that are replies to other comments. Show their user IDs, the comment ID, and the parent comment ID."}, {"role": "assistant", "content": "SELECT user_id, comment_id, parent_comment_id\nFROM social_media.comments\nWHERE parent_comment_id IS NOT NULL;"}, {"role": "user", "content": "Now, only include users whose profiles are not private."}, {"role": "assistant", "content": "SELECT c.user_id, c.comment_id, c.parent_comment_id\nFROM social_media.comments c\nJOIN social_media.user_settings us ON c.user_id = us.user_id\nWHERE c.parent_comment_id IS NOT NULL\n AND us.private_profile = false;"}, {"role": "user", "content": "Can you also show when their profile settings were last updated and order the results by updated_at descending?"}, {"role": "assistant", "content": "SELECT c.user_id, c.comment_id, c.parent_comment_id, us.updated_at\nFROM social_media.comments c\nJOIN social_media.user_settings us ON c.user_id = us.user_id\nWHERE c.parent_comment_id IS NOT NULL\n AND us.private_profile = false\nORDER BY us.updated_at DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n"} {"conversations": [{"role": "user", "content": "What is the average balance for each account_type among accounts with status 'Open'?"}, {"role": "assistant", "content": "SELECT account_type, AVG(balance) AS avg_balance FROM financial_services.accounts WHERE status = 'Open' GROUP BY account_type;"}, {"role": "user", "content": "Exclude account types with fewer than 3 accounts."}, {"role": "assistant", "content": "SELECT account_type, AVG(balance) AS avg_balance FROM financial_services.accounts WHERE status = 'Open' GROUP BY account_type HAVING COUNT(*) >= 3;"}, {"role": "user", "content": "Sort the results by average balance descending."}, {"role": "assistant", "content": "SELECT account_type, AVG(balance) AS avg_balance FROM financial_services.accounts WHERE status = 'Open' GROUP BY account_type HAVING COUNT(*) >= 3 ORDER BY avg_balance DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show each user_id for users with 'pending' KYC status along with the count of unread notifications they have."}, {"role": "assistant", "content": "SELECT k.user_id, COUNT(n.notification_id) AS unread_count\nFROM trading_platform.kyc_audit k\nJOIN trading_platform.notifications n ON k.user_id = n.user_id AND n.read_at IS NULL\nWHERE k.status = 'pending'\nGROUP BY k.user_id;"}, {"role": "user", "content": "The query doesn't include users with zero unread notifications. Please include users with zero unread notifications too."}, {"role": "assistant", "content": "SELECT k.user_id, COALESCE(COUNT(n.notification_id),0) AS unread_count\nFROM trading_platform.kyc_audit k\nLEFT JOIN trading_platform.notifications n ON k.user_id = n.user_id AND n.read_at IS NULL\nWHERE k.status = 'pending'\nGROUP BY k.user_id;"}, {"role": "user", "content": "Also include the date of the most recent notification sent for each user, whether read or unread."}, {"role": "assistant", "content": "SELECT k.user_id,\n COALESCE(COUNT(n.notification_id),0) AS unread_count,\n MAX(n.sent_at) AS last_notification_at\nFROM trading_platform.kyc_audit k\nLEFT JOIN trading_platform.notifications n ON k.user_id = n.user_id\nWHERE k.status = 'pending'\nGROUP BY k.user_id;"}, {"role": "user", "content": "Now only show users who have more than 1 unread notification, and order by unread_count descending."}, {"role": "assistant", "content": "SELECT user_id, unread_count, last_notification_at\nFROM (\n SELECT k.user_id,\n COALESCE(COUNT(n.notification_id),0) AS unread_count,\n MAX(n.sent_at) AS last_notification_at\n FROM trading_platform.kyc_audit k\n LEFT JOIN trading_platform.notifications n ON k.user_id = n.user_id AND n.read_at IS NULL\n WHERE k.status = 'pending'\n GROUP BY k.user_id\n) t\nWHERE unread_count > 1\nORDER BY unread_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) )\nCREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) )\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )\n"} {"conversations": [{"role": "user", "content": "How many distinct posts does each hashtag appear in?"}, {"role": "assistant", "content": "SELECT hashtag_id, COUNT(DISTINCT post_id) AS post_count FROM social_media.post_hashtags GROUP BY hashtag_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\n"} {"conversations": [{"role": "user", "content": "Show me the top 5 users by the total trade volume (quantity * price) as buyers, along with their email addresses and the number of distinct assets they traded."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(DISTINCT t.asset_id) AS distinct_assets_traded, SUM(t.quantity * t.price) AS total_trade_volume FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id GROUP BY u.user_id, u.email ORDER BY total_trade_volume DESC LIMIT 5;"}, {"role": "user", "content": "Now filter these results to only include trades that happened in the last 30 days."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(DISTINCT t.asset_id) AS distinct_assets_traded, SUM(t.quantity * t.price) AS total_trade_volume FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id WHERE t.traded_at >= NOW() - INTERVAL '30 days' GROUP BY u.user_id, u.email ORDER BY total_trade_volume DESC LIMIT 5;"}, {"role": "user", "content": "Actually, I want to see the average trade size (quantity) for each of these users as well."}, {"role": "assistant", "content": "SELECT u.user_id, u.email, COUNT(DISTINCT t.asset_id) AS distinct_assets_traded, SUM(t.quantity * t.price) AS total_trade_volume, AVG(t.quantity) AS avg_trade_size FROM trading_platform.users u JOIN trading_platform.trades t ON u.user_id = t.buyer_id WHERE t.traded_at >= NOW() - INTERVAL '30 days' GROUP BY u.user_id, u.email ORDER BY total_trade_volume DESC LIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( 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 character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) )\nCREATE TABLE trading_platform.trades (\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 character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.peers ( peer_id 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 ( kyc_audit_id text, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "List each player along with the number of achievements they have unlocked in game 'SuperQuest'."}, {"role": "assistant", "content": "SELECT p.player_id,\n p.username,\n COUNT(pa.achievement_id) AS achievement_count\nFROM gaming_technology.player_achievements pa\nJOIN gaming_technology.players p ON pa.player_id = p.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\nWHERE g.title = 'SuperQuest'\nGROUP BY p.player_id, p.username;"}, {"role": "user", "content": "Actually, I only want players who unlocked at least 5 achievements and also show their registration_date."}, {"role": "assistant", "content": "SELECT p.player_id,\n p.username,\n p.registration_date,\n COUNT(pa.achievement_id) AS achievement_count\nFROM gaming_technology.player_achievements pa\nJOIN gaming_technology.players p ON pa.player_id = p.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\nWHERE g.title = 'SuperQuest'\nGROUP BY p.player_id, p.username, p.registration_date\nHAVING COUNT(pa.achievement_id) >= 5;"}, {"role": "user", "content": "Also include the timestamp of their earliest unlocked achievement for that game."}, {"role": "assistant", "content": "SELECT p.player_id,\n p.username,\n p.registration_date,\n COUNT(pa.achievement_id) AS achievement_count,\n MIN(pa.unlocked_at) AS first_unlocked_at\nFROM gaming_technology.player_achievements pa\nJOIN gaming_technology.players p ON pa.player_id = p.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\nWHERE g.title = 'SuperQuest'\nGROUP BY p.player_id, p.username, p.registration_date\nHAVING COUNT(pa.achievement_id) >= 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Show me all reservations with more than 2 adults that are confirmed (status = 'Confirmed'), including their check-in dates and total amounts."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.property_id, r.guest_id, r.check_in_date, r.total_amount FROM hospitality_technology.reservations r WHERE r.num_adults > 2 AND r.status = 'Confirmed';"}, {"role": "user", "content": "Now join this with the room_types table to include the room type name and base rate for each reservation."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.property_id, r.guest_id, r.check_in_date, r.total_amount, rt.type_name, rt.base_rate FROM hospitality_technology.reservations r JOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id WHERE r.num_adults > 2 AND r.status = 'Confirmed';"}, {"role": "user", "content": "The query should also show the difference between the total amount and the base rate for each reservation."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.property_id, r.guest_id, r.check_in_date, r.total_amount, rt.type_name, rt.base_rate, (r.total_amount - rt.base_rate) AS rate_difference FROM hospitality_technology.reservations r JOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id WHERE r.num_adults > 2 AND r.status = 'Confirmed';"}, {"role": "user", "content": "Actually, I only need reservations where the total amount is at least 50% higher than the base rate, and order them by check-in date."}, {"role": "assistant", "content": "SELECT r.reservation_id, r.property_id, r.guest_id, r.check_in_date, r.total_amount, rt.type_name, rt.base_rate, (r.total_amount - rt.base_rate) AS rate_difference FROM hospitality_technology.reservations r JOIN hospitality_technology.room_types rt ON r.room_type_id = rt.room_type_id WHERE r.num_adults > 2 AND r.status = 'Confirmed' AND r.total_amount >= (rt.base_rate * 1.5) ORDER BY r.check_in_date;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.room_types ( room_type_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, type_name character varying(100) NOT NULL, description text, base_rate numeric(10, 2) NOT NULL, max_occupancy integer NOT NULL, bed_type character varying(50), area_sqft numeric(8,2), amenities text, PRIMARY KEY (room_type_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.reservations (\n reservation_id character varying(64) NOT NULL, -- unique identifier for the booking\n property_id character varying(64) NOT NULL, -- FK to properties table\n guest_id character varying(64) NOT NULL, -- FK to guests table (primary guest)\n room_id character varying(64), -- FK to rooms table (assigned room, might be null initially)\n room_type_id character varying(64) NOT NULL, -- FK to room_types table (booked room type)\n check_in_date date NOT NULL, -- scheduled check-in date\n check_out_date date NOT NULL, -- scheduled check-out date\n actual_check_in_ts timestamp with time zone, -- actual check-in time\n actual_check_out_ts timestamp with time zone, -- actual check-out time\n num_adults integer NOT NULL, -- number of adults\n num_children integer DEFAULT 0, -- number of children\n status character varying(50) NOT NULL, -- e.g., Pending, Confirmed, CheckedIn, CheckedOut, Cancelled, NoShow\n booking_source character varying(100), -- e.g., Website, OTA (Expedia, Booking.com), Phone, WalkIn\n rate_plan_id character varying(64), -- FK to rate_plans table (optional)\n total_amount numeric(12, 2), -- estimated or final total cost\n amount_paid numeric(12, 2) DEFAULT 0.00, -- amount already paid\n special_requests text, -- specific guest requests for this booking\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (reservation_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (room_id) REFERENCES hospitality_technology.rooms(room_id),\n FOREIGN KEY (room_type_id) REFERENCES hospitality_technology.room_types(room_type_id)\n)\nCREATE TABLE hospitality_technology.staff (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.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 all guests who have never left a review, including their full name and email."}, {"role": "assistant", "content": "SELECT g.guest_id, g.first_name, g.last_name, g.email \nFROM hospitality_technology.guests g \nLEFT JOIN hospitality_technology.reviews r ON g.guest_id = r.guest_id \nWHERE r.review_id IS NULL;"}, {"role": "user", "content": "Can you also include their phone number?"}, {"role": "assistant", "content": "SELECT g.guest_id, g.first_name, g.last_name, g.email, g.phone_number \nFROM hospitality_technology.guests g \nLEFT JOIN hospitality_technology.reviews r ON g.guest_id = r.guest_id \nWHERE r.review_id IS NULL;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties ( property_id text PRIMARY KEY, property_name text, address_line1 text, address_line2 text, city text, state_province text, postal_code text, country_code text, phone_number text, email_address text, property_type text, star_rating numeric, timezone text, manager_staff_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.rooms ( room_id text PRIMARY KEY, property_id text, room_number text, room_type_id text, floor int, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text PRIMARY KEY, property_id text, type_name text, description text, base_rate numeric, max_occupancy int, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, address_line1 text, city text, state_province text, postal_code text, country_code text, preferences text, loyalty_member_id text, communication_consent boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.payments ( payment_id text PRIMARY KEY, reservation_id text, guest_id text, bill_id text, amount numeric, currency_code text, payment_method text, card_type text, card_last_four text, transaction_ref text, payment_timestamp timestamp, status text, staff_id_processed text, notes text )\nCREATE TABLE hospitality_technology.reviews ( review_id text PRIMARY KEY, property_id text, reservation_id text, guest_id text, rating_overall int, rating_cleanliness int, rating_service int, rating_location int, rating_value int, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me the first and last names of citizens, the appointment id, and the department of the employee who scheduled their appointment."}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, a.appointment_id, e.department\nFROM government_services.appointments a\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nJOIN government_services.employees e ON a.employee_id = e.employee_id;"}, {"role": "user", "content": "Can you also include the scheduled start time and filter to show only appointments with the status 'Scheduled'?"}, {"role": "assistant", "content": "SELECT c.first_name, c.last_name, a.appointment_id, e.department, a.scheduled_start_time\nFROM government_services.appointments a\nJOIN government_services.citizens c ON a.citizen_id = c.citizen_id\nJOIN government_services.employees e ON a.employee_id = e.employee_id\nWHERE a.status = 'Scheduled';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.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.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 chain has the highest average ROI among all tokens in smart_money_token_performance? Show the chain and the average ROI."}, {"role": "assistant", "content": "SELECT chain, AVG(roi) AS avg_roi\nFROM smart_money_token_performance\nGROUP BY chain\nORDER BY avg_roi DESC\nLIMIT 1;"}, {"role": "user", "content": "Could you also include the total number of tokens analyzed for that chain?"}, {"role": "assistant", "content": "SELECT chain, AVG(roi) AS avg_roi, COUNT(DISTINCT token_symbol) AS token_count\nFROM smart_money_token_performance\nGROUP BY chain\nORDER BY avg_roi DESC\nLIMIT 1;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id text, project_id text, project_name text, rounds_name text, investment_value numeric, investment_date text, introduction text, valuation numeric )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative text, top_3_coins text, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, market_cap numeric, volume_24h numeric, trend_rank numeric, token_num numeric )\nCREATE TABLE token_dexpool_info ( pair_address text, token_name text, token_symbol text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_6h numeric, price_change_percentage_24h numeric, makers_24h numeric, volume_24h numeric, liquidity numeric, market_cap numeric, trend_rank numeric )\nCREATE TABLE smart_money_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_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": "Which hashtags appear on the most posts? Return hashtag_id, tag_name, and the number of posts each hashtag is used in, sorted descending, limited to the top 3."}, {"role": "assistant", "content": "SELECT\n h.hashtag_id,\n h.tag_name,\n COUNT(ph.post_id) AS post_count\nFROM social_media.hashtags h\nJOIN social_media.post_hashtags ph\n ON h.hashtag_id = ph.hashtag_id\nGROUP BY h.hashtag_id, h.tag_name\nORDER BY post_count DESC\nLIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.post_hashtags ( post_hashtag_id.text, post_id.text, hashtag_id.text )\nCREATE TABLE social_media.messages ( message_id.text, conversation_id.text, sender_user_id.text, content.text, media_url.text, media_type.text, sent_at.timestamp, read_at.timestamp )\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.conversation_participants ( participant_id.text, conversation_id.text, user_id.text, joined_at.timestamp, last_read_at.timestamp )\nCREATE TABLE social_media.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 active products, showing their product ID, name, and type, ordered by their creation date."}, {"role": "assistant", "content": "SELECT product_id, product_name, product_type FROM insurance.insurance_products WHERE is_active = TRUE ORDER BY created_at;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "I need to get the most recent message each verified user has sent in any group chat, showing username, group_name, message_id, and sent_at."}, {"role": "assistant", "content": "WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nWHERE ur.rn = 1\n AND u.is_verified = true;"}, {"role": "user", "content": "Actually, I only want messages sent in the past 30 days."}, {"role": "assistant", "content": "WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n AND m.sent_at >= NOW() - INTERVAL '30 days'\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nWHERE ur.rn = 1\n AND u.is_verified = true;"}, {"role": "user", "content": "Also, exclude any users who have disabled push notifications."}, {"role": "assistant", "content": "WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n AND m.sent_at >= NOW() - INTERVAL '30 days'\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nJOIN social_media.user_settings s ON s.user_id = u.user_id\nWHERE ur.rn = 1\n AND u.is_verified = true\n AND s.push_notifications_enabled = true;"}, {"role": "user", "content": "And order the results by sent_at descending."}, {"role": "assistant", "content": "WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n AND m.sent_at >= NOW() - INTERVAL '30 days'\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nJOIN social_media.user_settings s ON s.user_id = u.user_id\nWHERE ur.rn = 1\n AND u.is_verified = true\n AND s.push_notifications_enabled = true\nORDER BY ur.sent_at DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n"} {"conversations": [{"role": "user", "content": "I need a list of trip_id, status, and the corresponding vehicle's license_plate and fuel_type for trips that haven't yet begun."}, {"role": "assistant", "content": "SELECT t.trip_id, t.status, v.license_plate, v.fuel_type\nFROM transportation.trips t\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nWHERE t.status = 'Scheduled';"}, {"role": "user", "content": "I got an error because scheduled trips include records where actual_departure is not null. Please filter for trips with status 'Scheduled' and scheduled_departure in the next 7 days."}, {"role": "assistant", "content": "SELECT t.trip_id, t.status, v.license_plate, v.fuel_type\nFROM transportation.trips t\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nWHERE t.status = 'Scheduled'\n AND t.actual_departure IS NULL\n AND t.scheduled_departure >= now()\n AND t.scheduled_departure < now() + interval '7 days';"}, {"role": "user", "content": "Additionally, exclude vehicles with status not equal to 'Active' and show results ordered by scheduled_departure ascending."}, {"role": "assistant", "content": "SELECT t.trip_id, t.status, v.license_plate, v.fuel_type, t.scheduled_departure\nFROM transportation.trips t\nJOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id\nWHERE t.status = 'Scheduled'\n AND t.actual_departure IS NULL\n AND t.scheduled_departure >= now()\n AND t.scheduled_departure < now() + interval '7 days'\n AND v.status = 'Active'\nORDER BY t.scheduled_departure ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.trips ( trip_id.text, route_id.text, vehicle_id.text, driver_id.text, scheduled_departure.timestamp, actual_departure.timestamp, scheduled_arrival.timestamp, actual_arrival.timestamp, origin_location_id.text, destination_location_id.text, status.text, passenger_count.integer, cargo_manifest_id.text )\nCREATE TABLE transportation.maintenance_logs ( log_id text, vehicle_id text, service_date date, odometer_reading integer, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers ( passenger_id text PRIMARY KEY, first_name text, last_name text, email text, phone_number text, date_of_birth date, loyalty_program_id text, created_at timestamp )\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n"} {"conversations": [{"role": "user", "content": "For each maintenance log, find the upcoming scheduled service by matching next_service_due_date to another log's service_date. List the original log_id, the matching upcoming log_id, and both service_dates."}, {"role": "assistant", "content": "SELECT l1.log_id AS original_log, l2.log_id AS upcoming_log, l1.service_date AS original_date, l2.service_date AS upcoming_date\nFROM transportation.maintenance_logs l1\nLEFT JOIN transportation.maintenance_logs l2\n ON l1.next_service_due_date = l2.service_date\n AND l1.vehicle_id = l2.vehicle_id;"}, {"role": "user", "content": "Include the mechanic_name for both the original and the upcoming log entries."}, {"role": "assistant", "content": "SELECT l1.log_id AS original_log, l2.log_id AS upcoming_log, l1.service_date AS original_date, l2.service_date AS upcoming_date, l1.mechanic_name AS original_mechanic, l2.mechanic_name AS upcoming_mechanic\nFROM transportation.maintenance_logs l1\nLEFT JOIN transportation.maintenance_logs l2\n ON l1.next_service_due_date = l2.service_date\n AND l1.vehicle_id = l2.vehicle_id;"}, {"role": "user", "content": "Now exclude entries where there is no matching upcoming service."}, {"role": "assistant", "content": "SELECT l1.log_id AS original_log, l2.log_id AS upcoming_log, l1.service_date AS original_date, l2.service_date AS upcoming_date, l1.mechanic_name AS original_mechanic, l2.mechanic_name AS upcoming_mechanic\nFROM transportation.maintenance_logs l1\nJOIN transportation.maintenance_logs l2\n ON l1.next_service_due_date = l2.service_date\n AND l1.vehicle_id = l2.vehicle_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\n"} {"conversations": [{"role": "user", "content": "List the make, model, and acquisition_date for vehicles acquired after January 1, 2022."}, {"role": "assistant", "content": "SELECT make, model, acquisition_date\nFROM transportation.vehicles\nWHERE acquisition_date > '2022-01-01';"}, {"role": "user", "content": "Filter the result to include only vehicles with capacity greater than or equal to 50 and sort by acquisition_date ascending."}, {"role": "assistant", "content": "SELECT make, model, acquisition_date\nFROM transportation.vehicles\nWHERE acquisition_date > '2022-01-01' AND capacity >= 50\nORDER BY acquisition_date ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.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 me each case ID with its latest uploaded document. I want to see the case ID, document name, version, and upload timestamp for the most recently uploaded document in each case."}, {"role": "assistant", "content": "SELECT d.case_id, d.document_name, d.version, d.upload_timestamp\nFROM legal_services.documents d\nINNER JOIN (\n SELECT case_id, MAX(upload_timestamp) AS max_upload_timestamp\n FROM legal_services.documents\n GROUP BY case_id\n) latest ON d.case_id = latest.case_id AND d.upload_timestamp = latest.max_upload_timestamp;"}, {"role": "user", "content": "I actually also need to see the document type for these latest documents."}, {"role": "assistant", "content": "SELECT d.case_id, d.document_name, d.version, d.upload_timestamp, d.document_type\nFROM legal_services.documents d\nINNER JOIN (\n SELECT case_id, MAX(upload_timestamp) AS max_upload_timestamp\n FROM legal_services.documents\n GROUP BY case_id\n) latest ON d.case_id = latest.case_id AND d.upload_timestamp = latest.max_upload_timestamp;"}, {"role": "user", "content": "Now, only show cases where the latest uploaded document is a 'Contract'."}, {"role": "assistant", "content": "SELECT d.case_id, d.document_name, d.version, d.upload_timestamp, d.document_type\nFROM legal_services.documents d\nINNER JOIN (\n SELECT case_id, MAX(upload_timestamp) AS max_upload_timestamp\n FROM legal_services.documents\n GROUP BY case_id\n) latest ON d.case_id = latest.case_id AND d.upload_timestamp = latest.max_upload_timestamp\nWHERE d.document_type = 'Contract';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\n"} {"conversations": [{"role": "user", "content": "For each developer, show their name and the total number of in-game items in all games they've developed."}, {"role": "assistant", "content": "SELECT d.name AS developer_name,\n COUNT(i.item_id) AS total_items\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items i ON g.game_id = i.game_id\nGROUP BY d.name;"}, {"role": "user", "content": "Also include the average cost_amount of those items as avg_cost."}, {"role": "assistant", "content": "SELECT d.name AS developer_name,\n COUNT(i.item_id) AS total_items,\n AVG(i.cost_amount) AS avg_cost\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items i ON g.game_id = i.game_id\nGROUP BY d.name;"}, {"role": "user", "content": "Filter the results to only include developers with avg_cost above 500."}, {"role": "assistant", "content": "SELECT d.name AS developer_name,\n COUNT(i.item_id) AS total_items,\n AVG(i.cost_amount) AS avg_cost\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items i ON g.game_id = i.game_id\nGROUP BY d.name\nHAVING AVG(i.cost_amount) > 500;"}, {"role": "user", "content": "Order the output by avg_cost in descending order."}, {"role": "assistant", "content": "SELECT d.name AS developer_name,\n COUNT(i.item_id) AS total_items,\n AVG(i.cost_amount) AS avg_cost\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items i ON g.game_id = i.game_id\nGROUP BY d.name\nHAVING AVG(i.cost_amount) > 500\nORDER BY avg_cost DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.developers ( developer_id uuid, name text, country text, founded_year integer, website text, created_at timestamp with time zone )\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 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, 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 all achievement unlock records where the same player unlocked two different achievements within the same day? Please show player_id, achievement_id_1, achievement_id_2, and the unlock dates for each."}, {"role": "assistant", "content": "SELECT pa1.player_id, pa1.achievement_id as achievement_id_1, pa2.achievement_id as achievement_id_2, pa1.unlocked_at as unlock_date_1, pa2.unlocked_at as unlock_date_2\nFROM gaming_technology.player_achievements pa1\nJOIN gaming_technology.player_achievements pa2\n ON pa1.player_id = pa2.player_id\n AND pa1.achievement_id <> pa2.achievement_id\n AND DATE(pa1.unlocked_at) = DATE(pa2.unlocked_at)\n AND pa1.unlocked_at < pa2.unlocked_at;"}, {"role": "user", "content": "Add a condition to only include records where both achievements were unlocked on or after January 1st, 2024."}, {"role": "assistant", "content": "SELECT pa1.player_id, pa1.achievement_id as achievement_id_1, pa2.achievement_id as achievement_id_2, pa1.unlocked_at as unlock_date_1, pa2.unlocked_at as unlock_date_2\nFROM gaming_technology.player_achievements pa1\nJOIN gaming_technology.player_achievements pa2\n ON pa1.player_id = pa2.player_id\n AND pa1.achievement_id <> pa2.achievement_id\n AND DATE(pa1.unlocked_at) = DATE(pa2.unlocked_at)\n AND pa1.unlocked_at < pa2.unlocked_at\nWHERE pa1.unlocked_at >= '2024-01-01' AND pa2.unlocked_at >= '2024-01-01';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 first name, last name, and email for guests residing in California."}, {"role": "assistant", "content": "SELECT first_name, last_name, email FROM hospitality_technology.guests WHERE state_province = 'CA'"}, {"role": "user", "content": "Only show those who have a phone number."}, {"role": "assistant", "content": "SELECT first_name, last_name, email, phone_number FROM hospitality_technology.guests WHERE state_province = 'CA' AND phone_number IS NOT NULL"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.guests ( guest_id.text, first_name.text, last_name.text, email.text, phone_number.text, date_of_birth.date, address_line1.text, city.text, state_province.text, postal_code.text, country_code.text, preferences.text, loyalty_member_id.text, communication_consent.boolean, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.reservations ( reservation_id.text, property_id.text, guest_id.text, room_id.text, room_type_id.text, check_in_date.date, check_out_date.date, actual_check_in_ts.timestamp, actual_check_out_ts.timestamp, num_adults.integer, num_children.integer, status.text, booking_source.text, rate_plan_id.text, total_amount.numeric, amount_paid.numeric, special_requests.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE hospitality_technology.staff ( staff_id.text, property_id.text, first_name.text, last_name.text, position.text, work_email.text, work_phone.text, hire_date.date, termination_date.date, is_active.boolean, access_level.integer, manager_id.text, created_at.timestamp )\nCREATE TABLE hospitality_technology.services ( service_id.text, property_id.text, service_name.text, description.text, category.text, price.numeric, unit.text, is_available.boolean, department.text )\nCREATE TABLE hospitality_technology.service_orders ( order_id.text, 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": "Show me all the details for all policy beneficiaries."}, {"role": "assistant", "content": "SELECT * FROM insurance.policy_beneficiaries;"}, {"role": "user", "content": "Filter the results to only include beneficiaries for customer 'CUST987'."}, {"role": "assistant", "content": "SELECT * FROM insurance.policy_beneficiaries WHERE customer_id = 'CUST987';"}, {"role": "user", "content": "From those results, only show beneficiaries with a 'Child' relationship and order them by percentage share descending."}, {"role": "assistant", "content": "SELECT * FROM insurance.policy_beneficiaries WHERE customer_id = 'CUST987' AND relationship = 'Child' ORDER BY percentage_share DESC;"}, {"role": "user", "content": "Okay, but only show the first name, last name, relationship, and percentage share, and only for those added after '2023-07-01'."}, {"role": "assistant", "content": "SELECT first_name, last_name, relationship, percentage_share FROM insurance.policy_beneficiaries WHERE customer_id = 'CUST987' AND relationship = 'Child' AND added_at > '2023-07-01' ORDER BY percentage_share DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text 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": "For each pair of origin and destination location IDs, show the number of completed trips between them."}, {"role": "assistant", "content": "SELECT origin_location_id, destination_location_id, COUNT(*) AS completed_trip_count FROM transportation.trips WHERE status = 'Completed' GROUP BY origin_location_id, destination_location_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.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 )\n"} {"conversations": [{"role": "user", "content": "Show me the total transaction amount by transaction_type for all transactions processed by employees in the 'Trading' department, along with their department name."}, {"role": "assistant", "content": "SELECT t.transaction_type, SUM(t.amount) AS total_amount, e.department\nFROM financial_services.transactions t\nJOIN financial_services.employees e ON t.account_id IN (\n SELECT account_id \n FROM financial_services.accounts \n WHERE branch_id = e.branch_id\n)\nWHERE e.department = 'Trading'\nGROUP BY t.transaction_type, e.department;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.employees ( 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 distinct patient IDs who have received a diagnosis from a doctor with 'Cardiology' specialty."}, {"role": "assistant", "content": "SELECT DISTINCT T1.patient_id FROM healthcare.diagnoses AS T1 JOIN healthcare.doctors AS T2 ON T1.doctor_id = T2.doctor_id WHERE T2.specialty = 'Cardiology';"}, {"role": "user", "content": "For these patients, also show their primary insurance policy number."}, {"role": "assistant", "content": "SELECT DISTINCT T1.patient_id, T3.policy_number FROM healthcare.diagnoses AS T1 JOIN healthcare.doctors AS T2 ON T1.doctor_id = T2.doctor_id JOIN healthcare.patient_insurance AS T3 ON T1.patient_id = T3.patient_id WHERE T2.specialty = 'Cardiology' AND T3.is_primary = true;"}, {"role": "user", "content": "Only include patients whose 'Cardiology' diagnosis was made in the last year."}, {"role": "assistant", "content": "SELECT DISTINCT T1.patient_id, T3.policy_number FROM healthcare.diagnoses AS T1 JOIN healthcare.doctors AS T2 ON T1.doctor_id = T2.doctor_id JOIN healthcare.patient_insurance AS T3 ON T1.patient_id = T3.patient_id WHERE T2.specialty = 'Cardiology' AND T3.is_primary = true AND T1.diagnosis_date >= date('now', '-1 year');"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.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.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 passengers who have booked a trip to a city named 'Chicago'. Show their first name, last name, email, and the booking ID."}, {"role": "assistant", "content": "SELECT p.first_name, p.last_name, p.email, b.booking_id\nFROM transportation.bookings b\nJOIN transportation.passengers p ON b.passenger_id = p.passenger_id\nJOIN transportation.trips t ON b.trip_id = t.trip_id\nJOIN transportation.locations l ON t.destination_location_id = l.location_id\nWHERE l.city = 'Chicago';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the location\n name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)\n type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address\n address_line1 character varying(255), -- street address\n city character varying(128), -- city name\n state_province character varying(128), -- state or province\n postal_code character varying(32), -- postal code\n country character varying(64) NOT NULL, -- country name\n latitude numeric(9, 6), -- geographic latitude\n longitude numeric(9, 6), -- geographic longitude\n timezone character varying(64), -- IANA timezone name (e.g., America/New_York)\n PRIMARY KEY (location_id)\n)\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": "For each user, retrieve their first and last log actions along with the respective timestamps."}, {"role": "assistant", "content": "SELECT t.user_id,\n lf.action AS first_action,\n lf.logged_at AS first_time,\n ll.action AS last_action,\n ll.logged_at AS last_time\nFROM (\n SELECT user_id,\n MIN(logged_at) AS first_time,\n MAX(logged_at) AS last_time\n FROM trading_platform.logs\n GROUP BY user_id\n) t\nJOIN trading_platform.logs lf\n ON lf.user_id = t.user_id AND lf.logged_at = t.first_time\nJOIN trading_platform.logs ll\n ON ll.user_id = t.user_id AND ll.logged_at = t.last_time;"}, {"role": "user", "content": "Filter to only include users with more than 5 log entries."}, {"role": "assistant", "content": "SELECT t.user_id,\n lf.action AS first_action,\n lf.logged_at AS first_time,\n ll.action AS last_action,\n ll.logged_at AS last_time\nFROM (\n SELECT user_id,\n MIN(logged_at) AS first_time,\n MAX(logged_at) AS last_time\n FROM trading_platform.logs\n GROUP BY user_id\n HAVING COUNT(*) > 5\n) t\nJOIN trading_platform.logs lf\n ON lf.user_id = t.user_id AND lf.logged_at = t.first_time\nJOIN trading_platform.logs ll\n ON ll.user_id = t.user_id AND ll.logged_at = t.last_time;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\n"} {"conversations": [{"role": "user", "content": "Show me all users who have wallets but have never placed any orders, along with their wallet addresses."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, u.email, w.address FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id LEFT JOIN trading_platform.orders o ON u.user_id = o.user_id WHERE o.order_id IS NULL;"}, {"role": "user", "content": "Now modify the query to only include users who created their wallets in the last 6 months."}, {"role": "assistant", "content": "SELECT u.user_id, u.username, u.email, w.address FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id LEFT JOIN trading_platform.orders o ON u.user_id = o.user_id WHERE o.order_id IS NULL AND w.created_at >= NOW() - INTERVAL '6 months';"}, {"role": "user", "content": "Actually, I want to see the count of such users grouped by the month they created their wallets."}, {"role": "assistant", "content": "SELECT DATE_TRUNC('month', w.created_at) AS month_created, COUNT(DISTINCT u.user_id) AS user_count FROM trading_platform.users u JOIN trading_platform.wallets w ON u.user_id = w.user_id LEFT JOIN trading_platform.orders o ON u.user_id = o.user_id WHERE o.order_id IS NULL GROUP BY month_created ORDER BY month_created;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "How many servers are in each region, and what's the average number of current players for those servers?"}, {"role": "assistant", "content": "SELECT\n region,\n COUNT(server_id) AS server_count,\n AVG(current_players) AS average_current_players\nFROM gaming_technology.servers\nGROUP BY\n region;"}, {"role": "user", "content": "Only include regions with more than 5 servers."}, {"role": "assistant", "content": "SELECT\n region,\n COUNT(server_id) AS server_count,\n AVG(current_players) AS average_current_players\nFROM gaming_technology.servers\nGROUP BY\n region\nHAVING\n COUNT(server_id) > 5;"}, {"role": "user", "content": "Also, include the total maximum players capacity for each of these regions."}, {"role": "assistant", "content": "SELECT\n region,\n COUNT(server_id) AS server_count,\n AVG(current_players) AS average_current_players,\n SUM(max_players) AS total_max_players\nFROM gaming_technology.servers\nGROUP BY\n region\nHAVING\n COUNT(server_id) > 5;"}, {"role": "user", "content": "Order the results by the average current players in descending order."}, {"role": "assistant", "content": "SELECT\n region,\n COUNT(server_id) AS server_count,\n AVG(current_players) AS average_current_players,\n SUM(max_players) AS total_max_players\nFROM gaming_technology.servers\nGROUP BY\n region\nHAVING\n COUNT(server_id) > 5\nORDER BY\n average_current_players DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.game_sessions ( session_id.uuid, player_id.uuid, game_id.uuid, server_id.uuid, start_time.timestamptz, end_time.timestamptz, duration_seconds.integer, score.integer, session_data.jsonb )\nCREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )\n"} {"conversations": [{"role": "user", "content": "Find the top 3 tokens by total supply that have a token symbol starting with 'T', showing their token names, contract addresses, and total supply."}, {"role": "assistant", "content": "SELECT token_name, contract_address, total_supply FROM web3.tokens WHERE token_symbol LIKE 'T%' ORDER BY total_supply DESC LIMIT 3;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens ( token_id.text, contract_address.text, token_name.text, token_symbol.text, decimals.integer, total_supply.numeric )\n"} {"conversations": [{"role": "user", "content": "Show me the invoice number and total amount for each invoice, along with the number and name of the case it belongs to."}, {"role": "assistant", "content": "SELECT T1.invoice_number, T1.total_amount, T2.case_number, T2.case_name FROM invoices AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id;"}, {"role": "user", "content": "Refine this to only include invoices with a status of 'Overdue' or 'Unpaid'."}, {"role": "assistant", "content": "SELECT T1.invoice_number, T1.total_amount, T2.case_number, T2.case_name FROM invoices AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id WHERE T1.status = 'Overdue' OR T1.status = 'Unpaid';"}, {"role": "user", "content": "Also include the invoice due date and order the results by due date ascending."}, {"role": "assistant", "content": "SELECT T1.invoice_number, T1.total_amount, T1.due_date, T2.case_number, T2.case_name FROM invoices AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id WHERE T1.status = 'Overdue' OR T1.status = 'Unpaid' ORDER BY T1.due_date ASC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Show me the top 5 users who have the highest total trade volume (quantity * price) as buyers, along with the number of distinct assets they traded."}, {"role": "assistant", "content": "SELECT t.buyer_id, u.email, SUM(t.quantity * t.price) AS total_volume, COUNT(DISTINCT t.asset_id) AS distinct_assets\nFROM trading_platform.trades t\nJOIN trading_platform.users u ON t.buyer_id = u.user_id\nGROUP BY t.buyer_id, u.email\nORDER BY total_volume DESC\nLIMIT 5;"}, {"role": "user", "content": "Now modify the query to include only trades that happened in the last 30 days and show the average trade price for each buyer."}, {"role": "assistant", "content": "SELECT t.buyer_id, u.email, SUM(t.quantity * t.price) AS total_volume, COUNT(DISTINCT t.asset_id) AS distinct_assets, AVG(t.price) AS avg_trade_price\nFROM trading_platform.trades t\nJOIN trading_platform.users u ON t.buyer_id = u.user_id\nWHERE t.traded_at >= NOW() - INTERVAL '30 days'\nGROUP BY t.buyer_id, u.email\nORDER BY total_volume DESC\nLIMIT 5;"}, {"role": "user", "content": "Actually, I want to see the top 5 buyers by total trade volume who also have wallets, and include their wallet addresses."}, {"role": "assistant", "content": "SELECT t.buyer_id, u.email, w.address AS wallet_address, SUM(t.quantity * t.price) AS total_volume\nFROM trading_platform.trades t\nJOIN trading_platform.users u ON t.buyer_id = u.user_id\nJOIN trading_platform.wallets w ON t.buyer_id = w.user_id\nWHERE t.traded_at >= NOW() - INTERVAL '30 days'\nGROUP BY t.buyer_id, u.email, w.address\nORDER BY total_volume DESC\nLIMIT 5;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 text PRIMARY KEY, user_id text, address text, private_key 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 character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) )\nCREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) )\nCREATE TABLE trading_platform.peers ( peer_id 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 ( kyc_audit_id text, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) )\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n"} {"conversations": [{"role": "user", "content": "List the first and last names of all doctors whose email address ends with '@hospital.org'."}, {"role": "assistant", "content": "SELECT first_name, last_name FROM healthcare.doctors WHERE email LIKE '%@hospital.org';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List each patient's first_name, last_name, and the plan_name and policy_number of their primary insurance plan."}, {"role": "assistant", "content": "SELECT p.first_name,\n p.last_name,\n ip.plan_name,\n pi.policy_number\nFROM healthcare.patients p\nJOIN healthcare.patient_insurance pi ON p.patient_id = pi.patient_id AND pi.is_primary = TRUE\nJOIN healthcare.insurance_plans ip ON pi.plan_id = ip.plan_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text PRIMARY KEY, 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 any two claims made by the same customer on the same day. Return customer_id, the two claim IDs, and the incident date."}, {"role": "assistant", "content": "SELECT c1.customer_id,\n c1.claim_id AS claim1_id,\n c2.claim_id AS claim2_id,\n DATE(c1.incident_date) AS incident_date\nFROM insurance.claims c1\nJOIN insurance.claims c2\n ON c1.customer_id = c2.customer_id\n AND DATE(c1.incident_date) = DATE(c2.incident_date)\n AND c1.claim_id < c2.claim_id;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claims ( claim_id text, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\n"} {"conversations": [{"role": "user", "content": "List all smart money addresses that have a negative PNL but a positive Realized Ratio. Show the address, chain, PNL, and Realized Ratio."}, {"role": "assistant", "content": "SELECT token_address, chain, pnl, realized_ratio FROM smart_money_token_performance WHERE pnl < 0 AND realized_ratio > 0"}, {"role": "user", "content": "Can you refine the results to only include addresses where the absolute value of PNL is greater than 1000?"}, {"role": "assistant", "content": "SELECT token_address, chain, pnl, realized_ratio FROM smart_money_token_performance WHERE pnl < -1000 AND realized_ratio > 0"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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": "Show me the total price and quantity for each service order, along with the guest's full name."}, {"role": "assistant", "content": "SELECT t1.order_id, t1.total_price, t1.quantity, t2.first_name, t2.last_name FROM hospitality_technology.service_orders AS t1 JOIN hospitality_technology.guests AS t2 ON t1.guest_id = t2.guest_id;"}, {"role": "user", "content": "Filter those orders to only include ones that have a total price greater than 100."}, {"role": "assistant", "content": "SELECT t1.order_id, t1.total_price, t1.quantity, t2.first_name, t2.last_name FROM hospitality_technology.service_orders AS t1 JOIN hospitality_technology.guests AS t2 ON t1.guest_id = t2.guest_id WHERE t1.total_price > 100;"}, {"role": "user", "content": "Also include the service name and the property name where the service was offered."}, {"role": "assistant", "content": "SELECT t1.order_id, t1.total_price, t1.quantity, t2.first_name, t2.last_name, t3.service_name, t4.property_name FROM hospitality_technology.service_orders AS t1 JOIN hospitality_technology.guests AS t2 ON t1.guest_id = t2.guest_id JOIN hospitality_technology.services AS t3 ON t1.service_id = t3.service_id JOIN hospitality_technology.properties AS t4 ON t3.property_id = t4.property_id WHERE t1.total_price > 100;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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.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.staff (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\nCREATE TABLE hospitality_technology.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)\n"} {"conversations": [{"role": "user", "content": "List tokens with a market cap greater than $500,000,000 and a trend rank of 10 or better. Show symbol, name, chain, market cap, and trend rank."}, {"role": "assistant", "content": "SELECT token_symbol, token_name, chain, market_cap, trend_rank FROM token_basic_info WHERE market_cap > 500000000 AND trend_rank <= 10;"}, {"role": "user", "content": "Now, only show tokens on the 'Ethereum' or 'Polygon' chains."}, {"role": "assistant", "content": "SELECT token_symbol, token_name, chain, market_cap, trend_rank FROM token_basic_info WHERE market_cap > 500000000 AND trend_rank <= 10 AND chain IN ('Ethereum', 'Polygon');"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_basic_info ( coin_id.text, token_name.text, token_symbol.text, token_address.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, highest_price_24h.numeric, lowest_price_24h.numeric, market_cap.numeric, market_cap_rank.numeric, market_cap_change_percentage_24h.text, total_volume.text, narrative.text, trend_rank.numeric )\nCREATE TABLE token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )\nCREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\nCREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )\n"} {"conversations": [{"role": "user", "content": "Show me all NFT collections on the 'Ethereum' blockchain, listing their name, contract address, and ERC type."}, {"role": "assistant", "content": "SELECT name, contract_address, erc_type FROM nft_collections WHERE blockchain = 'Ethereum'"}, {"role": "user", "content": "For these Ethereum collections, can you show the total number of unique wallets that have ever held an NFT from each collection by joining with the historical holder table?"}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, COUNT(DISTINCT nhh.wallet_address) AS unique_holders FROM nft_collections nc JOIN nft_holder_historical nhh ON nc.contract_address = nhh.contract_address WHERE nc.blockchain = 'Ethereum' GROUP BY nc.name, nc.contract_address"}, {"role": "user", "content": "Only show collections that have more than 100 unique holders, sorted by the number of unique holders descending."}, {"role": "assistant", "content": "SELECT nc.name, nc.contract_address, COUNT(DISTINCT nhh.wallet_address) AS unique_holders FROM nft_collections nc JOIN nft_holder_historical nhh ON nc.contract_address = nhh.contract_address WHERE nc.blockchain = 'Ethereum' GROUP BY nc.name, nc.contract_address HAVING COUNT(DISTINCT nhh.wallet_address) > 100 ORDER BY unique_holders DESC"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE 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 (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\n"} {"conversations": [{"role": "user", "content": "Show me all token transfers where the from_address is the same as the to_address, indicating self-transfers, along with the token_id and value."}, {"role": "assistant", "content": "SELECT transfer_id, token_id, from_address, to_address, value, transaction_id FROM web3.token_transfers WHERE from_address = to_address;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.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": "Show me the list of players who have never logged in since they registered."}, {"role": "assistant", "content": "SELECT player_id, username, registration_date\nFROM gaming_technology.players\nWHERE last_login IS NULL;"}, {"role": "user", "content": "Only include those who registered more than 30 days ago."}, {"role": "assistant", "content": "SELECT player_id, username, registration_date\nFROM gaming_technology.players\nWHERE last_login IS NULL\n AND registration_date < NOW() - INTERVAL '30 days';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.developers ( developer_id uuid NOT NULL DEFAULT gen_random_uuid(), name character varying(150) NOT NULL UNIQUE, country character varying(100), founded_year integer, website character varying(255), created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (developer_id) )\nCREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, name character varying(150) NOT NULL, description text NOT NULL, icon_url character varying(255), points integer DEFAULT 0, hidden boolean DEFAULT false, PRIMARY KEY (achievement_id) )\n"} {"conversations": [{"role": "user", "content": "Find all assets that have metadata with both 'category' and 'subcategory' keys, along with their corresponding values."}, {"role": "assistant", "content": "SELECT m1.asset_id, m1.value as category, m2.value as subcategory FROM trading_platform.metadata m1 JOIN trading_platform.metadata m2 ON m1.asset_id = m2.asset_id WHERE m1.key = 'category' AND m2.key = 'subcategory';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\n"} {"conversations": [{"role": "user", "content": "List all vehicles that use diesel fuel, showing their make, model, and year."}, {"role": "assistant", "content": "SELECT make, model, year FROM transportation.vehicles WHERE fuel_type = 'diesel';"}, {"role": "user", "content": "Now include only vehicles acquired in the last 5 years."}, {"role": "assistant", "content": "SELECT make, model, year FROM transportation.vehicles WHERE fuel_type = 'diesel' AND acquisition_date >= CURRENT_DATE - INTERVAL '5 years';"}, {"role": "user", "content": "Can you also show their status and order the results by year in descending order?"}, {"role": "assistant", "content": "SELECT make, model, year, status FROM transportation.vehicles WHERE fuel_type = 'diesel' AND acquisition_date >= CURRENT_DATE - INTERVAL '5 years' ORDER BY year DESC;"}, {"role": "user", "content": "Actually, I only want to see active vehicles in this list."}, {"role": "assistant", "content": "SELECT make, model, year, status FROM transportation.vehicles WHERE fuel_type = 'diesel' AND acquisition_date >= CURRENT_DATE - INTERVAL '5 years' AND status = 'active' ORDER BY year DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\n"} {"conversations": [{"role": "user", "content": "List the medical record ID and record date for all medical records that are linked to an appointment whose duration was longer than the average duration of all appointments."}, {"role": "assistant", "content": "SELECT T1.record_id, T1.record_date FROM healthcare.medical_records AS T1 JOIN healthcare.appointments AS T2 ON T1.appointment_id = T2.appointment_id WHERE T2.duration_minutes > (SELECT AVG(duration_minutes) FROM healthcare.appointments);"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments (\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 )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n"} {"conversations": [{"role": "user", "content": "For each city and state, show the number of service locations available along with their accessibility status."}, {"role": "assistant", "content": "SELECT city, state, is_accessible, COUNT(*) AS location_count FROM government_services.service_locations GROUP BY city, state, is_accessible;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.service_locations ( location_id text, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\n"} {"conversations": [{"role": "user", "content": "How many reviews have been submitted for each review_source?"}, {"role": "assistant", "content": "SELECT review_source, COUNT(*) AS review_count\nFROM hospitality_technology.reviews\nGROUP BY review_source;"}, {"role": "user", "content": "Now, show only sources with more than 200 reviews and sort by review count descending."}, {"role": "assistant", "content": "SELECT review_source, COUNT(*) AS review_count\nFROM hospitality_technology.reviews\nGROUP BY review_source\nHAVING COUNT(*) > 200\nORDER BY review_count DESC;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.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 users who follow both user 'U100' and user 'U101'."}, {"role": "assistant", "content": "SELECT f1.follower_user_id\nFROM social_media.follows f1\nJOIN social_media.follows f2 ON f1.follower_user_id = f2.follower_user_id\nWHERE f1.following_user_id = 'U100' AND f2.following_user_id = 'U101';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.comments ( comment_id text PRIMARY KEY, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id text PRIMARY KEY, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id text PRIMARY KEY, post_id text, hashtag_id text )\nCREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversation_participants ( participant_id text PRIMARY KEY, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n"} {"conversations": [{"role": "user", "content": "特定の職種の従業員情報を取得したいです。従業員ID、名前、職種、雇用日を表示してください。"}, {"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": "雇用日が2020年1月1日以降の従業員だけに絞り込むことはできますか?"}, {"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": "雇用ステータスが「Active」の従業員だけをさらに条件に加えられますか?"}, {"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": "スキル認定情報も結果に含めてください。"}, {"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\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": "How many messages in total have been sent that do not contain any media attachment?"}, {"role": "assistant", "content": "SELECT COUNT(*) AS non_media_message_count\nFROM social_media.messages\nWHERE media_url IS NULL OR media_url = '';"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.messages ( message_id text PRIMARY KEY, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\n"} {"conversations": [{"role": "user", "content": "List the content and sent time for messages sent by user 'U101'."}, {"role": "assistant", "content": "SELECT content, sent_at FROM social_media.messages WHERE sender_user_id = 'U101';"}, {"role": "user", "content": "Could you also include the group name for those messages and only show messages sent in group chats?"}, {"role": "assistant", "content": "SELECT m.content, m.sent_at, c.name AS group_name FROM social_media.messages m JOIN social_media.conversations c ON m.conversation_id = c.conversation_id WHERE m.sender_user_id = 'U101' AND c.type = 'group';"}, {"role": "user", "content": "Now filter to include only messages sent in June 2024 and order them by sent time descending."}, {"role": "assistant", "content": "SELECT m.content, m.sent_at, c.name AS group_name FROM social_media.messages m JOIN social_media.conversations c ON m.conversation_id = c.conversation_id WHERE m.sender_user_id = 'U101' AND c.type = 'group' AND m.sent_at >= '2024-06-01' AND m.sent_at < '2024-07-01' ORDER BY m.sent_at DESC;"}, {"role": "user", "content": "Also limit the results to the top 15."}, {"role": "assistant", "content": "SELECT m.content, m.sent_at, c.name AS group_name FROM social_media.messages m JOIN social_media.conversations c ON m.conversation_id = c.conversation_id WHERE m.sender_user_id = 'U101' AND c.type = 'group' AND m.sent_at >= '2024-06-01' AND m.sent_at < '2024-07-01' ORDER BY m.sent_at DESC LIMIT 15;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.messages (\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)\n"} {"conversations": [{"role": "user", "content": "For each player, list their username and the total number of unique servers they have played on, only including players who have played on two or more different servers. Also show the titles of all games they've played sessions on."}, {"role": "assistant", "content": "SELECT p.username, COUNT(DISTINCT gs.server_id) AS unique_servers, STRING_AGG(DISTINCT g.title, ', ') AS game_titles\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nJOIN gaming_technology.servers s ON gs.server_id = s.server_id\nJOIN gaming_technology.games g ON gs.game_id = g.game_id\nWHERE gs.server_id IS NOT NULL\nGROUP BY p.player_id\nHAVING COUNT(DISTINCT gs.server_id) >= 2;"}, {"role": "user", "content": "Add another column for the total duration in seconds that each player has spent on these servers."}, {"role": "assistant", "content": "SELECT p.username, COUNT(DISTINCT gs.server_id) AS unique_servers, STRING_AGG(DISTINCT g.title, ', ') AS game_titles, SUM(gs.duration_seconds) AS total_duration_seconds\nFROM gaming_technology.players p\nJOIN gaming_technology.game_sessions gs ON p.player_id = gs.player_id\nJOIN gaming_technology.servers s ON gs.server_id = s.server_id\nJOIN gaming_technology.games g ON gs.game_id = g.game_id\nWHERE gs.server_id IS NOT NULL\nGROUP BY p.player_id\nHAVING COUNT(DISTINCT gs.server_id) >= 2;"}], "system": "You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory (\n inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry\n player_id uuid NOT NULL, -- FK linking to the player owning the item\n item_id uuid NOT NULL, -- FK linking to the item definition\n quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items)\n acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired\n instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability)\n PRIMARY KEY (inventory_id),\n -- Optional unique constraint if items are non-stackable or unique instances\n -- UNIQUE (player_id, item_id) -- Use if quantity is always 1\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id)\n)\n"}