Dataset Viewer
Auto-converted to Parquet Duplicate
conversations
listlengths
2
8
system
stringlengths
295
8.03k
[ { "role": "user", "content": "Could you list each game_id along with the count of hidden achievements and the count of visible achievements?" }, { "role": "assistant", "content": "SELECT game_id,\n SUM(CASE WHEN hidden THEN 1 ELSE 0 END) AS hidden_count,\n SUM(CASE WHEN NOT hidden THEN 1 ELSE 0 END) AS visible_count\nFROM gaming_technology.achievements\nGROUP BY game_id;" }, { "role": "user", "content": "Actually, please provide pairs of one hidden and one visible achievement name for each game where both types exist." }, { "role": "assistant", "content": "SELECT h.game_id,\n h.name AS hidden_name,\n v.name AS visible_name\nFROM gaming_technology.achievements h\nJOIN gaming_technology.achievements v\n ON h.game_id = v.game_id\n AND h.hidden = TRUE\n AND v.hidden = FALSE\nWHERE EXISTS (\n SELECT 1 FROM gaming_technology.achievements x\n WHERE x.game_id = h.game_id\n AND x.hidden = FALSE\n)\nAND EXISTS (\n SELECT 1 FROM gaming_technology.achievements y\n WHERE y.game_id = h.game_id\n AND y.hidden = TRUE\n);" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )
[ { "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;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, -- unique identifier for the message conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id) sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id) content text, -- textual content of the message media_url text, -- URL to attached media (image/video) media_type character varying(20), -- type of media ('image', 'video', null) sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent read_at timestamp, -- timestamp when message was read by recipient(s) PRIMARY KEY (message_id) )
[ { "role": "user", "content": "What is the schedule of trains arriving at platform 1A at station XYZ on December 25th, 2023?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide information about train schedules or specific arrival times as this data is not included in the platform management table. For train schedules, please refer to the train timetable or contact the station's customer service." } ]
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. ##Table Structure CREATE TABLE train_station_management.platforms ( platform_id character varying(64) NOT NULL, -- Unique identifier for the platform station_id character varying(64) NOT NULL, -- Foreign key referencing stations platform_number character varying(10) NOT NULL, -- Platform identifier (e.g., '1A', '5') track_number character varying(10), -- Associated track number, if different status character varying(32) NOT NULL DEFAULT 'Operational', -- e.g., Operational, Maintenance, Closed length_meters numeric(8,2), -- Length of the platform in meters accessible boolean NOT NULL DEFAULT false, -- Is the platform accessible (e.g., wheelchair)? PRIMARY KEY (platform_id), FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id) )
[ { "role": "user", "content": "Count the number of posts that have a media URL but no textual content." }, { "role": "assistant", "content": "SELECT COUNT(*) FROM social_media.posts AS T1 WHERE T1.media_url IS NOT NULL AND (T1.content IS NULL OR T1.content = '');" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, -- unique identifier for the user username character varying(50) NOT NULL UNIQUE, -- user's unique handle email character varying(128) NOT NULL UNIQUE, -- user's email address password_hash text NOT NULL, -- hashed password full_name character varying(100), -- user's full name profile_picture_url text, -- URL to the profile picture bio text, -- short user biography location character varying(100), -- user's location created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update is_verified boolean NOT NULL DEFAULT false, -- verification status PRIMARY KEY (user_id) ) CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, -- unique identifier for the post user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id) content text, -- textual content of the post media_url text, -- URL to attached media (image/video) media_type character varying(20), -- type of media ('image', 'video', null) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private') location_lat numeric(9,6), -- latitude of post location location_lon numeric(9,6), -- longitude of post location PRIMARY KEY (post_id) ) CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, -- unique identifier for the comment post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id) user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id) parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id) content text NOT NULL, -- textual content of the comment created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit PRIMARY KEY (comment_id) ) CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, -- unique identifier for the like user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id) post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable) comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something ) CREATE TABLE social_media.follows ( follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id) following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id) created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started PRIMARY KEY (follow_id), CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows ) CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used PRIMARY KEY (hashtag_id) ) CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, -- unique identifier for the message conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id) sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id) content text, -- textual content of the message media_url text, -- URL to attached media (image/video) media_type character varying(20), -- type of media ('image', 'video', null) sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent read_at timestamp, -- timestamp when message was read by recipient(s) PRIMARY KEY (message_id) ) CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated last_message_at timestamp, -- timestamp of the last message in the conversation is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message group_name character varying(100), -- name of the group chat (if applicable) PRIMARY KEY (conversation_id) ) CREATE TABLE social_media.conversation_participants ( participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id) user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id) joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation last_read_at timestamp, -- timestamp indicating up to when the user has read messages PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, -- unique identifier for the notification recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id) sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications) notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message') target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id) target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation') created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created read_at timestamp, -- timestamp notification was marked as read PRIMARY KEY (notification_id) ) CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id) theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark') email_notifications_enabled boolean DEFAULT true, -- enable/disable email notifications push_notifications_enabled boolean DEFAULT true, -- enable/disable push notifications private_profile boolean DEFAULT false, -- is the user profile private updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change PRIMARY KEY (setting_id) )
[ { "role": "user", "content": "特定の予約ID 'book_zyx' に関連するすべてのチケットの詳細を取得するのを手伝っていただけますか?また、関連する車両情報も含めてください。" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGETALL ticket:<ticket_id>\nHGETALL car:<car_id>" }, { "role": "user", "content": "チェックイン済みのチケットだけを表示するようにフィルタリングしていただけますか?" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket:<ticket_id> is_checked_in\nHGETALL ticket:<ticket_id> (only if is_checked_in = 1)\nHGETALL car:<car_id>" }, { "role": "user", "content": "座席番号も結果に含めて、座席番号順に並べ替えることは可能ですか?" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket:<ticket_id> is_checked_in\nHGETALL ticket:<ticket_id> (only if is_checked_in = 1)\nHGETALL car:<car_id>\n(Sort results by seat_number in ascending order)" }, { "role": "user", "content": "車両IDごとにチケットの総数を追加していただけますか?" }, { "role": "assistant", "content": "SMEMBERS booking:book_zyx:tickets\nHGET ticket:<ticket_id> is_checked_in\nHGETALL ticket:<ticket_id> (only if is_checked_in = 1)\nHGETALL car:<car_id>\n(Group by car_id and count total tickets per car_id)\n(Sort results by seat_number in ascending order)" } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure // Use Hashes for ticket details. Key format: ticket:<ticket_id> // HSET ticket:tkt_1a2b ticket_id "tkt_1a2b" booking_id "book_zyx" car_id "car_abc" seat_number "12A" ... is_checked_in 0 ... // To link tickets to bookings (optional): // SADD booking:book_zyx:tickets ticket:tkt_1a2b // Use Hashes for maintenance record details. Key format: maintenance_record:<record_id> // HSET maintenance_record:maint_rec_001 record_id "maint_rec_001" asset_id "train_789" asset_type "Train" ... status "Completed" // To link records to assets (optional): // SADD train:train_789:maintenance maintenance_record:maint_rec_001 // SADD platform:plat_123:maintenance maintenance_record:maint_rec_002
[ { "role": "user", "content": "Can you help me fetch the inventory details for components associated with a specific aircraft build, including the batch number, quantity, and warehouse location?" }, { "role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse" }, { "role": "user", "content": "Can you modify this to show only inventory batches received after a specific date, say June 1, 2023?" }, { "role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01')\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse" }, { "role": "user", "content": "What if I also want to exclude batches with quantities less than 10?" }, { "role": "assistant", "content": "MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01') AND ib.quantity >= 10\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse" } ]
You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure Node Label ':AircraftModel'. Properties: { model_id: String (Constraint: UNIQUE), model_name: String, manufacturer: String, passenger_capacity: Integer, max_range_km: Integer, engine_type: String, wingspan_m: Float, status: String, first_flight_date: Date }. Index on model_id. Node Label ':Material'. Properties: { material_id: String (Constraint: UNIQUE), material_name: String, specification: String, description: String, density_kg_m3: Float, tensile_strength_mpa: Integer }. Index on material_id. Node Label ':AssemblyLine'. Properties: { line_id: String (Constraint: UNIQUE), line_name: String, location_building: String, location_area: String, capacity_units_per_month: Integer, status: String }. Relationship: (:AssemblyLine)-[:BUILDS_MODEL]->(:AircraftModel {model_id}). Index on line_id. Node Label ':AssemblyStep'. Properties: { step_id: String (Constraint: UNIQUE), step_number: Integer, step_name: String, description: String, standard_duration_hours: Float, required_skill_level: String, workstation: String }. Relationship: (:AssemblyLine {line_id})-[:HAS_STEP {sequence: <step_number>}]->(:AssemblyStep). Index on step_id. Node Label ':AircraftBuild'. Properties: { build_id: String (Constraint: UNIQUE), serial_number: String (Constraint: UNIQUE), build_start_date: Datetime, estimated_completion_date: Date, actual_completion_date: Datetime, current_status: String, customer_order_id: String }. Relationships: (:AircraftBuild)-[:IS_MODEL]->(:AircraftModel {model_id}), (:AircraftBuild)-[:ASSEMBLED_ON]->(:AssemblyLine {line_id}). Index on build_id, serial_number, current_status. Node Label ':Employee'. Properties: { employee_id: String (Constraint: UNIQUE), first_name: String, last_name: String, job_title: String, skill_certifications: String[], hire_date: Date, employment_status: String }. Relationships: (:Employee)-[:ASSIGNED_TO]->(:AssemblyLine {line_id}), (:Employee)-[:REPORTS_TO]->(:Employee {employee_id as supervisor_id}). Index on employee_id. Node Label ':InventoryBatch'. Properties: { inventory_record_id: String (Constraint: UNIQUE), quantity: Integer, location_warehouse: String, location_bin: String, received_date: Datetime, expiry_date: Date, batch_number: String, last_updated: Datetime }. Relationship: (:InventoryBatch)-[:IS_INSTANCE_OF]->(:Component {component_id}). Index on inventory_record_id, component_id.
[ { "role": "user", "content": "For each vehicle, show the vehicle_id, license_plate, date of its most recent trip (actual_arrival), and the odometer_reading at its latest maintenance service." }, { "role": "assistant", "content": "SELECT\n v.vehicle_id,\n v.license_plate,\n (\n SELECT MAX(t.actual_arrival)\n FROM transportation.trips t\n WHERE t.vehicle_id = v.vehicle_id\n ) AS last_trip_arrival,\n ml.odometer_reading\nFROM transportation.vehicles v\nLEFT JOIN LATERAL (\n SELECT odometer_reading\n FROM transportation.maintenance_logs ml\n WHERE ml.vehicle_id = v.vehicle_id\n ORDER BY ml.service_date DESC\n LIMIT 1\n) ml ON TRUE;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE TABLE transportation.passengers ( passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger first_name character varying(128) NOT NULL, -- passenger's first name last_name character varying(128) NOT NULL, -- passenger's last name email character varying(128) UNIQUE, -- email address phone_number character varying(32) UNIQUE, -- phone number date_of_birth date, -- passenger's date of birth loyalty_program_id character varying(64), -- identifier for loyalty program membership created_at timestamp with time zone NOT NULL, -- time when the passenger record was created PRIMARY KEY (passenger_id) ) CREATE 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 )
[ { "role": "user", "content": "For each application that has at least one failed notification, provide the application ID, the total number of notifications received for that application, and the count of failed notifications." }, { "role": "assistant", "content": "SELECT application_id, COUNT(*) AS total_notifications, COUNT(CASE WHEN status = 'Failed' THEN 1 END) AS failed_notifications FROM government_services.notifications GROUP BY application_id HAVING COUNT(CASE WHEN status = 'Failed' THEN 1 END) > 0;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "List all unique claim handler IDs present in the claims table." }, { "role": "assistant", "content": "SELECT DISTINCT claim_handler_id FROM insurance.claims WHERE claim_handler_id IS NOT NULL" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "Show me the object ID, coin type, and balance for all SUI coins where the status is 'active'." }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance FROM sui_coins WHERE status = 'active'" }, { "role": "user", "content": "Also, include the owner address in the result." }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active'" }, { "role": "user", "content": "Filter the results to only show coins where the balance is greater than '100000000000'." }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active' AND CAST(balance AS NUMERIC) > 100000000000" }, { "role": "user", "content": "Sort the results by balance in descending order and limit the output to 10." }, { "role": "assistant", "content": "SELECT object_id, coin_type, balance, owner FROM sui_coins WHERE status = 'active' AND CAST(balance AS NUMERIC) > 100000000000 ORDER BY CAST(balance AS NUMERIC) DESC LIMIT 10" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 )
[ { "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';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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) )
[ { "role": "user", "content": "What are the maintenance costs for a specific aircraft model like the Airbus A320?" }, { "role": "assistant", "content": "I'm sorry, but I don't have access to data regarding maintenance costs for specific aircraft models such as the Airbus A320. The information in the database is limited to details like model name, manufacturer, passenger capacity, and technical specifications. For maintenance cost information, you may need to consult with the manufacturer or a maintenance service provider." } ]
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. ##Table Structure CREATE TABLE manufacturing.aircraft_models ( model_id character varying(64) NOT NULL, model_name character varying(128) NOT NULL, manufacturer character varying(128) NOT NULL, passenger_capacity integer, max_range_km integer, engine_type character varying(100), wingspan_m numeric(6,2), status character varying(50) NOT NULL, first_flight_date date, PRIMARY KEY (model_id) )
[ { "role": "user", "content": "Find all contracts where the deployer address is the same as the contract address, indicating self-deployed contracts, and show their network IDs and deployment timestamps." }, { "role": "assistant", "content": "SELECT address, network_id, deployed_at FROM web3.contracts WHERE address = deployer_address;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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) )
[ { "role": "user", "content": "For each group chat, can you show me each participant's username and the date they joined the chat?" }, { "role": "assistant", "content": "SELECT u.username, c.group_name, cp.joined_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;" }, { "role": "user", "content": "Can you also include the total number of participants for each group chat in the result?" }, { "role": "assistant", "content": "SELECT u.username, c.group_name, cp.joined_at, COUNT(cp2.participant_id) AS total_participants\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\nJOIN social_media.conversation_participants cp2 ON cp2.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = true\nGROUP BY u.username, c.group_name, cp.joined_at;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp ) CREATE TABLE social_media.post_hashtags ( post_hashtag_id text, post_id text, hashtag_id text ) CREATE 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 ) CREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp ) CREATE 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 ) CREATE 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 )
[ { "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';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz ) CREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean ) CREATE 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) ) CREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition game_id uuid NOT NULL, -- FK linking to the game this item belongs to item_name character varying(150) NOT NULL, -- name of the item item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor) description text, -- description of the item rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary) cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD) cost_amount numeric(12, 2), -- price if purchasable attributes jsonb, -- flexible field for item stats or properties PRIMARY KEY (item_id) -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id) ) CREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )
[ { "role": "user", "content": "List usernames and the length of their 'bio' field for users whose 'is_verified' status is true." }, { "role": "assistant", "content": "SELECT username, LENGTH(bio) AS bio_length FROM social_media.users WHERE is_verified IS TRUE;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE social_media.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified bool )
[ { "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;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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) ) CREATE 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 )
[ { "role": "user", "content": "For each chain, which centralized exchange holds the largest total USD value in their token balance as of the most recent snapshot?" }, { "role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n)\nSELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value\nFROM cex_token_balance c\nJOIN latest_snapshot l ON c.snapshot_time = l.max_time\nGROUP BY c.chain, c.exchange\nQUALIFY ROW_NUMBER() OVER(PARTITION BY c.chain ORDER BY SUM(c.usd_value) DESC) = 1;" }, { "role": "user", "content": "Could you also include the number of distinct tokens each exchange holds in those chains?" }, { "role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n GROUP BY c.chain, c.exchange\n),\nranked_exchanges AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY chain ORDER BY total_usd_value DESC) AS rn\n FROM exchange_totals\n)\nSELECT chain, exchange, total_usd_value, token_count\nFROM ranked_exchanges\nWHERE rn = 1;" }, { "role": "user", "content": "I got an error with the QUALIFY clause. Can you rewrite the query using a derived table or CTE instead?" }, { "role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n GROUP BY c.chain, c.exchange\n),\nmax_values AS (\n SELECT chain, MAX(total_usd_value) AS max_usd_value\n FROM exchange_totals\n GROUP BY chain\n)\nSELECT e.chain, e.exchange, e.total_usd_value, e.token_count\nFROM exchange_totals e\nJOIN max_values m ON e.chain = m.chain AND e.total_usd_value = m.max_usd_value;" }, { "role": "user", "content": "Now, only show exchanges where their usd_value is above $5,000,000." }, { "role": "assistant", "content": "WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n GROUP BY c.chain, c.exchange\n),\nmax_values AS (\n SELECT chain, MAX(total_usd_value) AS max_usd_value\n FROM exchange_totals\n GROUP BY chain\n)\nSELECT e.chain, e.exchange, e.total_usd_value, e.token_count\nFROM exchange_totals e\nJOIN max_values m ON e.chain = m.chain AND e.total_usd_value = m.max_usd_value\nWHERE e.total_usd_value > 5000000;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested ) CREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) ) CREATE 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 ) CREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp chain character varying(128) NOT NULL, -- the chain that the token resides address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX exchange character varying(512) NOT NULL, -- a centralized exchange name token_address character varying(128) NOT NULL, -- token contract address token_symbol character varying(512), --token symbol balance numeric(38,10), -- token balance usd_value numeric(38,14), -- value of the token held in USD price double precision, --price of the token in USD ,PRIMARY KEY (snapshot_time, exchange, address, chain, token_address) ) CREATE 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 )
[ { "role": "user", "content": "List all ERC20 tokens where the price is between $1 and $10, including their names, symbols, and contract addresses." }, { "role": "assistant", "content": "SELECT t.name, t.symbol, t.address FROM token_prices_latest t WHERE t.price BETWEEN 1 AND 10;" }, { "role": "user", "content": "I think there's an error in your query - it should be joining with sui_coins_metadata on coin_type not address. Also, can you add the current price to the results?" }, { "role": "assistant", "content": "SELECT scm.name, scm.symbol, tpl.address, tpl.price FROM token_prices_latest tpl JOIN sui_coins_metadata scm ON tpl.address = scm.coin_type WHERE tpl.price BETWEEN 1 AND 10;" }, { "role": "user", "content": "Now filter these results to only show tokens with decimals equal to 18 and sort by name alphabetically." }, { "role": "assistant", "content": "SELECT scm.name, scm.symbol, tpl.address, tpl.price FROM token_prices_latest tpl JOIN sui_coins_metadata scm ON tpl.address = scm.coin_type WHERE tpl.price BETWEEN 1 AND 10 AND scm.decimals = 18 ORDER BY scm.name ASC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE erc1155_approval_for_all ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text ) CREATE TABLE erc20_balances_historical ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.integer ) CREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text ) CREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text ) CREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text ) CREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text ) CREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp ) CREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp ) CREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer ) CREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal ) CREATE 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 ) CREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )
[ { "role": "user", "content": "Show me all insurance plans that have more than 3 patients enrolled as their primary insurance, along with the provider name and count of patients, sorted by patient count in descending order." }, { "role": "assistant", "content": "SELECT ip.insurance_provider, COUNT(pi.patient_id) AS patient_count FROM healthcare.insurance_plans ip JOIN healthcare.patient_insurance pi ON ip.plan_id = pi.plan_id WHERE pi.is_primary = true GROUP BY ip.insurance_provider HAVING COUNT(pi.patient_id) > 3 ORDER BY patient_count DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE healthcare.patients ( patient_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp ) CREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor first_name character varying(100) NOT NULL, -- doctor's first name last_name character varying(100) NOT NULL, -- doctor's last name specialty character varying(100) NOT NULL, -- doctor's medical specialty license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number phone_number character varying(20), -- doctor's contact phone email character varying(128) UNIQUE, -- doctor's contact email hospital_affiliation_id character varying(64), -- FK to hospitals table (optional) 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) ) CREATE 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 ) CREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp ) CREATE 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) ) CREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, -- unique identifier for the medication type medication_name character varying(255) NOT NULL, -- common or brand name generic_name character varying(255), -- generic chemical name manufacturer character varying(100), -- drug manufacturer ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful) description text, -- description of the medication PRIMARY KEY (medication_id) ) CREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text ) CREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link patient_id character varying(64) NOT NULL, -- FK to patients table plan_id character varying(64) NOT NULL, -- FK to insurance_plans table policy_number character varying(100) NOT NULL, -- patient's policy number group_number character varying(100), -- group number, if applicable subscriber_name character varying(200), -- name of the primary policy holder effective_date date NOT NULL, -- date the coverage begins expiration_date date, -- date the coverage ends (if known) is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice )
[ { "role": "user", "content": "Show me the top 5 narratives by market cap, along with their 24-hour trading volume and 7-day price change percentage." }, { "role": "assistant", "content": "SELECT narrative.text, volume_24h.numeric, price_change_percentage_7d.numeric FROM narrative_info ORDER BY market_cap.numeric DESC LIMIT 5;" }, { "role": "user", "content": "Can you also include the top 3 coins for each of these narratives?" }, { "role": "assistant", "content": "SELECT narrative.text, volume_24h.numeric, price_change_percentage_7d.numeric, top_3_coins.text FROM narrative_info ORDER BY market_cap.numeric DESC LIMIT 5;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "Find the total transfer volume for each Avalanche token over the past 7 days and include the token's creator." }, { "role": "assistant", "content": "SELECT a.tick,\n i.creator,\n SUM(a.amt) AS total_volume\nFROM token_activities_avalanche a\nJOIN token_info_avalanche i\n ON a.tick = i.tick\nWHERE a.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY a.tick, i.creator;" }, { "role": "user", "content": "Only include tokens with total_volume > 10000 and sort by total_volume descending." }, { "role": "assistant", "content": "SELECT a.tick,\n i.creator,\n SUM(a.amt) AS total_volume\nFROM token_activities_avalanche a\nJOIN token_info_avalanche i\n ON a.tick = i.tick\nWHERE a.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY a.tick, i.creator\nHAVING SUM(a.amt) > 10000\nORDER BY total_volume DESC;" }, { "role": "user", "content": "Limit the results to the top 5 tokens." }, { "role": "assistant", "content": "SELECT a.tick,\n i.creator,\n SUM(a.amt) AS total_volume\nFROM token_activities_avalanche a\nJOIN token_info_avalanche i\n ON a.tick = i.tick\nWHERE a.block_timestamp >= NOW() - INTERVAL '7 days'\nGROUP BY a.tick, i.creator\nHAVING SUM(a.amt) > 10000\nORDER BY total_volume DESC\nLIMIT 5;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, -- Block number containing the transaction contract_address varchar NOT NULL, -- Event contract address wallet_address varchar NOT NULL, -- The wallet address for the contract amount varchar NOT NULL, -- Wallet's on-chain balance at the corresponding block height pk integer NOT NULL -- Partition key for the table(floor(block_number / 7200)) ) CREATE TABLE nft_holders ( block_number bigint NOT NULL, -- Block number containing the transaction contract_address varchar NOT NULL, -- Event contract address wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter) token_id varchar NOT NULL, -- NFT token id contract_type varchar NOT NULL, -- NFT contract type amount varchar NOT NULL, -- Number of held NFTs pk varchar NOT NULL -- The last string partition of the contract. ) CREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer ) CREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text ) CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar ) CREATE TABLE nft_collections ( blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract contract_address varchar NOT NULL, -- Contract address(with bloom filter) name varchar NOT NULL, -- name fields for the functionType in contract symbol varchar NOT NULL, -- symbol fields for the functionType in contract deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract erc_type varchar NOT NULL, -- The type of token owner varchar NOT NULL, -- owner fields for the functionType in contract traits varchar NOT NULL, -- traits fields for the functionType in contract description varchar NOT NULL, -- description fields for the functionType in contract slug varchar NOT NULL, -- slug fields for the functionType in contract media_info varchar NOT NULL, -- media_info fields for the functionType in contract image_url varchar NOT NULL, -- image_url fields for the functionType in contract banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract banner varchar NOT NULL, -- banner fields for the functionType in contract token_count bigint NOT NULL, -- token_count fields for the functionType in contract floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time / 1000 / 86400 / 30)) ) CREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp ) CREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract address varchar(42) NOT NULL, -- address fields for the functionType in contract decimals bigint NOT NULL, -- decimals fields for the functionType in contract symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract price real NOT NULL, -- price fields for the functionType in contract timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract ) CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer ) CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal ) CREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table) block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table) tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table) tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table) tick varchar NOT NULL, -- Token tick max_supply decimal(38,0) NOT NULL, -- Max supply lim decimal(38,0) NOT NULL, -- Limit of each mint wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint dec integer NOT NULL, -- Decimal for minimum divie creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table) ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 )
[ { "role": "user", "content": "What is the number of guests per country, grouped by country_code?" }, { "role": "assistant", "content": "SELECT country_code,\n COUNT(*) AS guest_count\nFROM hospitality_technology.guests\nGROUP BY country_code;" }, { "role": "user", "content": "Only include countries that have at least 5 guests." }, { "role": "assistant", "content": "SELECT country_code,\n COUNT(*) AS guest_count\nFROM hospitality_technology.guests\nGROUP BY country_code\nHAVING COUNT(*) >= 5;" }, { "role": "user", "content": "Also include the most recently registered guest in each of those countries, showing their full name and created_at." }, { "role": "assistant", "content": "WITH country_counts AS (\n SELECT country_code,\n COUNT(*) AS guest_count,\n MAX(created_at) AS last_reg\n FROM hospitality_technology.guests\n GROUP BY country_code\n HAVING COUNT(*) >= 5\n)\nSELECT cc.country_code,\n cc.guest_count,\n g.first_name || ' ' || g.last_name AS last_guest_name,\n g.created_at AS last_registration\nFROM country_counts cc\nJOIN hospitality_technology.guests g\n ON g.country_code = cc.country_code\n AND g.created_at = cc.last_reg;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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) )
[ { "role": "user", "content": "Show me the service name, category, and price for all services that are currently not available." }, { "role": "assistant", "content": "SELECT service_name, category, price FROM hospitality_technology.services WHERE is_available = FALSE;" }, { "role": "user", "content": "Filter this list further to only include services from the 'Transportation' department that are not available." }, { "role": "assistant", "content": "SELECT service_name, category, price FROM hospitality_technology.services WHERE is_available = FALSE AND department = 'Transportation';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "Find all documents that are larger than 5MB. Show the document ID, claim ID, file name, and file size in bytes." }, { "role": "assistant", "content": "SELECT document_id, claim_id, file_name, file_size_bytes\nFROM insurance.claim_documents\nWHERE file_size_bytes > 5242880;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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) ) CREATE 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 )
[ { "role": "user", "content": "List lawyers who have any unbilled time entries. Show their first name, last name, and the count of their unbilled entries." }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, COUNT(T2.entry_id) FROM lawyers AS T1 JOIN time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id WHERE T2.is_billed = false GROUP BY T1.lawyer_id, T1.first_name, T1.last_name;" }, { "role": "user", "content": "Modify that query to only include entries marked as billable, and instead show the total hours spent rather than the count." }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, SUM(T2.hours_spent) FROM lawyers AS T1 JOIN time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id WHERE T2.is_billed = false AND T2.is_billable = true GROUP BY T1.lawyer_id, T1.first_name, T1.last_name;" }, { "role": "user", "content": "Now, only show lawyers with more than 10 unbilled billable hours in total, and sort the results by the total hours descending." }, { "role": "assistant", "content": "SELECT T1.first_name, T1.last_name, SUM(T2.hours_spent) FROM lawyers AS T1 JOIN time_entries AS T2 ON T1.lawyer_id = T2.lawyer_id WHERE T2.is_billed = false AND T2.is_billable = true GROUP BY T1.lawyer_id, T1.first_name, T1.last_name HAVING SUM(T2.hours_spent) > 10 ORDER BY SUM(T2.hours_spent) DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE legal_services.lawyers ( lawyer_id text PRIMARY KEY, first_name text, last_name text, bar_number text UNIQUE, firm_id text, email text UNIQUE, phone text, specialization text, hire_date timestamp, is_partner bool ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 )
[ { "role": "user", "content": "Find the names of service locations where services categorized as 'Licensing' have had appointments scheduled." }, { "role": "assistant", "content": "SELECT DISTINCT T1.location_name FROM service_locations AS T1 JOIN appointments AS T2 ON T1.location_id = T2.location_id JOIN services AS T3 ON T2.service_id = T3.service_id WHERE T3.category = 'Licensing';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, -- unique identifier for the service agency_id character varying(64) NOT NULL, -- FK to agencies table service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal) description text, category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits eligibility_criteria text, -- description of who is eligible standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service average_processing_time_days integer, -- estimated processing time is_active boolean DEFAULT true, -- whether the service is currently offered online_application_url character varying(255), PRIMARY KEY (service_id) ) CREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, -- unique identifier for the physical location agency_id character varying(64) NOT NULL, -- FK to agencies table location_name character varying(200), -- e.g., Downtown DMV Office address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, -- description of opening times contact_phone character varying(32), is_accessible boolean, -- accessibility information (e.g., wheelchair access) PRIMARY KEY (location_id) ) CREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment citizen_id character varying(64) NOT NULL, -- FK to citizens table employee_id character varying(64), -- FK to employees table (optional, if assigned) location_id character varying(64), -- FK to service_locations table (if physical) service_id character varying(64), -- FK to services table (optional, if related to specific service) scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, -- reason for the appointment status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show booking_method character varying(50), -- e.g., Online, Phone, In-Person created_at timestamp NOT NULL, -- when the appointment was booked notes text, PRIMARY KEY (appointment_id) )
[ { "role": "user", "content": "Show me all wallet addresses that hold more than 1000 of any ERC1155 token, along with the token ID and amount, from the nft_holders table." }, { "role": "assistant", "content": "SELECT wallet_address, token_id, amount FROM nft_holders WHERE contract_type = 'ERC1155' AND CAST(amount AS decimal) > 1000;" }, { "role": "user", "content": "Can you join this with the nft_metadata table to include the name and image_uri of each token?" }, { "role": "assistant", "content": "SELECT nh.wallet_address, nh.token_id, nh.amount, nm.name, nm.image_uri FROM nft_holders nh JOIN nft_metadata nm ON nh.contract_address = nm.contract_address AND nh.token_id = nm.token_id WHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS decimal) > 1000;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer ) CREATE 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 ) CREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer ) CREATE 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 ) CREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text ) CREATE TABLE nft_metadata ( blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract contract_address varchar NOT NULL, -- Contract address(with bloom filter) token_id varchar NOT NULL, -- The number of the token contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract erc_type varchar NOT NULL, -- The type of token amount bigint NOT NULL, -- amount fields for the functionType in contract minter varchar NOT NULL, -- minter fields for the functionType in contract owner varchar NOT NULL, -- owner fields for the functionType in contract mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract metadata varchar NOT NULL, -- metadata fields for the functionType in contract name varchar NOT NULL, -- name fields for the functionType in contract image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract traits varchar NOT NULL, -- traits fields for the functionType in contract updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract status varchar NOT NULL, -- status fields for the functionType in contract rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract pk integer NOT NULL -- Partition key for the table(floor(mint_time / 1000 / 86400 / 30)) ) CREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp ) CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table) block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table) tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table) tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table) tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription max_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription lim decimal(38,0) NOT NULL, -- Mint limit: limit per inscription wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint dec integer NOT NULL, -- Decimal for minimum divie creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table) ) CREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table) block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table) tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table) tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table) log_index integer NOT NULL, -- Index of the log within the transaction type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list) tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription id varchar(255) NOT NULL, -- Unique identifier of the inscription 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" from_address varchar(42) NOT NULL, -- Address sending the inscription to_address varchar(42) NOT NULL -- Address receiving the inscription ) CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, -- Block number containing the transaction block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription wallet_address varchar(42) NOT NULL, -- Address of owner total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height )
[ { "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;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 )
[ { "role": "user", "content": "Find, for each case, pairs of documents where one document_type is 'Contract' and the other is 'Evidence'. Return the case_id, the name of the contract document as contract_name, and the name of the evidence document as evidence_name." }, { "role": "assistant", "content": "SELECT d1.case_id,\n d1.document_name AS contract_name,\n d2.document_name AS evidence_name\nFROM legal_services.documents d1\nJOIN legal_services.documents d2\n ON d1.case_id = d2.case_id\nWHERE d1.document_type = 'Contract'\n AND d2.document_type = 'Evidence';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "List the plan_id, plan_name, and plan_type for all insurance plans where the insurance_provider is 'Humana'." }, { "role": "assistant", "content": "SELECT\n plan_id,\n plan_name,\n plan_type\nFROM healthcare.insurance_plans\nWHERE\n insurance_provider = 'Humana';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment patient_id character varying(64) NOT NULL, -- FK to patients table doctor_id character varying(64) NOT NULL, -- FK to doctors table appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment duration_minutes integer NOT NULL, -- expected duration in minutes reason text, -- reason for the visit status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show location_id character varying(64), -- FK to a potential locations/clinics table notes text, -- notes related to scheduling created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) ) CREATE TABLE healthcare.medical_records ( record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry patient_id character varying(64) NOT NULL, -- FK to patients table appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt) doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record) record_date timestamp with time zone NOT NULL, -- date the record/observation was made chief_complaint text, -- patient's primary reason for visit present_illness_history text, -- detailed history of the current issue past_medical_history text, -- relevant past conditions/surgeries physical_examination_notes text, -- findings from the physical exam assessment text, -- doctor's assessment/diagnosis summary treatment_plan text, -- planned course of action vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (record_id) ) CREATE 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 ) CREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text ) CREATE 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) ) CREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan plan_name character varying(200) NOT NULL, -- name of the insurance plan insurance_provider character varying(100) NOT NULL, -- name of the insurance company plan_type character varying(50), -- e.g., PPO, HMO, EPO contact_phone character varying(20), -- provider contact number website character varying(255), -- provider website PRIMARY KEY (plan_id) )
[ { "role": "user", "content": "What is the detailed repair history for train number T5678?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide the detailed repair history for train number T5678 as this information is not available in the current database table. The table only includes basic information such as train ID, model, manufacturer, capacity, status, and maintenance dates. For repair history, you may need to consult a different database or department." } ]
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. ##Table Structure CREATE TABLE train_station_management.trains ( train_id text, train_number text, model text, manufacturer text, year_manufactured integer, capacity integer, status text, last_maintenance_date date, next_maintenance_date date )
[ { "role": "user", "content": "Show the IDs and registration dates of all verified citizens who could be eligible for at least one active service. Display the citizen ID and registration date." }, { "role": "assistant", "content": "SELECT DISTINCT c.citizen_id, c.registration_date\nFROM government_services.citizens c\nJOIN government_services.services s ON s.is_active = true\nWHERE c.is_verified = true;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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) ) CREATE 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 )
[ { "role": "user", "content": "Which exchanges hold the highest total USD value of tokens on the Ethereum chain, and what are their top 3 tokens by USD value?" }, { "role": "assistant", "content": "SELECT exchange, token_symbol, usd_value FROM (SELECT exchange, token_symbol, usd_value, ROW_NUMBER() OVER (PARTITION BY exchange ORDER BY usd_value DESC) as rank FROM cex_token_balance WHERE chain = 'Ethereum') WHERE rank <= 3 ORDER BY exchange, usd_value DESC;" }, { "role": "user", "content": "Can you modify this to show the top 5 exchanges by total USD value instead, and include their total balance across all tokens?" }, { "role": "assistant", "content": "SELECT exchange, SUM(usd_value) as total_usd_value, SUM(balance) as total_balance FROM cex_token_balance WHERE chain = 'Ethereum' GROUP BY exchange ORDER BY total_usd_value DESC LIMIT 5;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "Could you list all pairs of developers that are based in the same country and share the same website domain?" }, { "role": "assistant", "content": "SELECT\n d1.name AS developer1_name,\n d2.name AS developer2_name,\n d1.country,\n d1.website\nFROM\n gaming_technology.developers AS d1\nJOIN\n gaming_technology.developers AS d2 ON d1.country = d2.country\n AND d1.website = d2.website\n AND d1.developer_id < d2.developer_id\nWHERE\n d1.country IS NOT NULL\n AND d1.website IS NOT NULL AND d1.website != '';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE gaming_technology.developers ( developer_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the developer studio name character varying(150) NOT NULL UNIQUE, -- name of the development studio country character varying(100), -- country where the studio is based founded_year integer, -- year the studio was founded website character varying(255), -- developer's official website created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (developer_id) )
[ { "role": "user", "content": "Show me wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount, sorted by amount in descending order." }, { "role": "assistant", "content": "SELECT b.wallet_address, t.symbol, b.amount FROM erc20_balances b JOIN sui_coins_metadata t ON b.contract_address = t.coin_type WHERE CAST(b.amount AS decimal) > 1000 ORDER BY CAST(b.amount AS decimal) DESC;" }, { "role": "user", "content": "Can you also include the current price of each token from the token_prices_latest table?" }, { "role": "assistant", "content": "SELECT b.wallet_address, t.symbol, b.amount, p.price FROM erc20_balances b JOIN sui_coins_metadata t ON b.contract_address = t.coin_type JOIN token_prices_latest p ON b.contract_address = p.address WHERE CAST(b.amount AS decimal) > 1000 ORDER BY CAST(b.amount AS decimal) DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, -- Block number containing the transaction block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction transaction_index integer NOT NULL, -- Index of the transaction within the block transaction_hash varchar(66) NOT NULL, -- Transaction hash log_index integer NOT NULL, -- Log index contract_address varchar(42) NOT NULL -- Event contract address ) CREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text ) CREATE 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 ) CREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar ) CREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar ) CREATE TABLE nft_metadata ( blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract contract_address varchar NOT NULL, -- Contract address(with bloom filter) token_id varchar NOT NULL, -- The number of the token contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract erc_type varchar NOT NULL, -- The type of token amount bigint NOT NULL, -- amount fields for the functionType in contract minter varchar NOT NULL, -- minter fields for the functionType in contract owner varchar NOT NULL, -- owner fields for the functionType in contract mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract metadata varchar NOT NULL, -- metadata fields for the functionType in contract name varchar NOT NULL, -- name fields for the functionType in contract image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract traits varchar NOT NULL, -- traits fields for the functionType in contract updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract status varchar NOT NULL, -- status fields for the functionType in contract rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract pk integer NOT NULL -- Partition key for the table(floor(mint_time / 1000 / 86400 / 30)) ) CREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp ) CREATE 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 ) CREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, -- address fields for the functionType in contract table_id varchar NOT NULL, -- table_id fields for the functionType in contract key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract key0 varchar NOT NULL, -- key0 fields for the functionType in contract key1 varchar NOT NULL, -- key1 fields for the functionType in contract static_data varchar NOT NULL, -- static_data fields for the functionType in contract encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract block_number bigint NOT NULL, -- Block number uniquely identifying the block log_index bigint NOT NULL -- Index of the log within the transaction ) CREATE 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 ) CREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, -- Block number containing the transaction block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription wallet_address varchar(42) NOT NULL, -- Address of owner total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height ) CREATE 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 )
[ { "role": "user", "content": "List all appointments scheduled for '2024-07-25' with a status of 'Scheduled'." }, { "role": "assistant", "content": "SELECT * FROM legal_services.appointments WHERE DATE(start_time) = '2024-07-25' AND status = 'Scheduled'" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "Which smart money address on the Ethereum chain has the lowest ROI, and what are their profit and rank?" }, { "role": "assistant", "content": "SELECT address, roi, profit, rank FROM smart_money_profit WHERE chain = 'Ethereum' ORDER BY roi ASC LIMIT 1;" }, { "role": "user", "content": "Can you also include the realized_ratio for this address?" }, { "role": "assistant", "content": "SELECT address, roi, profit, rank, realized_ratio FROM smart_money_profit WHERE chain = 'Ethereum' ORDER BY roi ASC LIMIT 1;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "For each recipient address, count how many token transfers they have received." }, { "role": "assistant", "content": "SELECT to_address, COUNT(*) AS received_transfer_count FROM web3.token_transfers GROUP BY to_address;" }, { "role": "user", "content": "Only show addresses that have received more than 100 transfers." }, { "role": "assistant", "content": "SELECT to_address, COUNT(*) AS received_transfer_count FROM web3.token_transfers GROUP BY to_address HAVING COUNT(*) > 100;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "For each doctor, show their full name along with all plan names of insurance plans that have a 'contact_phone' beginning with '+44'." }, { "role": "assistant", "content": "SELECT d.first_name, d.last_name, ip.plan_name\nFROM healthcare.doctors d\nCROSS JOIN healthcare.insurance_plans ip\nWHERE ip.contact_phone LIKE '+44%';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
[ { "role": "user", "content": "Can you list all SUI coins with 'active' status and their owner addresses and balances?" }, { "role": "assistant", "content": "SELECT object_id, coin_type, owner, balance\nFROM sui_coins\nWHERE status = 'active';" }, { "role": "user", "content": "Add the coin symbol and name from the sui_coins_metadata table." }, { "role": "assistant", "content": "SELECT sc.object_id, sc.coin_type, sc.owner, sc.balance, scm.symbol, scm.name\nFROM sui_coins sc\nLEFT JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'active';" }, { "role": "user", "content": "Only include coins where the description mentions 'utility'." }, { "role": "assistant", "content": "SELECT sc.object_id, sc.coin_type, sc.owner, sc.balance, scm.symbol, scm.name\nFROM sui_coins sc\nLEFT JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'active' AND scm.description ILIKE '%utility%';" }, { "role": "user", "content": "Limit the output to the top 10 coins sorted by balance descending." }, { "role": "assistant", "content": "SELECT sc.object_id, sc.coin_type, sc.owner, sc.balance, scm.symbol, scm.name\nFROM sui_coins sc\nLEFT JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'active' AND scm.description ILIKE '%utility%'\nORDER BY CAST(sc.balance AS BIGINT) DESC\nLIMIT 10;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar ) CREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer ) CREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar ) CREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer ) CREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar ) CREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar ) CREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar ) CREATE 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 ) CREATE 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 ) CREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp ) CREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp ) CREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer ) CREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar ) CREATE 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 ) CREATE 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 )
[ { "role": "user", "content": "List the booking ID, the first name, and the last name of the passenger for all bookings." }, { "role": "assistant", "content": "SELECT T1.booking_id , T2.first_name , T2.last_name FROM transportation.bookings AS T1 JOIN transportation.passengers AS T2 ON T1.passenger_id = T2.passenger_id" }, { "role": "user", "content": "Now, only include bookings where the fare is greater than 100." }, { "role": "assistant", "content": "SELECT T1.booking_id , T2.first_name , T2.last_name FROM transportation.bookings AS T1 JOIN transportation.passengers AS T2 ON T1.passenger_id = T2.passenger_id WHERE T1.fare > 100" }, { "role": "user", "content": "For these bookings with fares over 100, also show the booking status and order the results by fare in descending order." }, { "role": "assistant", "content": "SELECT T1.booking_id , T2.first_name , T2.last_name , T1.status FROM transportation.bookings AS T1 JOIN transportation.passengers AS T2 ON T1.passenger_id = T2.passenger_id WHERE T1.fare > 100 ORDER BY T1.fare DESC" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 )
[ { "role": "user", "content": "Show me document_id, application_id, and verification_status for all documents submitted by citizen 'cit123'." }, { "role": "assistant", "content": "SELECT document_id,\n application_id,\n verification_status\nFROM documents\nWHERE citizen_id = 'cit123';" }, { "role": "user", "content": "I got an error: relation 'documents' does not exist." }, { "role": "assistant", "content": "SELECT document_id,\n application_id,\n verification_status\nFROM government_services.documents\nWHERE citizen_id = 'cit123';" }, { "role": "user", "content": "Now, only include documents where verification_status = 'Pending'." }, { "role": "assistant", "content": "SELECT document_id,\n application_id,\n verification_status\nFROM government_services.documents\nWHERE citizen_id = 'cit123'\n AND verification_status = 'Pending';" }, { "role": "user", "content": "Also, limit the results to files uploaded in 2024." }, { "role": "assistant", "content": "SELECT document_id,\n application_id,\n verification_status\nFROM government_services.documents\nWHERE citizen_id = 'cit123'\n AND verification_status = 'Pending'\n AND upload_timestamp >= '2024-01-01'\n AND upload_timestamp < '2025-01-01';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 )
[ { "role": "user", "content": "Get a list of room types along with their property name and the count of rooms currently Available for each type." }, { "role": "assistant", "content": "SELECT rt.type_name, p.property_name, COUNT(r.room_id) AS available_rooms_count\nFROM hospitality_technology.room_types rt\nJOIN hospitality_technology.rooms r ON rt.room_type_id = r.room_type_id\n AND r.status = 'Available'\nJOIN hospitality_technology.properties p ON rt.property_id = p.property_id\nGROUP BY rt.type_name, p.property_name;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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) ) CREATE 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) ) CREATE 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) ) CREATE 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) ) CREATE 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) ) CREATE 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) ) CREATE 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) ) CREATE 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) ) CREATE 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) )
[ { "role": "user", "content": "List all rooms that have a 'Jacuzzi' feature, including the room_number, property_id, type_name, and base_rate." }, { "role": "assistant", "content": "SELECT r.room_number,\n r.property_id,\n rt.type_name,\n rt.base_rate\nFROM hospitality_technology.rooms AS r\nJOIN hospitality_technology.room_types AS rt\n ON r.room_type_id = rt.room_type_id\n AND r.property_id = rt.property_id\nWHERE r.features ILIKE '%Jacuzzi%';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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 )
[ { "role": "user", "content": "List each guest’s full name and the total number of service orders they have placed, ordered by order count descending." }, { "role": "assistant", "content": "SELECT g.guest_id,\n g.first_name || ' ' || g.last_name AS full_name,\n COUNT(so.order_id) AS order_count\nFROM hospitality_technology.guests g\nLEFT JOIN hospitality_technology.service_orders so\n ON g.guest_id = so.guest_id\nGROUP BY g.guest_id, full_name\nORDER BY order_count DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE 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) )
[ { "role": "user", "content": "Show me all lawyers' full names, their bar number, and if they are partners, the full name of another partner from their firm." }, { "role": "assistant", "content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1;" }, { "role": "user", "content": "Only include lawyers who have an email address specified." }, { "role": "assistant", "content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1\nWHERE l1.email IS NOT NULL AND l1.email <> '';" }, { "role": "user", "content": "Actually, restrict it to lawyers hired in or after 2023." }, { "role": "assistant", "content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1\nWHERE l1.email IS NOT NULL AND l1.email <> '' AND l1.hire_date >= '2023-01-01';" }, { "role": "user", "content": "Sort the results by the lawyer's last name in descending order." }, { "role": "assistant", "content": "SELECT l1.first_name || ' ' || l1.last_name AS lawyer_full_name, l1.bar_number,\n CASE WHEN l1.is_partner = TRUE THEN (\n SELECT l2.first_name || ' ' || l2.last_name\n FROM legal_services.lawyers l2\n WHERE l2.firm_id = l1.firm_id AND l2.is_partner = TRUE AND l2.lawyer_id <> l1.lawyer_id\n LIMIT 1\n ) ELSE NULL END AS another_partner_full_name\nFROM legal_services.lawyers l1\nWHERE l1.email IS NOT NULL AND l1.email <> '' AND l1.hire_date >= '2023-01-01'\nORDER BY l1.last_name DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )
[ { "role": "user", "content": "Show me the number of game servers in each region and the average maximum number of players they can accommodate. Exclude any servers that are currently offline." }, { "role": "assistant", "content": "SELECT region, COUNT(server_id) AS server_count, AVG(max_players) AS average_max_players FROM gaming_technology.servers WHERE status != 'offline' GROUP BY region;" }, { "role": "user", "content": "Please filter the results to only include regions that have more than 5 active servers." }, { "role": "assistant", "content": "SELECT region, COUNT(server_id) AS server_count, AVG(max_players) AS average_max_players FROM gaming_technology.servers WHERE status != 'offline' GROUP BY region HAVING COUNT(server_id) > 5;" }, { "role": "user", "content": "Can you also include the total number of current players across all active servers in each of those regions?" }, { "role": "assistant", "content": "SELECT region, COUNT(server_id) AS server_count, AVG(max_players) AS average_max_players, SUM(current_players) AS total_current_players FROM gaming_technology.servers WHERE status != 'offline' GROUP BY region HAVING COUNT(server_id) > 5;" }, { "role": "user", "content": "Order the final results by the total number of current players in descending order." }, { "role": "assistant", "content": "SELECT region, COUNT(server_id) AS server_count, AVG(max_players) AS average_max_players, SUM(current_players) AS total_current_players FROM gaming_technology.servers WHERE status != 'offline' GROUP BY region HAVING COUNT(server_id) > 5 ORDER BY total_current_players DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player username character varying(100) NOT NULL UNIQUE, -- player's chosen display name email character varying(255) NOT NULL UNIQUE, -- player's email address for login/recovery password_hash text NOT NULL, -- securely hashed password registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created last_login timestamp with time zone, -- timestamp of the last successful login country_code character(2), -- player's country (ISO 3166-1 alpha-2) status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended) profile_data jsonb, -- flexible field for avatar url, bio, preferences etc. PRIMARY KEY (player_id) ) CREATE TABLE gaming_technology.games ( game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game title character varying(200) NOT NULL, -- official title of the game developer_id uuid NOT NULL, -- FK linking to the developers table publisher_id uuid, -- FK linking to a potential publishers table (optional) genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy) release_date date, -- official release date description text, -- short description or synopsis of the game platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile) engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity) website character varying(255), -- official website URL PRIMARY KEY (game_id) -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint ) CREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session player_id uuid NOT NULL, -- FK linking to the players table game_id uuid NOT NULL, -- FK linking to the games table server_id uuid, -- FK linking to the servers table (nullable for single-player) start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began end_time timestamp with time zone, -- when the session ended (null if ongoing) duration_seconds integer, -- calculated duration of the session in seconds score integer, -- player's score for the session, if applicable session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used) PRIMARY KEY (session_id) -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id), -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id), -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id) ) CREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance game_id uuid NOT NULL, -- FK linking to the game this server hosts server_name character varying(150), -- display name for the server region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2) ip_address character varying(45), -- IP address (IPv4 or IPv6) port integer, -- network port number current_players integer NOT NULL DEFAULT 0, -- number of players currently connected max_players integer NOT NULL, -- maximum player capacity status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance) last_heartbeat timestamp with time zone, -- last time the server reported its status PRIMARY KEY (server_id) -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id) ) CREATE TABLE gaming_technology.achievements ( achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to name character varying(150) NOT NULL, -- name of the achievement description text NOT NULL, -- how to unlock the achievement icon_url character varying(255), -- URL for the achievement's icon points integer DEFAULT 0, -- points awarded for unlocking (optional) hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked PRIMARY KEY (achievement_id) -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id) ) CREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance player_id uuid NOT NULL, -- FK linking to the player who unlocked it achievement_id uuid NOT NULL, -- FK linking to the achievement definition unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id), -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id) ) CREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition game_id uuid NOT NULL, -- FK linking to the game this item belongs to item_name character varying(150) NOT NULL, -- name of the item item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor) description text, -- description of the item rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary) cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD) cost_amount numeric(12, 2), -- price if purchasable attributes jsonb, -- flexible field for item stats or properties PRIMARY KEY (item_id) -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id) ) CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an inventory entry player_id uuid NOT NULL, -- FK linking to the player owning the item item_id uuid NOT NULL, -- FK linking to the item definition quantity integer NOT NULL DEFAULT 1, -- number of items held (for stackable items) acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the item was acquired instance_data jsonb, -- data specific to this instance (e.g., weapon mods, durability) PRIMARY KEY (inventory_id), -- Optional unique constraint if items are non-stackable or unique instances -- UNIQUE (player_id, item_id) -- Use if quantity is always 1 -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id), -- FOREIGN KEY (item_id) REFERENCES gaming_technology.in_game_items(item_id) )
[ { "role": "user", "content": "List each employee's first and last name along with their manager's first and last name." }, { "role": "assistant", "content": "SELECT e.first_name || ' ' || e.last_name AS employee_name,\n m.first_name || ' ' || m.last_name AS manager_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id;" }, { "role": "user", "content": "Filter the result to include only active employees and exclude those in the 'Executive' job_title." }, { "role": "assistant", "content": "SELECT e.first_name || ' ' || e.last_name AS employee_name,\n m.first_name || ' ' || m.last_name AS manager_name\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.status = 'Active'\n AND e.job_title <> 'Executive';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE TABLE financial_services.transactions ( transaction_id text PRIMARY KEY, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text ) CREATE 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 ) CREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )
[ { "role": "user", "content": "Can you show, for each employee, the full name and job title of their direct manager, as well as the employee's department and branch_id?" }, { "role": "assistant", "content": "SELECT e.employee_id, e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.department AS employee_department, e.branch_id AS employee_branch_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name, m.job_title AS manager_job_title\nFROM financial_services.employees e\nLEFT JOIN financial_services.employees m ON e.manager_id = m.employee_id;" }, { "role": "user", "content": "Actually, show only employees who have a manager assigned, and include only those where the manager works at a different branch than the employee." }, { "role": "assistant", "content": "SELECT e.employee_id, e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.department AS employee_department, e.branch_id AS employee_branch_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name, m.job_title AS manager_job_title, m.branch_id AS manager_branch_id\nFROM financial_services.employees e\nINNER JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.branch_id IS DISTINCT FROM m.branch_id;" }, { "role": "user", "content": "Now, only include employees who were hired after 2021-01-01." }, { "role": "assistant", "content": "SELECT e.employee_id, e.first_name AS employee_first_name, e.last_name AS employee_last_name, e.department AS employee_department, e.branch_id AS employee_branch_id, m.first_name AS manager_first_name, m.last_name AS manager_last_name, m.job_title AS manager_job_title, m.branch_id AS manager_branch_id\nFROM financial_services.employees e\nINNER JOIN financial_services.employees m ON e.manager_id = m.employee_id\nWHERE e.branch_id IS DISTINCT FROM m.branch_id\n AND e.hire_date > '2021-01-01';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE TABLE financial_services.transactions ( transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction account_id character varying(64) NOT NULL, -- account involved in the transaction related_account_id character varying(64), -- counterpart account for transfers transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest amount numeric(19, 4) NOT NULL, -- transaction amount currency character varying(3) NOT NULL, -- transaction currency transaction_date timestamp NOT NULL, -- exact time of the transaction effective_date date NOT NULL, -- date the transaction affects the balance description text, -- description or memo of the transaction status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed reference_number character varying(128), -- external reference if applicable (e.g., check number) PRIMARY KEY (transaction_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id) ) CREATE 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 ) CREATE 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 ) CREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, -- unique identifier for the employee first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst department character varying(100), -- e.g., Retail Banking, Wealth Management, IT branch_id character varying(64), -- Identifier for the branch they work at (if applicable) email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, -- Date of termination, null if currently employed manager_id character varying(64), -- Self-referencing key for manager relationship status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) ) CREATE 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) )
[ { "role": "user", "content": "Can you give me the total number of appointments grouped by status?" }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS total_appointments\nFROM healthcare.appointments\nGROUP BY status;" }, { "role": "user", "content": "Filter the result to show only statuses with more than 50 appointments." }, { "role": "assistant", "content": "SELECT status,\n COUNT(*) AS total_appointments\nFROM healthcare.appointments\nGROUP BY status\nHAVING COUNT(*) > 50;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "Find pairs of claims filed by the same customer where the incident dates are within 7 days of each other. Return customer_id, both claim IDs, and their incident dates." }, { "role": "assistant", "content": "SELECT c1.customer_id,\n c1.claim_id AS claim1_id,\n c1.incident_date AS incident1,\n c2.claim_id AS claim2_id,\n c2.incident_date AS incident2\nFROM insurance.claims c1\nJOIN insurance.claims c2\n ON c1.customer_id = c2.customer_id\n AND c1.claim_id < c2.claim_id\n AND c1.incident_date BETWEEN c2.incident_date - INTERVAL '7 days' AND c2.incident_date + INTERVAL '7 days';" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, -- unique identifier for the claim policy_id character varying(64) NOT NULL, -- identifier of the policy under which the claim is made (FK to policies) customer_id character varying(64) NOT NULL, -- identifier of the customer making the claim (FK to customers) incident_date timestamp NOT NULL, -- date and time of the incident leading to the claim reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- date the claim was reported description text NOT NULL, -- detailed description of the incident and claim estimated_loss numeric(15, 2), -- initial estimated cost of the loss status character varying(30) NOT NULL, -- e.g., Filed, Processing, Under Review, Approved, Denied, Settled settlement_amount numeric(15, 2), -- final amount paid out settlement_date date, claim_handler_id character varying(64), -- identifier for the employee handling the claim (FK to employees/adjusters) police_report_number character varying(100), PRIMARY KEY (claim_id) )
[ { "role": "user", "content": "Find all nodes that were last seen in the last 7 days, along with their IP addresses and ports." }, { "role": "assistant", "content": "SELECT node_id, ip_address, port FROM blockchain.nodes WHERE last_seen >= NOW() - INTERVAL '7 days';" }, { "role": "user", "content": "Now filter these results to only show nodes with port numbers between 8000 and 9000." }, { "role": "assistant", "content": "SELECT node_id, ip_address, port FROM blockchain.nodes WHERE last_seen >= NOW() - INTERVAL '7 days' AND port BETWEEN 8000 AND 9000;" }, { "role": "user", "content": "How many unique IP addresses are there among these active nodes?" }, { "role": "assistant", "content": "SELECT COUNT(DISTINCT ip_address) FROM blockchain.nodes WHERE last_seen >= NOW() - INTERVAL '7 days' AND port BETWEEN 8000 AND 9000;" }, { "role": "user", "content": "Can you show me the count of nodes for each unique IP address?" }, { "role": "assistant", "content": "SELECT ip_address, COUNT(node_id) AS node_count FROM blockchain.nodes WHERE last_seen >= NOW() - INTERVAL '7 days' AND port BETWEEN 8000 AND 9000 GROUP BY ip_address;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE blockchain.blocks ( block_id text, previous_block_id text, timestamp timestamp, nonce integer, merkle_root text, difficulty integer ) CREATE TABLE blockchain.transactions ( transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction block_id character varying(64) NOT NULL, -- identifier of the block containing the transaction sender_address character varying(128) NOT NULL, -- address of the sender receiver_address character varying(128) NOT NULL, -- address of the receiver amount numeric(38,14) NOT NULL, -- amount transferred timestamp timestamp NOT NULL, -- time when the transaction was created signature text NOT NULL, -- digital signature of the transaction PRIMARY KEY (transaction_id) ) CREATE TABLE blockchain.addresses ( address_id text PRIMARY KEY, public_key text, balance numeric ) CREATE TABLE blockchain.nodes ( node_id character varying(64) NOT NULL, -- unique identifier for the node ip_address character varying(15) NOT NULL, -- IP address of the node port integer NOT NULL, -- port number of the node last_seen timestamp NOT NULL, -- last time the node was active PRIMARY KEY (node_id) ) CREATE TABLE blockchain.smart_contracts ( contract_id text PRIMARY KEY, creator_address text, code text, timestamp timestamp )
[ { "role": "user", "content": "For projects that have completed more than one fundraising round, calculate the average investment value across all their recorded rounds. Display the project name and this average value." }, { "role": "assistant", "content": "SELECT project_name, AVG(investment_value) AS average_investment FROM project_fundraising_record GROUP BY project_name HAVING COUNT(*) > 1;" }, { "role": "user", "content": "Can you modify this to only show projects where the average investment value is greater than 10 million USD and order the results by average investment value descending?" }, { "role": "assistant", "content": "SELECT project_name, AVG(investment_value) AS average_investment FROM project_fundraising_record GROUP BY project_name HAVING COUNT(*) > 1 AND AVG(investment_value) > 10000000 ORDER BY average_investment DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )
[ { "role": "user", "content": "List all users who have bought assets, along with their wallet addresses." }, { "role": "assistant", "content": "SELECT DISTINCT T1.user_id, T1.address FROM wallets AS T1 JOIN trades AS T2 ON T1.user_id = T2.buyer_id;" }, { "role": "user", "content": "Filter this list to include only trades made in the last 30 days." }, { "role": "assistant", "content": "SELECT DISTINCT T1.user_id, T1.address FROM wallets AS T1 JOIN trades AS T2 ON T1.user_id = T2.buyer_id WHERE T2.traded_at >= datetime('now', '-30 days');" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp ) CREATE 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 ) CREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean ) CREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text ) CREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp ) CREATE TABLE trading_platform.logs ( log_id.text, user_id.text, action.text, details.text, logged_at.timestamp )
[ { "role": "user", "content": "List each employee's first and last name along with the count of active services offered by their agency." }, { "role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name;" }, { "role": "user", "content": "Actually, only include employees whose service count is greater than 5." }, { "role": "assistant", "content": "SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(s.service_id) > 5;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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) ) CREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) ) CREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) ) CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) ) CREATE 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) ) CREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) ) CREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) ) CREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) ) CREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )
[ { "role": "user", "content": "Show me the top 5 narratives by market cap, along with their 24-hour trading volume and 7-day price change percentage." }, { "role": "assistant", "content": "SELECT narrative, market_cap, volume_24h, price_change_percentage_7d FROM narrative_info ORDER BY market_cap DESC LIMIT 5;" }, { "role": "user", "content": "Can you also include the top 3 coins for each of these narratives and filter to only show narratives with a positive 7-day price change?" }, { "role": "assistant", "content": "SELECT narrative, market_cap, volume_24h, price_change_percentage_7d, top_3_coins FROM narrative_info WHERE price_change_percentage_7d > 0 ORDER BY market_cap DESC LIMIT 5;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure "CREATE TABLE narrative_info (", "narrative character varying(512) NOT NULL, -- the id of narrative", "top_3_coins text, -- the top 3 tokens in the narrative", "price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative", "price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative", "price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative", "market_cap double precision, -- the market cap of the narrative", "volume_24h double precision, -- the trade volume of the narrative", "trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative", "token_num bigint, -- total token number in the narrative", ",PRIMARY KEY (narrative));"
[ { "role": "user", "content": "List all node pairs that operate on the same port and were last_seen within 30 minutes of each other, showing both node_ids, the port, and the time difference in minutes." }, { "role": "assistant", "content": "SELECT n1.node_id AS node1_id, n2.node_id AS node2_id, n1.port,\n ABS(EXTRACT(EPOCH FROM (n1.last_seen - n2.last_seen))) / 60 AS minutes_diff\nFROM blockchain.nodes n1\nJOIN blockchain.nodes n2\n ON n1.port = n2.port\n AND n1.node_id < n2.node_id\nWHERE ABS(EXTRACT(EPOCH FROM (n1.last_seen - n2.last_seen))) <= 1800;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE blockchain.nodes ( node_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )
[ { "role": "user", "content": "How many unique patient records are there for each gender?" }, { "role": "assistant", "content": "SELECT gender, COUNT(DISTINCT patient_id) AS patient_count FROM healthcare.patients GROUP BY gender;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "List all loans (loan_id, loan_type, principal_amount) that have a current principal balance less than 25% of the original principal amount, along with their account_id and the difference between principal_amount and current_principal_balance." }, { "role": "assistant", "content": "SELECT loan_id, loan_type, principal_amount, account_id, (principal_amount - current_principal_balance) AS amount_paid FROM financial_services.loans WHERE current_principal_balance < (0.25 * principal_amount);" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
[ { "role": "user", "content": "Show the plan name and insurance provider for all insurance plans along with the total number of unique patients enrolled in each plan." }, { "role": "assistant", "content": "SELECT ip.plan_name, ip.insurance_provider, COUNT(DISTINCT pi.patient_id) AS enrolled_patient_count\nFROM healthcare.insurance_plans ip\nJOIN healthcare.patients_insurance pi ON ip.plan_id = pi.plan_id\nGROUP BY ip.plan_name, ip.insurance_provider;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE 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 ) CREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment patient_id character varying(64) NOT NULL, -- FK to patients table doctor_id character varying(64) NOT NULL, -- FK to doctors table appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment duration_minutes integer NOT NULL, -- expected duration in minutes reason text, -- reason for the visit status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show location_id character varying(64), -- FK to a potential locations/clinics table notes text, -- notes related to scheduling created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) ) CREATE 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 ) CREATE 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) ) CREATE TABLE healthcare.medications ( medication_id character varying(64) NOT NULL, -- unique identifier for the medication type medication_name character varying(255) NOT NULL, -- common or brand name generic_name character varying(255), -- generic chemical name manufacturer character varying(100), -- drug manufacturer ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful) description text, -- description of the medication PRIMARY KEY (medication_id) ) CREATE 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 ) CREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )
[ { "role": "user", "content": "What is the total revenue generated by ticket sales at the station with ID 'ST101' for the past month?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide information on the revenue generated by ticket sales as this data is not available in the current database table. The table only contains details about station information such as name, location, and platform count. If you have another question or need assistance with something else related to the station data, I'm happy to help." } ]
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. ##Table Structure CREATE TABLE train_station_management.stations ( station_id.text, station_name.text, city.text, state_province.text, country_code.text, address.text, timezone.text, number_of_platforms.integer, created_at.timestamp, last_updated_at.timestamp )
[ { "role": "user", "content": "What is the ticket price for a journey on train number T4321?" }, { "role": "assistant", "content": "I'm sorry, but I don't have access to information about ticket prices for specific trains. The data I have is limited to train details such as model, manufacturer, capacity, and maintenance schedules. For ticket pricing, please consult the ticketing office or the official website." } ]
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. ##Table Structure CREATE TABLE train_station_management.trains ( train_id text PRIMARY KEY, train_number text UNIQUE, model text, manufacturer text, year_manufactured int, capacity int, status text, last_maintenance_date date, next_maintenance_date date )
[ { "role": "user", "content": "How many reviews does each staff member respond to, along with their full name and the average response time in hours?" }, { "role": "assistant", "content": "SELECT st.staff_id,\n st.first_name || ' ' || st.last_name AS staff_full_name,\n COUNT(*) AS response_count,\n AVG(EXTRACT(EPOCH FROM (r.response_date - r.review_date)) / 3600) AS avg_response_time_hours\nFROM hospitality_technology.reviews r\nJOIN hospitality_technology.staff st\n ON r.response_staff_id = st.staff_id\nWHERE r.response_date IS NOT NULL\nGROUP BY st.staff_id, st.first_name, st.last_name;" }, { "role": "user", "content": "Filter to only include staff who responded to at least 5 reviews." }, { "role": "assistant", "content": "SELECT sub.staff_id,\n sub.staff_full_name,\n sub.response_count,\n sub.avg_response_time_hours\nFROM (\n SELECT st.staff_id,\n st.first_name || ' ' || st.last_name AS staff_full_name,\n COUNT(*) AS response_count,\n AVG(EXTRACT(EPOCH FROM (r.response_date - r.review_date)) / 3600) AS avg_response_time_hours\n FROM hospitality_technology.reviews r\n JOIN hospitality_technology.staff st\n ON r.response_staff_id = st.staff_id\n WHERE r.response_date IS NOT NULL\n GROUP BY st.staff_id, st.first_name, st.last_name\n) sub\nWHERE sub.response_count >= 5;" }, { "role": "user", "content": "Also order the result by average response time ascending." }, { "role": "assistant", "content": "SELECT sub.staff_id,\n sub.staff_full_name,\n sub.response_count,\n sub.avg_response_time_hours\nFROM (\n SELECT st.staff_id,\n st.first_name || ' ' || st.last_name AS staff_full_name,\n COUNT(*) AS response_count,\n AVG(EXTRACT(EPOCH FROM (r.response_date - r.review_date)) / 3600) AS avg_response_time_hours\n FROM hospitality_technology.reviews r\n JOIN hospitality_technology.staff st\n ON r.response_staff_id = st.staff_id\n WHERE r.response_date IS NOT NULL\n GROUP BY st.staff_id, st.first_name, st.last_name\n) sub\nWHERE sub.response_count >= 5\nORDER BY sub.avg_response_time_hours ASC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 ) CREATE TABLE hospitality_technology.rooms ( room_id character varying(64) NOT NULL, -- unique identifier for the room property_id character varying(64) NOT NULL, -- FK to properties table room_number character varying(10) NOT NULL, -- room number identifier (e.g., '101', 'Suite 2B') room_type_id character varying(64) NOT NULL, -- FK to room_types table floor integer, -- floor number the room is on status character varying(50) NOT NULL, -- e.g., Available, Occupied, Cleaning, OutOfOrder, Maintenance is_smoking boolean NOT NULL DEFAULT false, -- smoking allowed flag features text, -- description of features (e.g., Balcony, Sea View, Jacuzzi) current_condition text, -- notes on room condition last_cleaned_at timestamp with time zone, -- timestamp of last cleaning 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) ) CREATE 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 ) CREATE 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 ) CREATE 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 ) CREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service property_id character varying(64) NOT NULL, -- FK to properties table service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt description text, category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities price numeric(10, 2) NOT NULL, -- price per unit/instance unit character varying(30), -- e.g., Per Item, Per Hour, Per Day is_available boolean NOT NULL DEFAULT true, -- is the service currently offered? department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping) PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) ) CREATE 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 ) CREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, -- unique identifier for the payment transaction reservation_id character varying(64), -- FK to reservations (if payment is for a stay) guest_id character varying(64) NOT NULL, -- FK to guests (who paid) bill_id character varying(64), -- FK to bills/invoices this payment applies to amount numeric(12,2) NOT NULL, -- amount of the payment currency_code character varying(3) NOT NULL, -- ISO currency code (e.g., USD, EUR) payment_method character varying(50) NOT NULL, -- e.g., CreditCard, Cash, BankTransfer, Points, Voucher card_type character varying(50), -- e.g., Visa, MasterCard, Amex (if CC) card_last_four character varying(4), -- last 4 digits of CC (if CC) transaction_ref character varying(128), -- reference ID from payment gateway or processor payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the payment occurred status character varying(50) NOT NULL, -- e.g., Pending, Succeeded, Failed, Refunded, Disputed staff_id_processed character varying(64), -- FK to staff (who processed the payment) notes text, -- notes about the payment 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) ) CREATE 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) )
[ { "role": "user", "content": "List all spa services (category = 'Wellness') with their names, prices, and units, ordered by price in descending order." }, { "role": "assistant", "content": "SELECT service_name, price, unit FROM hospitality_technology.services WHERE category = 'Wellness' ORDER BY price DESC;" }, { "role": "user", "content": "Now, include only services with a price above $100 and show the property ID as well." }, { "role": "assistant", "content": "SELECT service_name, price, unit, property_id FROM hospitality_technology.services WHERE category = 'Wellness' AND price > 100 ORDER BY price DESC;" }, { "role": "user", "content": "The query is missing the service description. Can you include that as well?" }, { "role": "assistant", "content": "SELECT service_name, description, price, unit, property_id FROM hospitality_technology.services WHERE category = 'Wellness' AND price > 100 ORDER BY price DESC;" }, { "role": "user", "content": "Actually, I only need services from properties with ID starting with 'PROP1', and order by property_id first, then by price." }, { "role": "assistant", "content": "SELECT service_name, description, price, unit, property_id FROM hospitality_technology.services WHERE category = 'Wellness' AND price > 100 AND property_id LIKE 'PROP1%' ORDER BY property_id, price DESC;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, -- unique identifier for the guest profile first_name character varying(100) NOT NULL, -- guest's first name last_name character varying(100) NOT NULL, -- guest's last name email character varying(255) UNIQUE, -- guest's email address (unique identifier?) phone_number character varying(30), -- guest's phone number date_of_birth date, -- guest's date of birth address_line1 character varying(255), -- guest's home address city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, -- notes on guest preferences (e.g., allergies, room location) loyalty_member_id character varying(64) UNIQUE, -- FK to loyalty_members table communication_consent boolean DEFAULT true, -- consent for marketing communications 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) ) CREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service property_id character varying(64) NOT NULL, -- FK to properties table service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt description text, category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities price numeric(10, 2) NOT NULL, -- price per unit/instance unit character varying(30), -- e.g., Per Item, Per Hour, Per Day is_available boolean NOT NULL DEFAULT true, -- is the service currently offered? department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping) PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )
[ { "role": "user", "content": "Which employees have been assigned to applications for services with a standard fee greater than 200? Show the employee's full name, job title, application ID, and the service name." }, { "role": "assistant", "content": "SELECT e.first_name || ' ' || e.last_name AS employee_full_name, e.job_title, a.application_id, s.service_name\nFROM government_services.applications a\nJOIN government_services.employees e ON a.assigned_employee_id = e.employee_id\nJOIN government_services.services s ON a.service_id = s.service_id\nWHERE s.standard_fee > 200;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number 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, -- full primary residential address contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, -- when the citizen profile was created is_verified boolean DEFAULT false, -- whether identity has been officially verified PRIMARY KEY (citizen_id) ) CREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) ) CREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) ) CREATE 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 ) CREATE 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 ) CREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) ) CREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, -- unique identifier for the physical location agency_id character varying(64) NOT NULL, -- FK to agencies table location_name character varying(200), -- e.g., Downtown DMV Office address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, -- description of opening times contact_phone character varying(32), is_accessible boolean, -- accessibility information (e.g., wheelchair access) PRIMARY KEY (location_id) ) CREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text ) CREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )
[ { "role": "user", "content": "For each category, list all pairs of services where one is active and the other is inactive. Show the category, active service name, and inactive service name." }, { "role": "assistant", "content": "SELECT a.category,\n a.service_name AS active_service,\n i.service_name AS inactive_service\nFROM government_services.services a\nJOIN government_services.services i\n ON a.category = i.category\nWHERE a.is_active = TRUE\n AND i.is_active = FALSE;" } ]
You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question. ##Table Structure CREATE 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 )
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
-