Dataset Viewer
Auto-converted to Parquet Duplicate
system
stringlengths
323
8.11k
conversations
listlengths
2
8
You are an expert in writing database language. You 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 CREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate vin character varying(17) UNIQUE, -- vehicle identification number make character varying(64) NOT NULL, -- manufacturer of the vehicle model character varying(64) NOT NULL, -- model of the vehicle year integer NOT NULL, -- manufacturing year type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van) capacity integer, -- passenger or cargo capacity fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned depot_id character varying(64), -- identifier of the home depot/base acquisition_date date, -- date the vehicle was acquired PRIMARY KEY (vehicle_id) ) CREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips) vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used driver_id character varying(64) NOT NULL, -- identifier of the driver operating scheduled_departure timestamp with time zone NOT NULL, -- planned departure time actual_departure timestamp with time zone, -- actual departure time scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time actual_arrival timestamp with time zone, -- actual arrival time origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin) destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination) status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled passenger_count integer, -- number of passengers (if applicable) cargo_manifest_id character varying(64), -- link to cargo details (if applicable) PRIMARY KEY (trip_id) ) CREATE TABLE transportation.locations ( location_id character varying(64) NOT NULL, -- unique identifier for the location name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7) type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address address_line1 character varying(255), -- street address city character varying(128), -- city name state_province character varying(128), -- state or province postal_code character varying(32), -- postal code country character varying(64) NOT NULL, -- country name latitude numeric(9, 6), -- geographic latitude longitude numeric(9, 6), -- geographic longitude timezone character varying(64), -- IANA timezone name (e.g., America/New_York) PRIMARY KEY (location_id) ) CREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced service_date date NOT NULL, -- date the service was performed odometer_reading integer, -- vehicle mileage at time of service service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair) description text NOT NULL, -- detailed description of work done cost numeric(10, 2), -- cost of the service mechanic_name character varying(128), -- name or ID of the mechanic/shop next_service_due_date date, -- recommended date for next service PRIMARY KEY (log_id) ) CREATE TABLE transportation.fuel_logs ( fuel_log_id character varying(64) NOT NULL, -- unique identifier for the fuel log entry vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle fueled trip_id character varying(64), -- optional: identifier of the trip during which fueling occurred log_timestamp timestamp with time zone NOT NULL, -- time when fueling occurred fuel_type character varying(32) NOT NULL, -- type of fuel added (matches vehicle's fuel type) quantity numeric(10, 3) NOT NULL, -- amount of fuel added (e.g., Liters, Gallons, kWh) unit character varying(16) NOT NULL, -- unit of quantity (e.g., L, gal, kWh) cost_per_unit numeric(8, 4), -- price per unit of fuel total_cost numeric(10, 2) NOT NULL, -- total cost of the fuel purchase odometer_reading integer, -- vehicle mileage at time of fueling location_id character varying(64), -- identifier of the fueling station/location PRIMARY KEY (fuel_log_id) ) 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 character varying(64) NOT NULL, -- unique identifier for the booking passenger_id character varying(64) NOT NULL, -- identifier of the passenger making the booking trip_id character varying(64) NOT NULL, -- identifier of the trip being booked seat_number character varying(16), -- assigned seat number (if applicable) booking_time timestamp with time zone NOT NULL, -- time when the booking was made status character varying(32) NOT NULL, -- e.g., Confirmed, Cancelled, Pending Payment fare numeric(10, 2) NOT NULL, -- price paid for the booking payment_transaction_id character varying(128), -- reference to the payment transaction special_requests text, -- any special requests from the passenger PRIMARY KEY (booking_id) )
[ { "role": "user", "content": "For each depot, show the depot name, city, number of active vehicles, and average capacity." }, { "role": "assistant", "content": "SELECT loc.name AS depot_name, loc.city, COUNT(v.vehicle_id) AS active_vehicle_count, ROUND(AVG(v.capacity),2) AS avg_capacity FROM transportation.vehicles v JOIN transportation.locations loc ON v.depot_id = loc.location_id WHERE v.status = 'Active' GROUP BY loc.name, loc.city;" } ]
You are an expert in writing database language. You 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 CREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz ) CREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) ) CREATE TABLE gaming_technology.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz ) 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": "For each developer, show their name and the total number of achievements in all games they have developed." }, { "role": "assistant", "content": "SELECT d.name AS developer_name, COUNT(a.achievement_id) AS total_achievements\nFROM gaming_technology.developers d\nJOIN gaming_technology.servers s ON d.developer_id = s.game_id -- There is no direct relationship, but assuming developer_id and game_id are connected\nJOIN gaming_technology.achievements a ON s.game_id = a.game_id\nGROUP BY d.developer_id, d.name;" }, { "role": "user", "content": "I think the join between developers and servers is not correct, because developer_id and game_id are different types. Could you try to just show the total number of achievements across all games, and their respective developers, if possible with the current tables?" }, { "role": "assistant", "content": "SELECT '-' AS developer_name, COUNT(a.achievement_id) AS total_achievements\nFROM gaming_technology.achievements a;" }, { "role": "user", "content": "Can you instead list the total number of achievements available for each game_id?" }, { "role": "assistant", "content": "SELECT game_id, COUNT(achievement_id) AS total_achievements\nFROM gaming_technology.achievements\nGROUP BY game_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) ) CREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric ) "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));" "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 character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) ) CREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text ) CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )
[ { "role": "user", "content": "What are the top 5 tokens by 7-day price change percentage? Show token_symbol, token_name, narrative, and chain, ordered by price_change_percentage_7d descending." }, { "role": "assistant", "content": "```sql\nSELECT\n token_symbol,\n token_name,\n narrative,\n chain\nFROM token_basic_info\nORDER BY price_change_percentage_7d DESC\nLIMIT 5;\n```" } ]
You are an expert in writing database language. You 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 CREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )
[ { "role": "user", "content": "List tokens with trend rank 5 or better and a price below $1. Show symbol, price, and trend rank." }, { "role": "assistant", "content": "SELECT token_symbol, price, trend_rank FROM token_dexpool_info WHERE trend_rank IS NOT NULL AND trend_rank <= 5 AND price < 1;" } ]
You are an expert in writing database language. You 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 CREATE TABLE insurance.policies ( policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, product_id character varying(64) NOT NULL, agent_id character varying(64), policy_number character varying(100) NOT NULL UNIQUE, start_date date NOT NULL, end_date date NOT NULL, premium_amount numeric(12, 2) NOT NULL, coverage_limit numeric(15, 2) NOT NULL, deductible numeric(10, 2) NOT NULL, status character varying(30) NOT NULL, issued_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, cancellation_date date, cancellation_reason text, PRIMARY KEY (policy_id) )
[ { "role": "user", "content": "I need to find all pairs of policies for each customer whose coverage periods overlap. Show customer_id, the two policy_ids for each overlapping pair." }, { "role": "assistant", "content": "SELECT p1.customer_id,\n p1.policy_id AS policy1_id,\n p2.policy_id AS policy2_id\nFROM insurance.policies p1\nJOIN insurance.policies p2\n ON p1.customer_id = p2.customer_id\n AND p1.policy_id < p2.policy_id\n AND p1.start_date <= p2.end_date\n AND p2.start_date <= p1.end_date;" }, { "role": "user", "content": "Can you also include the number of days of overlap between the two policies as overlap_days?" }, { "role": "assistant", "content": "SELECT p1.customer_id,\n p1.policy_id AS policy1_id,\n p2.policy_id AS policy2_id,\n (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days\nFROM insurance.policies p1\nJOIN insurance.policies p2\n ON p1.customer_id = p2.customer_id\n AND p1.policy_id < p2.policy_id\n AND p1.start_date <= p2.end_date\n AND p2.start_date <= p1.end_date;" }, { "role": "user", "content": "Actually, restrict the results to only include pairs where both policies are currently active." }, { "role": "assistant", "content": "SELECT p1.customer_id,\n p1.policy_id AS policy1_id,\n p2.policy_id AS policy2_id,\n (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days\nFROM insurance.policies p1\nJOIN insurance.policies p2\n ON p1.customer_id = p2.customer_id\n AND p1.policy_id < p2.policy_id\n AND p1.start_date <= p2.end_date\n AND p2.start_date <= p1.end_date\nWHERE p1.status = 'active'\n AND p2.status = 'active';" } ]
You are an expert in writing database language. You 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 CREATE TABLE train_station_management.train_cars ( car_id character varying(64) NOT NULL, -- Unique identifier for the train car train_id character varying(64) NOT NULL, -- Foreign key referencing trains car_number character varying(10) NOT NULL, -- Identifier of the car within the train set car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars) capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars) features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom') PRIMARY KEY (car_id), FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id) ) CREATE TABLE train_station_management.routes ( route_id character varying(64) NOT NULL, -- Unique identifier for the route route_name character varying(128) NOT NULL, -- Name of the route (e.g., 'Northeast Corridor') description text, -- Description of the route origin_station_id character varying(64) NOT NULL, -- Starting station destination_station_id character varying(64) NOT NULL, -- Final station is_active boolean NOT NULL DEFAULT true, -- Is the route currently operational? PRIMARY KEY (route_id), FOREIGN KEY (origin_station_id) REFERENCES train_station_management.stations(station_id), FOREIGN KEY (destination_station_id) REFERENCES train_station_management.stations(station_id) ) CREATE TABLE train_station_management.route_stations ( route_station_id character varying(64) NOT NULL, -- Unique ID for this route-station link route_id character varying(64) NOT NULL, -- Foreign key referencing routes station_id character varying(64) NOT NULL, -- Foreign key referencing stations sequence_order integer NOT NULL, -- Order of the station in the route (1 for origin, 2, 3...) distance_from_previous_km numeric(10, 2), -- Distance from the previous station in the sequence typical_stop_duration_minutes integer, -- Typical dwell time at this station PRIMARY KEY (route_station_id), UNIQUE (route_id, station_id), UNIQUE (route_id, sequence_order), FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id), FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id) ) CREATE TABLE train_station_management.schedules ( schedule_id character varying(64) NOT NULL, -- Unique identifier for a specific scheduled trip train_id character varying(64) NOT NULL, -- Foreign key referencing the train used route_id character varying(64) NOT NULL, -- Foreign key referencing the route taken departure_datetime timestamp with time zone NOT NULL, -- Scheduled departure time from origin station arrival_datetime timestamp with time zone NOT NULL, -- Scheduled arrival time at destination station status character varying(32) NOT NULL DEFAULT 'Scheduled', -- e.g., Scheduled, On Time, Delayed, Cancelled, Arrived notes text, -- Any notes regarding this specific trip (e.g., reason for delay) PRIMARY KEY (schedule_id), FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id), FOREIGN KEY (route_id) REFERENCES train_station_management.routes(route_id) ) CREATE TABLE train_station_management.passengers ( passenger_id character varying(64) NOT NULL, -- Unique identifier for the passenger first_name character varying(100) NOT NULL, -- Passenger's first name last_name character varying(100) NOT NULL, -- Passenger's last name email character varying(128) UNIQUE, -- Passenger's email address phone_number character varying(32) UNIQUE, -- Passenger's phone number date_of_birth date, -- Passenger's date of birth loyalty_program_id character varying(64), -- ID for loyalty program, if applicable created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the passenger record was created PRIMARY KEY (passenger_id) ) CREATE TABLE train_station_management.bookings ( booking_id character varying(64) NOT NULL, -- Unique identifier for the booking passenger_id character varying(64) NOT NULL, -- Foreign key referencing the passenger schedule_id character varying(64) NOT NULL, -- Foreign key referencing the scheduled trip booking_datetime timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- When the booking was made status character varying(32) NOT NULL DEFAULT 'Confirmed', -- e.g., Confirmed, Cancelled, Pending total_price numeric(12, 2) NOT NULL, -- Total price for all tickets in this booking currency_code character varying(3) NOT NULL DEFAULT 'USD', -- Currency of the price special_requests text, -- Any special requests (e.g., wheelchair assistance) PRIMARY KEY (booking_id), FOREIGN KEY (passenger_id) REFERENCES train_station_management.passengers(passenger_id), FOREIGN KEY (schedule_id) REFERENCES train_station_management.schedules(schedule_id) ) CREATE TABLE train_station_management.staff ( staff_id character varying(64) NOT NULL, -- Unique identifier for the staff member first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, role character varying(64) NOT NULL, -- e.g., Station Master, Ticket Agent, Conductor, Engineer, Maintenance Crew primary_station_id character varying(64), -- Base station for the staff member (nullable for mobile staff) employee_number character varying(32) UNIQUE NOT NULL, -- Unique employee identifier hire_date date NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), is_active boolean NOT NULL DEFAULT true, -- Is the staff member currently employed? PRIMARY KEY (staff_id), FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id) )
[ { "role": "user", "content": "Can you help me get the total number of passenger cars for each train car type in the database?" }, { "role": "assistant", "content": "SELECT car_type, COUNT(*) as total_cars\nFROM train_station_management.train_cars\nWHERE car_type = 'Passenger'\nGROUP BY car_type;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.train_cars ( car_id character varying(64) NOT NULL, -- Unique identifier for the train car train_id character varying(64) NOT NULL, -- Foreign key referencing trains car_number character varying(10) NOT NULL, -- Identifier of the car within the train set car_type character varying(64) NOT NULL, -- e.g., Locomotive, Passenger, Sleeper, Dining, Baggage class character varying(32), -- e.g., First, Business, Economy (null for non-passenger cars) capacity integer, -- Passenger capacity of this specific car (null for non-passenger cars) features text, -- Comma-separated list of features (e.g., 'WiFi', 'Power Outlet', 'Accessible Restroom') PRIMARY KEY (car_id), FOREIGN KEY (train_id) REFERENCES train_station_management.trains(train_id) )
[ { "role": "user", "content": "What is the current location of a specific train car with car_id 'TC123'?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide the current location of a specific train car as this information is not stored in the database table. The table only contains static details about train cars such as car type, capacity, and features. For real-time location data, please refer to the train tracking system or contact the relevant department." } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE manufacturing.employees ( employee_id.text, first_name.text, last_name.text, job_title.text, skill_certifications.text, hire_date.date, assigned_line_id.text, employment_status.text, supervisor_employee_id.text )
[ { "role": "user", "content": "What is the current address of the employee with ID 'EMP234'?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide the current address of an employee as this information is not stored in the database table." } ]
You are an expert in writing database language. You 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 platform details. Key format: platform:<platform_id> // HSET platform:plat_123 platform_id "plat_123" station_id "station_xyz" platform_number "1A" track_number "T1" status "Operational" length_meters 250.50 accessible 1 // To link platforms to stations (optional): // SADD station:station_xyz:platforms platform:plat_123 platform:plat_456 // Use Hashes for train details. Key format: train:<train_id> // HSET train:train_789 train_id "train_789" train_number "Acela 2151" model "Siemens Velaro" ... status "Active" ... // To find train by train_number (optional index): // SET train_number:"Acela 2151" train:train_789 // Use Hashes for car details. Key format: car:<car_id> // HSET car:car_abc car_id "car_abc" train_id "train_789" car_number "C3" car_type "Passenger" class "Business" capacity 60 features "WiFi,Power Outlet" // To link cars to trains (optional): // SADD train:train_789:cars car:car_abc car:car_def // Use Hashes for details. Key format: route_station:<route_station_id> // HSET route_station:rs_ne_1 route_station_id "rs_ne_1" route_id "route_ne_corr" station_id "station_bos" sequence_order 1 ... // To find stops for a route, use a Sorted Set (score by sequence_order): // ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1 // ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2 // Use Hashes for schedule details. Key format: schedule:<schedule_id> // HSET schedule:sched_1122 schedule_id "sched_1122" train_id "train_789" route_id "route_ne_corr" departure_datetime "2024-05-10T08:00:00-04:00" ... status "Scheduled" // Use Hashes for details. Key format: schedule_stop:<stop_id> // HSET schedule_stop:stop_sched1122_1 stop_id "stop_sched1122_1" schedule_id "sched_1122" station_id "station_bos" ... // To find stops for a schedule, use a Sorted Set (score by sequence_order): // ZADD schedule:sched_1122:stops 1 schedule_stop:stop_sched1122_1 // ZADD schedule:sched_1122:stops 2 schedule_stop:stop_sched1122_2 // Use Hashes for passenger details. Key format: passenger:<passenger_id> // HSET passenger:pass_pqr passenger_id "pass_pqr" first_name "Alice" last_name "Smith" email "alice.smith@example.com" ... // To find passenger by email (optional index): // SET passenger_email:"alice.smith@example.com" passenger:pass_pqr // Use Hashes for booking details. Key format: booking:<booking_id> // HSET booking:book_zyx booking_id "book_zyx" passenger_id "pass_pqr" schedule_id "sched_1122" ... status "Confirmed" ... // To link bookings to passengers/schedules (optional): // SADD passenger:pass_pqr:bookings booking:book_zyx // SADD schedule:sched_1122:bookings booking:book_zyx // 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 staff details. Key format: staff:<staff_id> // HSET staff:staff_mno staff_id "staff_mno" first_name "Bob" ... employee_number "E12345" ... is_active 1 // To find staff by employee number (optional index): // SET staff_employee_number:"E12345" staff:staff_mno // 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": "I need to find all bookings for a specific schedule with schedule_id 'sched_1122' and include the passenger and ticket details." }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGETALL ticket:tkt_*" }, { "role": "user", "content": "Can you filter the tickets to show only those that are not checked in?" }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nENDIF" }, { "role": "user", "content": "Can you also include the car details for each ticket?" }, { "role": "assistant", "content": "SMEMBERS schedule:sched_1122:bookings\nHGETALL booking:book_*\nHGETALL passenger:pass_*\nSMEMBERS booking:book_*:tickets\nHGET ticket:tkt_* is_checked_in\nIF is_checked_in == 0 THEN\nHGETALL ticket:tkt_*\nHGET ticket:tkt_* car_id\nHGETALL car:car_*\nENDIF" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##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": "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 expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##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 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 expert in writing database language. You 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 CREATE TABLE insurance.insurance_products ( product_id.text, product_name.text, product_type.text, description.text, base_premium.numeric, coverage_details.text, underwriting_rules.text, is_active.boolean, created_at.timestamp, updated_at.timestamp )
[ { "role": "user", "content": "What are the top 5 product types by average base premium, showing the product_type and average base_premium, ordered by average base_premium descending?" }, { "role": "assistant", "content": "SELECT product_type, AVG(base_premium) AS avg_premium FROM insurance.insurance_products GROUP BY product_type ORDER BY avg_premium DESC LIMIT 5;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE manufacturing.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(128) NOT NULL, skill_certifications text, hire_date date NOT NULL, assigned_line_id character varying(64), employment_status character varying(50) NOT NULL, supervisor_employee_id character varying(64), PRIMARY KEY (employee_id) )
[ { "role": "user", "content": "What is the performance review score for employee with ID 'EMP456' for the last quarter?" }, { "role": "assistant", "content": "I'm sorry, but I can't assist with information about performance review scores as this data is not included in the employees table." } ]
You are an expert in writing database language. You 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 CREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips) vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used driver_id character varying(64) NOT NULL, -- identifier of the driver operating scheduled_departure timestamp with time zone NOT NULL, -- planned departure time actual_departure timestamp with time zone, -- actual departure time scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time actual_arrival timestamp with time zone, -- actual arrival time origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin) destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination) status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled passenger_count integer, -- number of passengers (if applicable) cargo_manifest_id character varying(64), -- link to cargo details (if applicable) PRIMARY KEY (trip_id) )
[ { "role": "user", "content": "List all trips that were completed and experienced a significant delay in actual arrival compared to the scheduled arrival (more than 45 minutes)." }, { "role": "assistant", "content": "SELECT\n trip_id,\n vehicle_id,\n driver_id,\n scheduled_arrival,\n actual_arrival,\n (actual_arrival - scheduled_arrival) AS arrival_delay\nFROM transportation.trips\nWHERE\n status = 'Completed'\n AND actual_arrival IS NOT NULL\n AND actual_arrival > scheduled_arrival + INTERVAL '45 minutes';" }, { "role": "user", "content": "For those completed trips with significant arrival delays, provide a count of how many fall into different delay duration categories: '45-90 mins', '>90 mins'." }, { "role": "assistant", "content": "SELECT\n CASE\n WHEN (actual_arrival - scheduled_arrival) > INTERVAL '45 minutes' AND (actual_arrival - scheduled_arrival) <= INTERVAL '90 minutes' THEN '45-90 mins'\n WHEN (actual_arrival - scheduled_arrival) > INTERVAL '90 minutes' THEN '>90 mins'\n ELSE 'Other Delays' -- Should not be reached based on previous filter, but good practice\n END AS delay_category,\n COUNT(*)\nFROM transportation.trips\nWHERE\n status = 'Completed'\n AND actual_arrival IS NOT NULL\n AND actual_arrival > scheduled_arrival + INTERVAL '45 minutes'\nGROUP BY\n delay_category;" } ]
You are an expert in writing database language. You 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 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": "List all auto loans (loan_id, principal_amount, interest_rate) where the current principal balance is less than 40% of the original principal amount, along with the account_id and the difference between principal_amount and current_principal_balance." }, { "role": "assistant", "content": "SELECT loan_id, principal_amount, interest_rate, account_id, (principal_amount - current_principal_balance) AS amount_paid FROM financial_services.loans WHERE loan_type = 'Auto' AND current_principal_balance < (0.4 * principal_amount);" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE manufacturing.aircraft_models ( model_id text, model_name text, manufacturer text, passenger_capacity integer, max_range_km integer, engine_type text, wingspan_m numeric, status text, first_flight_date date )
[ { "role": "user", "content": "What are the safety ratings or crash statistics for the Boeing 787 Dreamliner?" }, { "role": "assistant", "content": "I'm sorry, but I don't have access to safety ratings or crash statistics for specific aircraft models like the Boeing 787 Dreamliner. My data is limited to the information in the aircraft_models table, which includes details such as model name, manufacturer, passenger capacity, and technical specifications. For safety-related information, I recommend consulting official aviation authorities or safety reports." } ]
You are an expert in writing database language. You 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 CREATE TABLE blockchain.transactions ( transaction_id text, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text ) CREATE TABLE blockchain.smart_contracts ( contract_id text, creator_address text, code text, timestamp timestamp )
[ { "role": "user", "content": "Find all smart contracts deployed in 2022 that have never received any transactions." }, { "role": "assistant", "content": "SELECT sc.contract_id, sc.creator_address, sc.timestamp AS deployment_time\nFROM blockchain.smart_contracts sc\nLEFT JOIN blockchain.transactions t\n ON t.receiver_address = sc.contract_id\nWHERE sc.timestamp >= '2022-01-01' AND sc.timestamp < '2023-01-01'\n AND t.transaction_id IS NULL;" } ]
You are an expert in writing database language. You 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 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": "For each patient, find the date of their most recent medical record and the effective date of their current primary insurance plan. Return patient_id, last_record_date, and effective_date." }, { "role": "assistant", "content": "SELECT m.patient_id,\n m.last_date AS last_record_date,\n pi.effective_date\nFROM (\n SELECT patient_id,\n MAX(record_date) AS last_date\n FROM healthcare.medical_records\n GROUP BY patient_id\n) m\nJOIN healthcare.patient_insurance pi\n ON m.patient_id = pi.patient_id\nWHERE pi.is_primary = TRUE;" } ]
You are an expert in writing database language. You 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 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": "Find all pairs of token transfers where one transfer's sender and recipient are swapped with another transfer's sender and recipient, showing both transfer IDs." }, { "role": "assistant", "content": "SELECT t1.from_address AS sender,\n t1.to_address AS recipient,\n t1.transfer_id AS transfer1_id,\n t2.transfer_id AS transfer2_id\nFROM web3.token_transfers t1\nJOIN web3.token_transfers t2\n ON t1.from_address = t2.to_address\n AND t1.to_address = t2.from_address\n AND t1.transfer_id < t2.transfer_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) ) CREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) ) CREATE TABLE trading_platform.orders ( order_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, wallet_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, order_type character varying(32) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, status character varying(32) NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (order_id) ) CREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, order_id character varying(64) NOT NULL, buyer_id character varying(64) NOT NULL, seller_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, quantity numeric(38,14) NOT NULL, price numeric(38,14) NOT NULL, traded_at timestamp NOT NULL, PRIMARY KEY (trade_id) ) CREATE TABLE trading_platform.utxos ( utxo_id character varying(64) NOT NULL, transaction_id character varying(64) NOT NULL, output_index integer NOT NULL, address character varying(128) NOT NULL, amount numeric(38,14) NOT NULL, spent boolean NOT NULL, PRIMARY KEY (utxo_id) ) CREATE TABLE trading_platform.dapps ( dapp_id character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) ) CREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) ) CREATE TABLE trading_platform.logs ( log_id character varying(64) NOT NULL, user_id character varying(64), action character varying(128) NOT NULL, details text NOT NULL, logged_at timestamp NOT NULL, PRIMARY KEY (log_id) ) CREATE TABLE trading_platform.notifications ( notification_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, message text NOT NULL, sent_at timestamp NOT NULL, read_at timestamp, PRIMARY KEY (notification_id) )
[ { "role": "user", "content": "How many DApps have names that start with the letter 'A'?" }, { "role": "assistant", "content": "SELECT COUNT(*) AS dapp_count\nFROM trading_platform.dapps\nWHERE name LIKE 'A%';" } ]
You are an expert in writing database language. You 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 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) )
[ { "role": "user", "content": "Report the number of employees for each department, broken down by their employment status." }, { "role": "assistant", "content": "SELECT department, status, COUNT(*) AS employee_count FROM financial_services.employees GROUP BY department, status" }, { "role": "user", "content": "Only show results for departments that have at least 10 employees in total (across all statuses)." } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.platforms ( platform_id text, station_id text, platform_number text, track_number text, status text, length_meters numeric, accessible boolean )
[ { "role": "user", "content": "What is the maintenance schedule for platform 3 at station DEF for the next month?" }, { "role": "assistant", "content": "I'm sorry, but I don't have access to the maintenance schedule for platforms. The data I have only includes static information about platform details such as ID, station, number, track, status, length, and accessibility. For maintenance schedules, you may need to consult the station management or relevant department." } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )
[ { "role": "user", "content": "Find pairs of users who registered on the same weekday but in different years. List the user ID and registration date for both users, and the weekday name." }, { "role": "assistant", "content": "SELECT u1.user_id, u1.created_at AS user1_created_at, u2.user_id, u2.created_at AS user2_created_at, TO_CHAR(u1.created_at, 'Day') AS registration_weekday FROM web3.users u1 JOIN web3.users u2 ON TO_CHAR(u1.created_at, 'Day') = TO_CHAR(u2.created_at, 'Day') AND EXTRACT(YEAR FROM u1.created_at) <> EXTRACT(YEAR FROM u2.created_at) AND u1.user_id < u2.user_id ORDER BY TO_CHAR(u1.created_at, 'D'), u1.created_at;" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )
[ { "role": "user", "content": "Show the usernames and registration dates for all users whose email ends with '@gmail.com'." }, { "role": "assistant", "content": "SELECT username, created_at FROM web3.users WHERE email LIKE '%@gmail.com';" }, { "role": "user", "content": "Actually, can you also include how many such users there are in total in the result?" }, { "role": "assistant", "content": "SELECT username, created_at, COUNT(*) OVER() AS total_gmail_users FROM web3.users WHERE email LIKE '%@gmail.com';" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.token_transfers ( transfer_id text, token_id text, from_address text, to_address text, value numeric, transaction_id text, log_index integer )
[ { "role": "user", "content": "For each transaction, list the total value transferred and the number of different addresses involved (either as sender or receiver)." }, { "role": "assistant", "content": "SELECT transaction_id, SUM(value) AS total_value_transferred, COUNT(DISTINCT addr) AS num_addresses_involved\nFROM (\n SELECT transaction_id, from_address AS addr, value FROM web3.token_transfers\n UNION ALL\n SELECT transaction_id, to_address AS addr, 0 as value FROM web3.token_transfers\n) t\nGROUP BY transaction_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE government_services.services ( service_id text PRIMARY KEY, agency_id text, service_name text, description text, category text, eligibility_criteria text, standard_fee numeric, average_processing_time_days int, is_active boolean, online_application_url text ) CREATE TABLE government_services.documents ( document_id character varying(64) NOT NULL, -- unique identifier for the document instance application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly) citizen_id character varying(64) NOT NULL, -- FK to citizens table document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path) upload_timestamp timestamp NOT NULL, expiry_date date, verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected verified_by_employee_id character varying(64), -- FK to employees table verification_timestamp timestamp, PRIMARY KEY (document_id) ) CREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text ) CREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, -- unique identifier for the government employee agency_id character varying(64) NOT NULL, -- FK to agencies table 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, -- null if currently employed access_level character varying(50), -- Role or permission level manager_employee_id character varying(64), -- FK to self for reporting structure PRIMARY KEY (employee_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": "What is the average number of appointments assigned per employee for each job title?" }, { "role": "assistant", "content": "SELECT e.job_title, CAST(COUNT(a.appointment_id) AS REAL) / COUNT(DISTINCT e.employee_id) AS average_appointments_per_employee FROM government_services.employees e LEFT JOIN government_services.appointments a ON e.employee_id = a.employee_id GROUP BY e.job_title;" } ]
You are an expert in writing database language. You 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 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.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": "For each trip, can you show the trip_id, number of passengers, and the make and model of the assigned vehicle?" }, { "role": "assistant", "content": "SELECT b.trip_id, COUNT(b.passenger_id) AS passenger_count, v.make, v.model\nFROM transportation.bookings b\nJOIN transportation.vehicles v ON b.trip_id IN (\n SELECT DISTINCT trip_id FROM transportation.fuel_logs WHERE vehicle_id = v.vehicle_id\n)\nGROUP BY b.trip_id, v.make, v.model;" } ]
You are an expert in writing database language. You 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 CREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )
[ { "role": "user", "content": "How many beneficiaries were added on each unique date?" }, { "role": "assistant", "content": "SELECT DATE(added_at), COUNT(*) FROM insurance.policy_beneficiaries GROUP BY DATE(added_at);" } ]
You are an expert in writing database language. You 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 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 number of guests registered in each city. Order the results by city name." }, { "role": "assistant", "content": "SELECT city, COUNT(guest_id) AS guest_count FROM guests GROUP BY city ORDER BY city;" } ]
You are an expert in writing database language. You 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 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 )
[ { "role": "user", "content": "Which routes have their origin and destination in the same city? Show the route number, description, and the origin and destination location IDs." }, { "role": "assistant", "content": "SELECT r.route_number, r.description, r.origin_location_id, r.destination_location_id\nFROM transportation.routes r\nJOIN transportation.routes r2 ON r.origin_location_id = r2.destination_location_id AND r.route_id = r2.route_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) 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 character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )
[ { "role": "user", "content": "What is the total and average amount of unspent UTXOs per address?" }, { "role": "assistant", "content": "SELECT\n address,\n COUNT(*) AS utxo_count,\n SUM(amount) AS total_unspent_amount,\n AVG(amount) AS average_unspent_amount\nFROM trading_platform.utxos\nWHERE spent = FALSE\nGROUP BY address;" } ]
You are an expert in writing database language. You 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 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.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
[ { "role": "user", "content": "I want to list all insurance plans along with the number of medical records that have a record_date in 2024. Display plan_id, plan_name, and the total medical records." }, { "role": "assistant", "content": "SELECT ip.plan_id, ip.plan_name, COUNT(mr.record_id) AS total_medical_records\nFROM healthcare.insurance_plans ip\nLEFT JOIN healthcare.medical_records mr ON 1=0 -- there is no direct relationship in schema, so no records will be counted\nWHERE mr.record_date >= '2024-01-01' AND mr.record_date < '2025-01-01'\nGROUP BY ip.plan_id, ip.plan_name;" }, { "role": "user", "content": "Since there's no direct relationship, can you adjust it to just show all insurance plans of type 'EPO' with their plan_id and plan_name?" }, { "role": "assistant", "content": "SELECT plan_id, plan_name\nFROM healthcare.insurance_plans\nWHERE plan_type = 'EPO';" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
[ { "role": "user", "content": "List each user along with the wallet_id of their first created wallet." }, { "role": "assistant", "content": "SELECT\n m.user_id,\n w.wallet_id AS first_wallet_id\nFROM (\n SELECT user_id, MIN(created_at) AS first_created_at\n FROM web3.wallets\n GROUP BY user_id\n) AS m\nJOIN web3.wallets AS w\n ON w.user_id = m.user_id\n AND w.created_at = m.first_created_at;" } ]
You are an expert in writing database language. You 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 CREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )
[ { "role": "user", "content": "What is the average USD value per address for each narrative across all chains?" }, { "role": "assistant", "content": "SELECT\n narrative,\n AVG(usd_value / NULLIF(address_amount, 0)) AS avg_usd_per_address\nFROM smart_money_token_inflow\nGROUP BY narrative;" } ]
You are an expert in writing database language. You 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 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.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.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.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id) hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id) PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post ) 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) )
[ { "role": "user", "content": "List all users who have a non-empty bio and a profile picture URL." }, { "role": "assistant", "content": "SELECT\n user_id,\n username,\n full_name,\n bio,\n profile_picture_url\nFROM social_media.users\nWHERE\n bio IS NOT NULL AND profile_picture_url IS NOT NULL;" } ]
You are an expert in writing database language. You 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 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": "How many notifications are there for each status?" }, { "role": "assistant", "content": "SELECT\n status,\n COUNT(*) AS notification_count\nFROM government_services.notifications\nGROUP BY status;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.platforms ( platform_id.text, station_id.text, platform_number.text, track_number.text, status.text, length_meters.numeric, accessible.boolean )
[ { "role": "user", "content": "What is the history of incidents or accidents that occurred on platform 5 at station GHI?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide information about the history of incidents or accidents on platform 5 at station GHI. My data is limited to the structural and operational details of the platforms, such as platform ID, station ID, and status. For incident history, you may need to consult a different database or contact the relevant authorities." } ]
You are an expert in writing database language. You 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 CREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text ) 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.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, 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, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb ) 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 games that have servers deployed in more than one geographical region. Show the game title and the count of regions." }, { "role": "assistant", "content": "SELECT g.title, count(DISTINCT s.region) AS region_count FROM games AS g JOIN servers AS s ON g.game_id = s.game_id GROUP BY g.game_id, g.title HAVING count(DISTINCT s.region) > 1;" } ]
You are an expert in writing database language. You 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 CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text ) CREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp ) CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) CREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )
[ { "role": "user", "content": "How many unread notifications does each user have?" }, { "role": "assistant", "content": "SELECT user_id,\n COUNT(*) AS unread_notifications\nFROM trading_platform.notifications\nWHERE read_at IS NULL\nGROUP BY user_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric ) 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 text, chain text, address text, exchange text, token_address text, token_symbol text, balance numeric, usd_value numeric, price numeric ) 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 ) CREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )
[ { "role": "user", "content": "For the 'DeFi' narrative, what is the average ROI and the total net inflow (usd_value where type=1) from smart money token inflow?" }, { "role": "assistant", "content": "SELECT AVG(sm.roi) AS avg_roi, SUM(smt.usd_value) AS total_net_inflow\nFROM smart_money_token_inflow smt\nJOIN smart_money_profit sm ON smt.chain = sm.chain\nWHERE smt.narrative = 'DeFi' AND smt.type = 1;" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.token_transfers ( transfer_id character varying(64) NOT NULL, -- unique identifier for the transfer token_id character varying(64) NOT NULL, -- identifier of the token being transferred from_address character varying(128) NOT NULL, -- address of the sender to_address character varying(128) NOT NULL, -- address of the receiver value numeric(38,14) NOT NULL, -- amount of tokens transferred transaction_id character varying(64) NOT NULL, -- identifier of the transaction containing the transfer log_index integer NOT NULL, -- index of the transfer log in the transaction PRIMARY KEY (transfer_id) )
[ { "role": "user", "content": "Find cases where an address received tokens in one transfer and then sent tokens in another. List the receive transfer_id, the send transfer_id, the address, and both transfer values." }, { "role": "assistant", "content": "SELECT recv.transfer_id AS receive_transfer_id,\n send.transfer_id AS send_transfer_id,\n recv.to_address AS address,\n recv.value AS received_value,\n send.value AS sent_value\nFROM web3.token_transfers recv\nJOIN web3.token_transfers send\n ON recv.to_address = send.from_address;" } ]
You are an expert in writing database language. You 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 CREATE TABLE trading_platform.users ( user_id text PRIMARY KEY, username text, email text, password_hash text, created_at timestamp ) CREATE TABLE trading_platform.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp ) CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp ) CREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean ) CREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text ) CREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp ) CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) CREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )
[ { "role": "user", "content": "List each wallet with its wallet_id, user_id, and the total amount of unspent UTXOs associated with that wallet." }, { "role": "assistant", "content": "SELECT\n w.wallet_id,\n w.user_id,\n COALESCE(SUM(u.amount), 0) AS unspent_total\nFROM trading_platform.wallets w\nLEFT JOIN trading_platform.utxos u\n ON w.address = u.address\n AND u.spent = false\nGROUP BY w.wallet_id, w.user_id;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##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": "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 expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.staff ( staff_id character varying(64) NOT NULL, -- Unique identifier for the staff member first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, role character varying(64) NOT NULL, -- e.g., Station Master, Ticket Agent, Conductor, Engineer, Maintenance Crew primary_station_id character varying(64), -- Base station for the staff member (nullable for mobile staff) employee_number character varying(32) UNIQUE NOT NULL, -- Unique employee identifier hire_date date NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), is_active boolean NOT NULL DEFAULT true, -- Is the staff member currently employed? PRIMARY KEY (staff_id), FOREIGN KEY (primary_station_id) REFERENCES train_station_management.stations(station_id) )
[ { "role": "user", "content": "What are the specific job responsibilities and daily tasks for a staff member with the role of Station Master?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide information about the specific job responsibilities or daily tasks for a Station Master. The data in the staff table only includes basic identification and contact details, role titles, and employment status, without details on job descriptions or duties." } ]
You are an expert in writing database language. You 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 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": "Show the full names and contact emails of all citizens who have applied for services with a standard fee greater than 100." }, { "role": "assistant", "content": "SELECT c.first_name || ' ' || c.last_name AS full_name, c.contact_email\nFROM government_services.citizens c\nJOIN government_services.services s ON c.citizen_id IS NOT NULL -- Replace with actual application linking table if exists\nWHERE s.standard_fee > 100;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##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": "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 expert in writing database language. You 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 CREATE TABLE government_services.agencies ( agency_id.text, agency_name.text, jurisdiction_level.text, primary_contact_email.text, main_phone_number.text, website_url.text, established_date.date, parent_agency_id.text ) 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 ) 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.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.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 ) 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": "Find the names and addresses of service locations where no appointments have been scheduled." }, { "role": "assistant", "content": "SELECT sl.location_name, sl.address FROM government_services.service_locations sl LEFT JOIN government_services.appointments a ON sl.location_id = a.location_id WHERE a.appointment_id IS NULL;" } ]
You are an expert in writing database language. You 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 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.trips ( trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips) vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used driver_id character varying(64) NOT NULL, -- identifier of the driver operating scheduled_departure timestamp with time zone NOT NULL, -- planned departure time actual_departure timestamp with time zone, -- actual departure time scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time actual_arrival timestamp with time zone, -- actual arrival time origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin) destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination) status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled passenger_count integer, -- number of passengers (if applicable) cargo_manifest_id character varying(64), -- link to cargo details (if applicable) PRIMARY KEY (trip_id) ) CREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text ) CREATE TABLE transportation.maintenance_logs ( log_id text PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )
[ { "role": "user", "content": "List all maintenance logs for vehicles that had 'Oil Change' service in the last 3 months, showing vehicle ID, service date, and cost." }, { "role": "assistant", "content": "SELECT vehicle_id, service_date, cost FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months';" }, { "role": "user", "content": "Can you include the mechanic name and show only services that cost more than $100?" }, { "role": "assistant", "content": "SELECT vehicle_id, service_date, cost, mechanic_name FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100;" }, { "role": "user", "content": "Actually, I need to see the vehicle make and model as well. Can you include that information?" }, { "role": "assistant", "content": "Sorry, I can't include vehicle make and model as those fields aren't present in the provided table schemas. The maintenance_logs table only contains vehicle_id but not make/model information." }, { "role": "user", "content": "Then just add the odometer reading to the previous query and order by the most recent services first." }, { "role": "assistant", "content": "SELECT vehicle_id, service_date, cost, mechanic_name, odometer_reading FROM transportation.maintenance_logs WHERE service_type = 'Oil Change' AND service_date >= CURRENT_DATE - INTERVAL '3 months' AND cost > 100 ORDER BY service_date DESC;" } ]
You are an expert in writing database language. You 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 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 )
[ { "role": "user", "content": "Provide every combination of medication name and insurance plan name." }, { "role": "assistant", "content": "SELECT m.medication_name, p.plan_name\nFROM healthcare.medications AS m\nCROSS JOIN healthcare.insurance_plans AS p;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE manufacturing.employees ( employee_id text, first_name text, last_name text, job_title text, skill_certifications text, hire_date date, assigned_line_id text, employment_status text, supervisor_employee_id text )
[ { "role": "user", "content": "What is the reason for the termination of employee with ID 'EMP789'?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide information on the reason for an employee's termination as it is not stored in the current database table." } ]
You are an expert in writing database language. You 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 CREATE TABLE legal_services.lawyers ( lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer first_name character varying(100) NOT NULL, -- lawyer's first name last_name character varying(100) NOT NULL, -- lawyer's last name bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number firm_id character varying(64), -- FK to law_firms table email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email phone character varying(32), -- lawyer's contact phone number specialization text, -- areas of legal expertise hire_date timestamp NOT NULL, -- date the lawyer was hired or joined is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner PRIMARY KEY (lawyer_id) )
[ { "role": "user", "content": "How many lawyers who are partners were hired in each year? Show the hire year and the count." }, { "role": "assistant", "content": "SELECT strftime('%Y', hire_date) AS hire_year , count(lawyer_id) FROM legal_services.lawyers WHERE is_partner = true GROUP BY hire_year" } ]
You are an expert in writing database language. You 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 CREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )
[ { "role": "user", "content": "List all tokens with a price below $1 and a 24-hour trading volume over $5 million." }, { "role": "assistant", "content": "SELECT token_name, token_symbol, price, total_volume FROM token_basic_info WHERE price < 1 AND total_volume::numeric > 5000000;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.trains ( train_id character varying(64) NOT NULL, -- Unique identifier for the train set train_number character varying(32) NOT NULL, -- Operational number of the train (e.g., 'Acela 2151') model character varying(128), -- Model of the train (e.g., 'Siemens Velaro') manufacturer character varying(128), -- Manufacturer of the train year_manufactured integer, -- Year the train was built capacity integer NOT NULL, -- Total passenger capacity status character varying(32) NOT NULL DEFAULT 'Active', -- e.g., Active, Maintenance, Retired last_maintenance_date date, -- Date of last scheduled maintenance next_maintenance_date date, -- Date of next scheduled maintenance PRIMARY KEY (train_id), UNIQUE (train_number) )
[ { "role": "user", "content": "What is the current location of train number Acela 2151?" }, { "role": "assistant", "content": "I'm sorry, but I don't have access to real-time location data for trains. The database only contains static information such as train ID, model, capacity, and maintenance schedules. For current location updates, please check with the train operator or a tracking service." } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, -- unique identifier for the token contract_address character varying(128) NOT NULL, -- address of the token contract token_name character varying(128) NOT NULL, -- name of the token token_symbol character varying(32) NOT NULL, -- symbol of the token decimals integer NOT NULL, -- number of decimals for the token total_supply numeric(38,14) NOT NULL, -- total supply of the token PRIMARY KEY (token_id) )
[ { "role": "user", "content": "List the token symbol and name for all tokens whose associated contract address has emitted at least one event. Also include the contract address." }, { "role": "assistant", "content": "SELECT T.token_symbol, T.token_name, T.contract_address FROM web3.tokens AS T JOIN contracts AS C ON T.contract_address = C.address JOIN events AS E ON C.contract_id = E.contract_id GROUP BY T.token_symbol, T.token_name, T.contract_address;" } ]
You are an expert in writing database language. You 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 to store station details. Key format: station:<station_id> // Example: // HSET station:station_xyz station_id "station_xyz" station_name "Grand Central Terminal" city "New York" state_province "NY" country_code "USA" address "89 E 42nd St..." timezone "America/New_York" number_of_platforms 44 created_at "2023-01-15T10:00:00Z" last_updated_at "2023-10-28T15:30:00Z" // To quickly find stations by city (optional index): // SADD stations:city:NewYork station:station_xyz // Use Hashes for platform details. Key format: platform:<platform_id> // HSET platform:plat_123 platform_id "plat_123" station_id "station_xyz" platform_number "1A" track_number "T1" status "Operational" length_meters 250.50 accessible 1 // To link platforms to stations (optional): // SADD station:station_xyz:platforms platform:plat_123 platform:plat_456 // Use Hashes for train details. Key format: train:<train_id> // HSET train:train_789 train_id "train_789" train_number "Acela 2151" model "Siemens Velaro" ... status "Active" ... // To find train by train_number (optional index): // SET train_number:"Acela 2151" train:train_789 // Use Hashes for car details. Key format: car:<car_id> // HSET car:car_abc car_id "car_abc" train_id "train_789" car_number "C3" car_type "Passenger" class "Business" capacity 60 features "WiFi,Power Outlet" // To link cars to trains (optional): // SADD train:train_789:cars car:car_abc car:car_def // Use Hashes for route details. Key format: route:<route_id> // HSET route:route_ne_corr route_id "route_ne_corr" route_name "Northeast Corridor" ... origin_station_id "station_bos" ... is_active 1 // Use Hashes for details. Key format: route_station:<route_station_id> // HSET route_station:rs_ne_1 route_station_id "rs_ne_1" route_id "route_ne_corr" station_id "station_bos" sequence_order 1 ... // To find stops for a route, use a Sorted Set (score by sequence_order): // ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1 // ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2 // Use Hashes for passenger details. Key format: passenger:<passenger_id> // HSET passenger:pass_pqr passenger_id "pass_pqr" first_name "Alice" last_name "Smith" email "alice.smith@example.com" ... // To find passenger by email (optional index): // SET passenger_email:"alice.smith@example.com" passenger:pass_pqr // Use Hashes for booking details. Key format: booking:<booking_id> // HSET booking:book_zyx booking_id "book_zyx" passenger_id "pass_pqr" schedule_id "sched_1122" ... status "Confirmed" ... // To link bookings to passengers/schedules (optional): // SADD passenger:pass_pqr:bookings booking:book_zyx // SADD schedule:sched_1122:bookings booking:book_zyx // 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
[ { "role": "user", "content": "能否帮我统计特定车站(station_id 为 'station_xyz')的所有平台数量?" }, { "role": "assistant", "content": "SCARD station:station_xyz:platforms" } ]
You are an expert in writing database language. You 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 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.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": "Count the number of registered citizens by gender." }, { "role": "assistant", "content": "SELECT\n gender,\n COUNT(*) AS citizen_count\nFROM government_services.citizens\nGROUP BY gender;" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.train_cars ( car_id text PRIMARY KEY, train_id text, car_number text, car_type text, class text, capacity int, features text )
[ { "role": "user", "content": "What is the current operational status of the train car with car_id 'CAR123'?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide information on the current operational status of the train car with car_id 'CAR123'. The data in the train_cars table does not include real-time status updates or operational conditions." } ]
You are an expert in writing database language. You 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 CREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )
[ { "role": "user", "content": "How many messages include a media attachment?" }, { "role": "assistant", "content": "SELECT COUNT(*) FROM social_media.messages WHERE media_url IS NOT NULL AND TRIM(media_url) <> '';" } ]
You are an expert in writing database language. You 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": "特定の予約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 CREATE TABLE financial_services.customers ( customer_id.text, first_name.text, last_name.text, date_of_birth.date, ssn_hash.text, address.text, city.text, state.text, zip_code.text, country.text, email.text, phone_number.text, created_at.timestamp, status.text, risk_profile.text ) CREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, -- unique identifier for the account customer_id character varying(64) NOT NULL, -- foreign key linking to the customer account_number character varying(128) NOT NULL UNIQUE, -- unique account number visible to customer account_type character varying(50) NOT NULL, -- e.g., Checking, Savings, Investment, Loan, Credit Card balance numeric(19, 4) NOT NULL DEFAULT 0.00, -- current account balance currency character varying(3) NOT NULL, -- currency code (e.g., USD, EUR) opened_date date NOT NULL, -- date the account was opened status character varying(32) NOT NULL, -- e.g., Open, Closed, Frozen interest_rate numeric(5, 4), -- annual interest rate, if applicable last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last account update PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) ) 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": "Which customers have accounts in more than one state? Please show their customer_id, full name, and the list of states where they hold accounts." }, { "role": "assistant", "content": "SELECT c.customer_id, c.first_name || ' ' || c.last_name AS full_name, STRING_AGG(DISTINCT c.state, ', ') AS states\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nGROUP BY c.customer_id, c.first_name, c.last_name\nHAVING COUNT(DISTINCT c.state) > 1;" }, { "role": "user", "content": "Can you also include the total number of accounts each customer has?" }, { "role": "assistant", "content": "SELECT c.customer_id, c.first_name || ' ' || c.last_name AS full_name, STRING_AGG(DISTINCT c.state, ', ') AS states, COUNT(a.account_id) AS total_accounts\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nGROUP BY c.customer_id, c.first_name, c.last_name\nHAVING COUNT(DISTINCT c.state) > 1;" }, { "role": "user", "content": "It seems like it's listing the customer state info rather than the account's. Can you instead show which states are associated with their accounts' addresses?" }, { "role": "assistant", "content": "SELECT c.customer_id, c.first_name || ' ' || c.last_name AS full_name, STRING_AGG(DISTINCT ca.state, ', ') AS account_states, COUNT(a.account_id) AS total_accounts\nFROM financial_services.customers c\nJOIN financial_services.accounts a ON c.customer_id = a.customer_id\nJOIN financial_services.customers ca ON ca.customer_id = a.customer_id\nGROUP BY c.customer_id, c.first_name, c.last_name\nHAVING COUNT(DISTINCT ca.state) > 1;" }, { "role": "user", "content": "Actually, can you pull the state value from the accounts table instead if possible?" }, { "role": "assistant", "content": "-- Assuming accounts table has a 'state' field, otherwise this cannot be done directly as accounts does not have state info per schema.\n-- If not, we must take it from customers as previously, since only customers has 'state'." } ]
You are an expert in writing database language. You 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 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) )
[ { "role": "user", "content": "Which rooms on the 4th floor are non-smoking, along with their property IDs and type IDs?" }, { "role": "assistant", "content": "SELECT room_id, property_id, room_number, room_type_id FROM hospitality_technology.rooms WHERE floor = 4 AND is_smoking = FALSE;" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )
[ { "role": "user", "content": "For each block that contains more than 5 transactions, list the block number, the total sum of values transferred within that block, and the average gas used per transaction in that block." }, { "role": "assistant", "content": "SELECT block_number, SUM(value) AS total_value_in_block, AVG(gas_used) AS average_gas_used FROM web3.transactions GROUP BY block_number HAVING COUNT(*) > 5 ORDER BY block_number;" } ]
You are an expert in writing database language. You 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 CREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text ) CREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text ) CREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text ) 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 ) CREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )
[ { "role": "user", "content": "How many documents of each type exist in the system? Show the document type and the count." }, { "role": "assistant", "content": "SELECT document_type, COUNT(*) AS document_count\nFROM legal_services.documents\ngroup BY document_type;" } ]
You are an expert in writing database language. You 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 CREATE TABLE project_fundraising_record ( id text, project_id text, project_name text, rounds_name text, investment_value numeric, investment_date text, introduction text, valuation numeric )
[ { "role": "user", "content": "How many fundraising rounds did each project complete?" }, { "role": "assistant", "content": "SELECT project_name, COUNT(*) AS round_count FROM project_fundraising_record GROUP BY project_name;" } ]
You are an expert in writing database language. You 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 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.locations ( location_id.text, name.text, type.text, address_line1.text, city.text, state_province.text, postal_code.text, country.text, latitude.numeric, longitude.numeric, timezone.text ) 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": "What was the total quantity and total cost of 'Gasoline' fuel logged in the year 2023?" }, { "role": "assistant", "content": "SELECT SUM(quantity) , SUM(total_cost) FROM transportation.fuel_logs WHERE fuel_type = 'Gasoline' AND EXTRACT(YEAR FROM log_timestamp) = 2023" } ]
You are an expert in writing database language. You 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 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 ) CREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )
[ { "role": "user", "content": "List all invoices that were paid within 7 days of their issue date. Show invoice number, issue date, payment date, and total amount." }, { "role": "assistant", "content": "SELECT invoice_number, issue_date, payment_date, total_amount FROM legal_services.invoices WHERE status = 'Paid' AND payment_date IS NOT NULL AND (payment_date::DATE - issue_date) <= 7;" } ]
You are an expert in writing database language. You 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 CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) ) CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) ) CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) ) CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) ) CREATE TABLE social_media.notifications ( notification_id character varying(64) NOT NULL, recipient_user_id character varying(64) NOT NULL, sender_user_id character varying(64), notification_type character varying(30) NOT NULL, target_entity_id character varying(64), target_entity_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (notification_id) ) CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )
[ { "role": "user", "content": "How many likes were given to comments in June 2024?" }, { "role": "assistant", "content": "SELECT COUNT(*) AS comment_likes_count\nFROM social_media.likes\nWHERE comment_id IS NOT NULL \n AND DATE_TRUNC('month', created_at) = '2024-06-01';" } ]
You are an expert in writing database language. You 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 CREATE TABLE social_media.posts ( post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, visibility character varying(20) NOT NULL DEFAULT 'public', location_lat numeric(9,6), location_lon numeric(9,6), PRIMARY KEY (post_id) ) 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.likes ( like_id text PRIMARY KEY, user_id text, post_id text, comment_id text, created_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 )
[ { "role": "user", "content": "How many likes have been received by public posts, grouped by media_type? Please show media_type and the count of likes for each." }, { "role": "assistant", "content": "SELECT p.media_type,\n COUNT(l.like_id) AS like_count\nFROM social_media.posts p\nJOIN social_media.likes l\n ON p.post_id = l.post_id\nWHERE p.visibility = 'public'\nGROUP BY p.media_type\nORDER BY like_count DESC;" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )
[ { "role": "user", "content": "List all wallets that were created during the hour of the day which saw the highest number of wallet creations. Show the wallet ID, user ID, address, and creation timestamp." }, { "role": "assistant", "content": "WITH HourlyCounts AS (\n SELECT EXTRACT(HOUR FROM created_at) AS hour, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY 1\n),\nMaxHour AS (\n SELECT hour\n FROM HourlyCounts\n ORDER BY wallet_count DESC\n LIMIT 1\n)\nSELECT wallet_id, user_id, address, created_at\nFROM web3.wallets\nWHERE EXTRACT(HOUR FROM created_at) = (SELECT hour FROM MaxHour);" } ]
You are an expert in writing database language. You 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 CREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) ) CREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.trades ( trade_id character varying(64) NOT NULL, -- unique identifier for the trade order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade buyer_id character varying(64) NOT NULL, -- identifier of the buyer seller_id character varying(64) NOT NULL, -- identifier of the seller asset_id character varying(64) NOT NULL, -- identifier of the asset being traded quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade price numeric(38,14) NOT NULL, -- price per unit of the asset traded_at timestamp NOT NULL, -- time when the trade was executed PRIMARY KEY (trade_id) ) CREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) ) 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 character varying(64) NOT NULL, name character varying(128) NOT NULL, description text NOT NULL, url character varying(256) NOT NULL, PRIMARY KEY (dapp_id) ) CREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp ) CREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text ) CREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit user_id character varying(64) NOT NULL, -- identifier of the user being audited status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected) reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed PRIMARY KEY (kyc_audit_id) ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) CREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )
[ { "role": "user", "content": "Which DApps have the word 'exchange' in their description?" }, { "role": "assistant", "content": "SELECT name, description\nFROM trading_platform.dapps\nWHERE description ILIKE '%exchange%';" } ]
You are an expert in writing database language. You 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 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": "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 expert in writing database language. You 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 CREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, -- unique identifier for the token contract_address character varying(128) NOT NULL, -- address of the token contract token_name character varying(128) NOT NULL, -- name of the token token_symbol character varying(32) NOT NULL, -- symbol of the token decimals integer NOT NULL, -- number of decimals for the token total_supply numeric(38,14) NOT NULL, -- total supply of the token PRIMARY KEY (token_id) )
[ { "role": "user", "content": "Show all token symbols along with the names of any other tokens on the same contract address." }, { "role": "assistant", "content": "SELECT t1.token_symbol, t2.token_name AS other_token_name, t1.contract_address\nFROM web3.tokens t1\nJOIN web3.tokens t2\n ON t1.contract_address = t2.contract_address\n AND t1.token_id <> t2.token_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )
[ { "role": "user", "content": "List the usernames of players who own at least one item from the game with title 'Game Title X'." }, { "role": "assistant", "content": "SELECT DISTINCT T1.username FROM players AS T1 INNER JOIN player_inventory AS T2 ON T1.player_id = T2.player_id INNER JOIN items AS T3 ON T2.item_id = T3.item_id INNER JOIN games AS T4 ON T3.game_id = T4.game_id WHERE T4.title = 'Game Title X';" } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE manufacturing.aircraft_models ( model_id character varying(64) NOT NULL, -- unique identifier for the aircraft model model_name character varying(128) NOT NULL, -- commercial name of the model (e.g., 737 MAX, A320neo) manufacturer character varying(128) NOT NULL, -- manufacturer name (e.g., Boeing, Airbus) passenger_capacity integer, -- typical passenger capacity max_range_km integer, -- maximum flight range in kilometers engine_type character varying(100), -- type of engines used wingspan_m numeric(6,2), -- wingspan in meters status character varying(50) NOT NULL, -- e.g., 'In Production', 'Development', 'Discontinued' first_flight_date date, -- date of the model's first flight PRIMARY KEY (model_id) )
[ { "role": "user", "content": "What is the current market price of a Boeing 737 MAX aircraft?" }, { "role": "assistant", "content": "I'm sorry, but I don't have access to the current market price of aircraft models. The data I have is limited to technical specifications and general information about aircraft models such as passenger capacity, range, and status. For pricing information, you may need to consult with manufacturers or industry reports." } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.trains ( train_id character varying(64) NOT NULL, train_number character varying(32) NOT NULL, model character varying(128), manufacturer character varying(128), year_manufactured integer, capacity integer NOT NULL, status character varying(32) NOT NULL DEFAULT 'Active', last_maintenance_date date, next_maintenance_date date, PRIMARY KEY (train_id), UNIQUE (train_number) )
[ { "role": "user", "content": "What is the fuel consumption rate of train number T1234?" }, { "role": "assistant", "content": "I'm sorry, but I don't have information on the fuel consumption rate of train number T1234. The data available in the system only includes details such as train ID, model, manufacturer, year manufactured, capacity, status, and maintenance dates." } ]
You are an expert in writing database language and you can refuse the user's question if the question is not related to the table structure. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. ##Table Structure CREATE TABLE train_station_management.maintenance_records ( record_id text, asset_id text, asset_type text, maintenance_type text, staff_id text, start_datetime timestamp, end_datetime timestamp, description text, cost numeric, status text )
[ { "role": "user", "content": "What are the personal contact details of the staff member associated with staff_id 'STAFF789' who worked on a specific maintenance record?" }, { "role": "assistant", "content": "I'm sorry, but I can't provide personal contact details of staff members as this information is not stored in the maintenance_records table and is outside the scope of the available data." } ]
You are an expert in writing database language. You 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 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": "List the names of agencies and their established dates, but only for agencies that offer at least one service." }, { "role": "assistant", "content": "SELECT DISTINCT T1.agency_name , T1.established_date FROM government_services.agencies AS T1 JOIN government_services.services AS T2 ON T1.agency_id = T2.agency_id" } ]
You are an expert in writing database language. You 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 CREATE TABLE trading_platform.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp ) CREATE TABLE trading_platform.orders ( order_id text, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp ) CREATE TABLE trading_platform.assets ( asset_id text, name text, symbol text, type text ) 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.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) ) CREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp ) CREATE TABLE trading_platform.notifications ( notification_id text, user_id text, message text, sent_at timestamp, read_at timestamp )
[ { "role": "user", "content": "List all DApps along with the number of metadata entries linked to each, even if the DApp has no linked metadata." }, { "role": "assistant", "content": "SELECT d.name, d.url, COUNT(m.metadata_id) AS metadata_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON d.dapp_id = m.asset_id\nGROUP BY d.dapp_id, d.name, d.url;" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.events ( event_id character varying(64) NOT NULL, -- unique identifier for the event contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event event_name character varying(128) NOT NULL, -- name of the event data text NOT NULL, -- data payload of the event emitted_at timestamp NOT NULL, -- time when the event was emitted transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event log_index integer NOT NULL, -- index of the event log in the transaction PRIMARY KEY (event_id) ) CREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) ) CREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric ) CREATE TABLE web3.wallets ( wallet_id text, user_id text, address text, private_key text, created_at timestamp ) CREATE TABLE web3.users ( user_id text, username text, email text, password_hash text, created_at timestamp )
[ { "role": "user", "content": "For each event recorded, list its ID, name, and the status and value of the transaction in which it occurred." }, { "role": "assistant", "content": "SELECT E.event_id, E.event_name, E.transaction_id, T.status, T.value FROM web3.events AS E JOIN web3.transactions AS T ON E.transaction_id = T.transaction_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )
[ { "role": "user", "content": "Provide a breakdown of the total number of conversations, showing how many are group chats and how many are not. Also, show the count of conversations that have a recorded last message time." }, { "role": "assistant", "content": "SELECT COUNT(*) AS total_conversations, COUNT(CASE WHEN is_group_chat = true THEN 1 END) AS group_chat_count, COUNT(CASE WHEN is_group_chat = false THEN 1 END) AS private_chat_count, COUNT(last_message_at) AS conversations_with_messages_count FROM social_media.conversations;" } ]
You are an expert in writing database language. You 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 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.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp ) CREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text ) 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": "How many users have their profile pictures set and also have written a bio?" }, { "role": "assistant", "content": "SELECT COUNT(*) AS user_count\nFROM social_media.users\nWHERE profile_picture_url IS NOT NULL AND profile_picture_url <> ''\n AND bio IS NOT NULL AND bio <> '';" } ]
You are an expert in writing database language. You 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 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 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.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )
[ { "role": "user", "content": "List the full names of patients who have had at least one appointment scheduled with a doctor, along with the medication names they have been prescribed. Please include only patients who have both an appointment and at least one corresponding medication." }, { "role": "assistant", "content": "SELECT DISTINCT p.first_name, p.last_name, m.medication_name\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nJOIN healthcare.medications m ON m.medication_id IN (\n SELECT medication_id FROM healthcare.medications\n) -- Placeholder, since no direct prescription table or mapping is given\nWHERE a.status = 'scheduled';" }, { "role": "user", "content": "Actually, could you also include the appointment time in the results?" }, { "role": "assistant", "content": "SELECT DISTINCT p.first_name, p.last_name, a.appointment_time, m.medication_name\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nJOIN healthcare.medications m ON m.medication_id IN (\n SELECT medication_id FROM healthcare.medications\n)\nWHERE a.status = 'scheduled';" }, { "role": "user", "content": "The medication names are not matching with the appointments, I think there is no direct link. Can you just give me, for each patient who has at least one scheduled appointment, all their appointment times and their last names, without including medication info?" }, { "role": "assistant", "content": "SELECT DISTINCT p.first_name, p.last_name, a.appointment_time\nFROM healthcare.patients p\nJOIN healthcare.appointments a ON p.patient_id = a.patient_id\nWHERE a.status = 'scheduled';" } ]
You are an expert in writing database language. You 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 CREATE TABLE legal_services.clients ( client_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, company_name character varying(200), email character varying(128) UNIQUE NOT NULL, phone character varying(32), address text, date_registered timestamp NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (client_id) ) CREATE TABLE legal_services.lawyers ( lawyer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, bar_number character varying(64) UNIQUE NOT NULL, firm_id character varying(64), email character varying(128) UNIQUE NOT NULL, phone character varying(32), specialization text, hire_date timestamp NOT NULL, is_partner boolean DEFAULT false, PRIMARY KEY (lawyer_id) ) CREATE TABLE legal_services.law_firms ( firm_id character varying(64) NOT NULL, firm_name character varying(200) NOT NULL, address text NOT NULL, phone character varying(32), website character varying(255), founded_date date, managing_partner_id character varying(64), PRIMARY KEY (firm_id) ) CREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) ) CREATE TABLE legal_services.documents ( document_id character varying(64) NOT NULL, case_id character varying(64) NOT NULL, document_name character varying(255) NOT NULL, document_type character varying(100), storage_path text NOT NULL, uploaded_by_lawyer_id character varying(64), upload_timestamp timestamp NOT NULL, version integer DEFAULT 1, description text, PRIMARY KEY (document_id) ) CREATE TABLE legal_services.time_entries ( entry_id character varying(64) NOT NULL, case_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, date_worked date NOT NULL, hours_spent numeric(5, 2) NOT NULL CHECK (hours_spent > 0), billing_rate numeric(10, 2) NOT NULL, description text NOT NULL, is_billable boolean DEFAULT true, is_billed boolean DEFAULT false, invoice_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (entry_id) ) CREATE TABLE legal_services.appointments ( appointment_id character varying(64) NOT NULL, client_id character varying(64) NOT NULL, lawyer_id character varying(64) NOT NULL, case_id character varying(64), start_time timestamp NOT NULL, end_time timestamp NOT NULL, location text, subject character varying(255), notes text, status character varying(50) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (appointment_id) )
[ { "role": "user", "content": "List all clients along with their case_number and case_type for cases that are currently 'Open'." }, { "role": "assistant", "content": "SELECT c.first_name, c.last_name, c.email, cs.case_number, cs.case_type\nFROM legal_services.clients AS c\nJOIN legal_services.cases AS cs\n ON c.client_id = cs.client_id\nWHERE cs.status = 'Open';" } ]
You are an expert in writing database language. You 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 CREATE TABLE financial_services.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address text NOT NULL, city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, status character varying(32) NOT NULL, risk_profile character varying(50), PRIMARY KEY (customer_id) ) CREATE TABLE financial_services.accounts ( account_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, account_number character varying(128) NOT NULL UNIQUE, account_type character varying(50) NOT NULL, balance numeric(19, 4) NOT NULL DEFAULT 0.00, currency character varying(3) NOT NULL, opened_date date NOT NULL, status character varying(32) NOT NULL, interest_rate numeric(5, 4), last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (account_id), FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id) ) CREATE TABLE financial_services.securities ( security_id character varying(64) NOT NULL, ticker_symbol character varying(20) NOT NULL UNIQUE, isin_code character varying(12) UNIQUE, cusip_code character varying(9) UNIQUE, security_name text NOT NULL, security_type character varying(50) NOT NULL, exchange character varying(50), currency character varying(3) NOT NULL, issuer_name character varying(255), sector character varying(100), last_updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (security_id) ) CREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) ) CREATE TABLE financial_services.market_data ( data_point_id bigserial NOT NULL, security_id character varying(64) NOT NULL, data_timestamp timestamp NOT NULL, open_price numeric(19, 8), high_price numeric(19, 8), low_price numeric(19, 8), close_price numeric(19, 8) NOT NULL, adjusted_close_price numeric(19, 8), volume bigint, source character varying(50), PRIMARY KEY (data_point_id), UNIQUE (security_id, data_timestamp), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) ) CREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) ) 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": "For each security, show the average daily volume from market data and the total quantity traded across all trades." }, { "role": "assistant", "content": "WITH MarketDataAgg AS ( SELECT security_id, AVG(volume) AS avg_daily_volume FROM financial_services.market_data GROUP BY security_id ), TradesAgg AS ( SELECT security_id, SUM(quantity) AS total_quantity_traded FROM financial_services.trades GROUP BY security_id ) SELECT T1.ticker_symbol, T1.security_name, T2.avg_daily_volume, T3.total_quantity_traded FROM financial_services.securities AS T1 LEFT JOIN MarketDataAgg AS T2 ON T1.security_id = T2.security_id LEFT JOIN TradesAgg AS T3 ON T1.security_id = T3.security_id WHERE T2.avg_daily_volume IS NOT NULL OR T3.total_quantity_traded IS NOT NULL;" }, { "role": "user", "content": "Only include securities where the average daily volume is above 500000 and the total quantity traded is above 10000." } ]
You are an expert in writing database language. You 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 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.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.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 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": "Show me all insurance plans where the website includes 'secure'." }, { "role": "assistant", "content": "SELECT * FROM healthcare.insurance_plans WHERE website ILIKE '%secure%';" } ]
You are an expert in writing database language. You 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 CREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) )
[ { "role": "user", "content": "What is the average number of days by which paid invoices were paid late? Calculate the average of (payment_date - due_date) for invoices with status 'Paid'." }, { "role": "assistant", "content": "SELECT AVG((payment_date::date - due_date)) AS average_late_days\nFROM legal_services.invoices\nWHERE status = 'Paid';" } ]
You are an expert in writing database language. You 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 CREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )
[ { "role": "user", "content": "Calculate the average total amount for invoices issued in each calendar year." }, { "role": "assistant", "content": "SELECT EXTRACT(YEAR FROM issue_date) AS issue_year, AVG(total_amount) AS average_total_amount FROM legal_services.invoices GROUP BY EXTRACT(YEAR FROM issue_date) ORDER BY issue_year" } ]
You are an expert in writing database language. You 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 CREATE TABLE legal_services.law_firms ( firm_id.text, firm_name.text, address.text, phone.text, website.text, founded_date.date, managing_partner_id.text )
[ { "role": "user", "content": "Show me the names and phone numbers of all law firms founded in the same city." }, { "role": "assistant", "content": "SELECT lf1.firm_name AS firm1_name, lf1.phone AS firm1_phone, lf2.firm_name AS firm2_name, lf2.phone AS firm2_phone, lf1.address \nFROM legal_services.law_firms lf1\nJOIN legal_services.law_firms lf2 ON lf1.address = lf2.address AND lf1.firm_id < lf2.firm_id;" } ]
You are an expert in writing database language. You 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 CREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) ) CREATE TABLE gaming_technology.games ( game_id uuid NOT NULL DEFAULT gen_random_uuid(), title character varying(200) NOT NULL, developer_id uuid NOT NULL, publisher_id uuid, genre character varying(100), release_date date, description text, platform character varying(50) NOT NULL, engine character varying(100), website character varying(255), PRIMARY KEY (game_id) ) CREATE TABLE gaming_technology.servers ( server_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, server_name character varying(150), region character varying(50) NOT NULL, ip_address character varying(45), port integer, current_players integer NOT NULL DEFAULT 0, max_players integer NOT NULL, status character varying(30) NOT NULL DEFAULT 'offline', last_heartbeat timestamp with time zone, PRIMARY KEY (server_id) ) CREATE TABLE gaming_technology.in_game_items ( item_id uuid NOT NULL DEFAULT gen_random_uuid(), game_id uuid NOT NULL, item_name character varying(150) NOT NULL, item_type character varying(50) NOT NULL, description text, rarity character varying(30), cost_currency character varying(10), cost_amount numeric(12, 2), attributes jsonb, PRIMARY KEY (item_id) ) CREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )
[ { "role": "user", "content": "For each player, show the player_id and the count of inventory items they acquired with a quantity greater than 1." }, { "role": "assistant", "content": "SELECT player_id, COUNT(inventory_id) AS items_qty_gt_1_count FROM gaming_technology.player_inventory WHERE quantity > 1 GROUP BY player_id;" } ]
You are an expert in writing database language. You 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 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.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 )
[ { "role": "user", "content": "Count the number of trips for each route type." }, { "role": "assistant", "content": "SELECT R.type, COUNT(T.trip_id) FROM transportation.trips AS T JOIN transportation.routes AS R ON T.route_id = R.route_id GROUP BY R.type;" } ]
You are an expert in writing database language. You 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 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": "How many documents were uploaded in the year 2023?" }, { "role": "assistant", "content": "SELECT count(*) FROM government_services.documents WHERE date_part('year', upload_timestamp) = 2023;" } ]
You are an expert in writing database language. You 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 CREATE TABLE healthcare.insurance_plans ( plan_id text PRIMARY KEY, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )
[ { "role": "user", "content": "Find all insurance providers that offer both HMO and PPO plans and list the provider name along with the corresponding HMO and PPO plan IDs." }, { "role": "assistant", "content": "SELECT h.insurance_provider,\n h.plan_id AS hmo_plan_id,\n p.plan_id AS ppo_plan_id\nFROM healthcare.insurance_plans h\nJOIN healthcare.insurance_plans p\n ON h.insurance_provider = p.insurance_provider\nWHERE h.plan_type = 'HMO'\n AND p.plan_type = 'PPO';" } ]
You are an expert in writing database language. You 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 CREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )
[ { "role": "user", "content": "Show the customer_id and pairs of payment_ids for any customers who have overlapping payment periods." }, { "role": "assistant", "content": "SELECT p1.customer_id,\n p1.payment_id AS payment1_id,\n p2.payment_id AS payment2_id\nFROM insurance.premium_payments p1\nJOIN insurance.premium_payments p2\n ON p1.customer_id = p2.customer_id\n AND p1.payment_id < p2.payment_id\n AND p1.payment_period_start <= p2.payment_period_end\n AND p1.payment_period_end >= p2.payment_period_start;" } ]
You are an expert in writing database language. You 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 CREATE TABLE web3.transactions ( transaction_id text, from_address text, to_address text, value numeric, gas_used integer, gas_price numeric, block_number integer, timestamp timestamp, input_data text, status text, nonce integer )
[ { "role": "user", "content": "For each transaction, find the next transaction initiated by the same sender. List the original transaction_id, the next transaction_id, the sender address, and the time difference in hours between them." }, { "role": "assistant", "content": "SELECT t1.transaction_id AS original_tx,\n t2.transaction_id AS next_tx,\n t1.from_address,\n EXTRACT(EPOCH FROM (t2.timestamp - t1.timestamp)) / 3600 AS hours_diff\nFROM transactions t1\nJOIN transactions t2\n ON t1.from_address = t2.from_address\n AND t2.timestamp = (\n SELECT MIN(timestamp)\n FROM transactions t3\n WHERE t3.from_address = t1.from_address\n AND t3.timestamp > t1.timestamp\n );" } ]
You are an expert in writing database language. You 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 CREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )
[ { "role": "user", "content": "For each vehicle, list the vehicle_id and the total number of trips it has performed." }, { "role": "assistant", "content": "SELECT vehicle_id, COUNT(*) AS trip_count FROM transportation.trips GROUP BY vehicle_id;" }, { "role": "user", "content": "Can you limit this to only vehicles that have more than 10 trips?" }, { "role": "assistant", "content": "SELECT vehicle_id, COUNT(*) AS trip_count FROM transportation.trips GROUP BY vehicle_id HAVING COUNT(*) > 10;" }, { "role": "user", "content": "In addition, for these vehicles, can you show the driver_id who has driven the highest number of trips for each vehicle?" }, { "role": "assistant", "content": "SELECT vehicle_id, driver_id, trip_driver_count FROM (SELECT vehicle_id, driver_id, COUNT(*) AS trip_driver_count, ROW_NUMBER() OVER (PARTITION BY vehicle_id ORDER BY COUNT(*) DESC) as rn FROM transportation.trips GROUP BY vehicle_id, driver_id) t WHERE rn = 1 AND vehicle_id IN (SELECT vehicle_id FROM transportation.trips GROUP BY vehicle_id HAVING COUNT(*) > 10);" } ]
You are an expert in writing database language. You 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 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 )
[ { "role": "user", "content": "List all users who signed up in 2024 and have not set a bio. Show their usernames, emails, and account creation dates." }, { "role": "assistant", "content": "SELECT username, email, created_at FROM social_media.users WHERE bio IS NULL AND EXTRACT(YEAR FROM created_at) = 2024;" } ]
You are an expert in writing database language. You 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 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) )
[ { "role": "user", "content": "Provide a count of citizens registered per calendar year." }, { "role": "assistant", "content": "SELECT CAST(EXTRACT(YEAR FROM registration_date) AS INTEGER) AS registration_year, COUNT(*) AS citizen_count FROM government_services.citizens GROUP BY 1 ORDER BY 1;" } ]
You are an expert in writing database language. You 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 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": "For each location, count the total number of appointments scheduled. Show the location name and the count." }, { "role": "assistant", "content": "SELECT T2.location_name, COUNT(T1.appointment_id) FROM government_services.appointments AS T1 JOIN locations AS T2 ON T1.location_id = T2.location_id GROUP BY T2.location_name;" } ]
You are an expert in writing database language. You 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 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.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.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": "Show the earliest and latest creation timestamps recorded in the posts table." }, { "role": "assistant", "content": "SELECT MIN(created_at), MAX(created_at) FROM social_media.posts" } ]
You are an expert in writing database language. You 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 CREATE TABLE social_media.users ( user_id character varying(64) NOT NULL, username character varying(50) NOT NULL UNIQUE, email character varying(128) NOT NULL UNIQUE, password_hash text NOT NULL, full_name character varying(100), profile_picture_url text, bio text, location character varying(100), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, is_verified boolean NOT NULL DEFAULT false, PRIMARY KEY (user_id) ) CREATE TABLE social_media.comments ( comment_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, parent_comment_id character varying(64), content text NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (comment_id) ) CREATE TABLE social_media.likes ( like_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, post_id character varying(64), comment_id character varying(64), created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (like_id), CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) ) CREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) ) CREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) ) CREATE TABLE social_media.user_settings ( setting_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL UNIQUE, theme character varying(20) DEFAULT 'light', email_notifications_enabled boolean DEFAULT true, push_notifications_enabled boolean DEFAULT true, private_profile boolean DEFAULT false, updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (setting_id) )
[ { "role": "user", "content": "Find all users who have set their bio to a non-empty value, showing their username and email." }, { "role": "assistant", "content": "SELECT username, email\nFROM social_media.users\nWHERE bio IS NOT NULL AND TRIM(bio) != '';" } ]
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
3