diff --git "a/data.jsonl" "b/data.jsonl" new file mode 100644--- /dev/null +++ "b/data.jsonl" @@ -0,0 +1,250 @@ +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nIndex 'suppliers'. Mapping: { properties: { supplier_id: { type: 'keyword' }, supplier_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, address: { type: 'text' }, country: { type: 'keyword' }, contact_person: { type: 'text', index: false }, contact_email: { type: 'keyword' }, quality_rating: { type: 'float' }, certified_date: { type: 'date' } } }. Document _id can be supplier_id.\n","conversations":[{"role":"user","content":"\ud2b9\uc815 \uacf5\uae09\uc5c5\uccb4 ID\ub85c \uacf5\uae09\uc5c5\uccb4\uc758 \uc138\ubd80 \uc815\ubcf4\ub97c \uc870\ud68c\ud558\uace0 \uc2f6\uc2b5\ub2c8\ub2e4. \ubaa8\ub4e0 \ud544\ub4dc\ub97c \ud3ec\ud568\ud574 \uc8fc\uc138\uc694."},{"role":"assistant","content":"GET suppliers\/_doc\/{supplier_id}"},{"role":"user","content":"\ub9cc\uc57d \uc5ec\ub7ec \uacf5\uae09\uc5c5\uccb4 ID\ub97c \ud55c \ubc88\uc5d0 \uc870\ud68c\ud558\uace0 \uc2f6\ub2e4\uba74 \uc5b4\ub5bb\uac8c \ud574\uc57c \ud558\ub098\uc694?"},{"role":"assistant","content":"GET suppliers\/_search\n{\n \"query\": {\n \"terms\": {\n \"supplier_id\": [\"id1\", \"id2\", \"id3\"]\n }\n }\n}"},{"role":"user","content":"\uc870\ud68c \uacb0\uacfc\uc5d0\uc11c \uacf5\uae09\uc5c5\uccb4 \uc774\ub984\uacfc \uc5f0\ub77d\ucc98 \uc774\uba54\uc77c\ub9cc \ubcf4\uace0 \uc2f6\uc2b5\ub2c8\ub2e4."},{"role":"assistant","content":"GET suppliers\/_search\n{\n \"query\": {\n \"terms\": {\n \"supplier_id\": [\"id1\", \"id2\", \"id3\"]\n }\n },\n \"_source\": [\"supplier_name\", \"contact_email\"]\n}"},{"role":"user","content":"\uacb0\uacfc\ub97c \uacf5\uae09\uc5c5\uccb4 \uc774\ub984 \uae30\uc900\uc73c\ub85c \uc624\ub984\ucc28\uc21c \uc815\ub82c\ud574 \uc8fc\uc138\uc694."},{"role":"assistant","content":"GET suppliers\/_search\n{\n \"query\": {\n \"terms\": {\n \"supplier_id\": [\"id1\", \"id2\", \"id3\"]\n }\n },\n \"_source\": [\"supplier_name\", \"contact_email\"],\n \"sort\": [\n {\n \"supplier_name.keyword\": {\n \"order\": \"asc\"\n }\n }\n ]\n}"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n\/\/ db.createCollection('passengers')\n\/\/ Optional: db.passengers.createIndex({ passenger_id: 1 }, { unique: true })\n\/\/ Optional: db.passengers.createIndex({ email: 1 }, { unique: true, sparse: true })\n\/\/ Optional: db.passengers.createIndex({ phone_number: 1 }, { unique: true, sparse: true })\n{\n _id: ObjectId(),\n passenger_id: \"pass_pqr\", \/\/ String (unique)\n first_name: \"Alice\", \/\/ String\n last_name: \"Smith\", \/\/ String\n email: \"alice.smith@example.com\", \/\/ String (unique, sparse)\n phone_number: \"+15551234567\", \/\/ String (unique, sparse)\n date_of_birth: ISODate(\"1990-03-20\"), \/\/ Date\n loyalty_program_id: \"LOYALTY123\", \/\/ String\n created_at: ISODate(\"2023-02-01T11:00:00Z\") \/\/ Date\n}\n","conversations":[{"role":"user","content":"Can you show me the total number of passengers registered in the database?"},{"role":"assistant","content":"db.passengers.countDocuments({})"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nUse Hashes. Key pattern: 'inv:'. Example: HSET inv:INVREC500 component_id \"component:WINGBOLT\" quantity 5000 location_warehouse \"WH3\" batch_number \"BCH778899\" ... Consider Sorted Set by expiry date: ZADD component_expiry: .\n","conversations":[{"role":"user","content":"I need to get the inventory quantity and location for a specific batch number. Can you help with that?"},{"role":"assistant","content":"HGETALL inv:"},{"role":"user","content":"Can you also show me the component ID associated with this batch?"},{"role":"assistant","content":"HGETALL inv:"},{"role":"user","content":"If I want to retrieve multiple inventory records for the same component ID, how can I do that?"},{"role":"assistant","content":"ZRANGE component_expiry: 0 -1"},{"role":"user","content":"Can you sort those records by expiry date in ascending order?"},{"role":"assistant","content":"ZRANGE component_expiry: 0 -1 WITHSCORES"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nUse Hashes. Key pattern: 'inv:'. Example: HSET inv:INVREC500 component_id \"component:WINGBOLT\" quantity 5000 location_warehouse \"WH3\" batch_number \"BCH778899\" ... Consider Sorted Set by expiry date: ZADD component_expiry: .\n","conversations":[{"role":"user","content":"Can you help me retrieve the inventory details for a specific component ID, including the quantity and warehouse location?"},{"role":"assistant","content":"HGETALL inv:"},{"role":"user","content":"Can you also include the batch number for that inventory record?"},{"role":"assistant","content":"HGETALL inv:"},{"role":"user","content":"If I want to check the expiry date for this component, how can I retrieve that information?"},{"role":"assistant","content":"ZRANGE component_expiry: 0 -1 WITHSCORES"},{"role":"user","content":"Can you filter the results to show only inventory records with an expiry date after a specific timestamp?"},{"role":"assistant","content":"ZRANGEBYSCORE component_expiry: +inf WITHSCORES"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nUse Hashes. Key pattern: 'component:'. Example: HSET component:LGSTRUT01 part_number \"PN-5521-A\" component_name \"Landing Gear Strut\" material_id \"mat:TI64\" supplier_id \"sup:ACME_AERO\" ... Consider Sets for reverse lookups (e.g., 'material_components:' -> Set).\n","conversations":[{"role":"user","content":"I need to find all components associated with a specific supplier. Can you help with that?"},{"role":"assistant","content":"HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE"},{"role":"user","content":"Can you also show me the material ID for each of these components?"},{"role":"assistant","content":"HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id"},{"role":"user","content":"What if I want to exclude components with a specific material ID?"},{"role":"assistant","content":"HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id\nIF HGET component: material_id != 'mat:TI64' THEN INCLUDE"},{"role":"user","content":"Can you add the component name to the result as well?"},{"role":"assistant","content":"HGETALL component:\nIF HGET component: supplier_id = 'sup:ACME_AERO' THEN INCLUDE\nHGET component: material_id\nIF HGET component: material_id != 'mat:TI64' THEN INCLUDE\nHGET component: component_name"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n\/\/ db.createCollection('stations')\n\/\/ Optional: Add unique index: db.stations.createIndex({ station_id: 1 }, { unique: true })\n{\n _id: ObjectId(), \/\/ Auto-generated MongoDB ID\n station_id: \"station_xyz\", \/\/ String (unique identifier, corresponds to SQL PK)\n station_name: \"Grand Central Terminal\", \/\/ String\n city: \"New York\", \/\/ String\n state_province: \"NY\", \/\/ String\n country_code: \"USA\", \/\/ String\n address: \"89 E 42nd St, New York, NY 10017\", \/\/ String\n timezone: \"America\/New_York\", \/\/ String\n number_of_platforms: 44, \/\/ Int32\n created_at: ISODate(\"2023-01-15T10:00:00Z\"), \/\/ Date\n last_updated_at: ISODate(\"2023-10-28T15:30:00Z\") \/\/ Date\n}\n\/\/ db.createCollection('trains')\n\/\/ Optional: db.trains.createIndex({ train_id: 1 }, { unique: true })\n\/\/ Optional: db.trains.createIndex({ train_number: 1 }, { unique: true })\n{\n _id: ObjectId(),\n train_id: \"train_789\", \/\/ String (unique)\n train_number: \"Acela 2151\", \/\/ String (unique)\n model: \"Siemens Velaro\", \/\/ String\n manufacturer: \"Siemens\", \/\/ String\n year_manufactured: 2010, \/\/ Int32\n capacity: 304, \/\/ Int32\n status: \"Active\", \/\/ String ('Active', 'Maintenance', 'Retired')\n last_maintenance_date: ISODate(\"2023-09-15\"), \/\/ Date (Date part only relevant)\n next_maintenance_date: ISODate(\"2024-03-15\") \/\/ Date (Date part only relevant)\n}\n\/\/ db.createCollection('bookings')\n\/\/ Optional: db.bookings.createIndex({ booking_id: 1 }, { unique: true })\n\/\/ Optional: db.bookings.createIndex({ passenger_id: 1 })\n\/\/ Optional: db.bookings.createIndex({ schedule_id: 1 })\n{\n _id: ObjectId(),\n booking_id: \"book_zyx\", \/\/ String (unique)\n passenger_id: \"pass_pqr\", \/\/ String (references passengers.passenger_id)\n schedule_id: \"sched_1122\", \/\/ String (references schedules.schedule_id)\n booking_datetime: ISODate(\"2024-04-15T14:30:00Z\"), \/\/ Date\n status: \"Confirmed\", \/\/ String ('Confirmed', 'Cancelled', 'Pending')\n total_price: 150.75, \/\/ Decimal128 or Double\n currency_code: \"USD\", \/\/ String\n special_requests: \"Wheelchair assistance required at origin\" \/\/ String\n}\n\/\/ db.createCollection('staff')\n\/\/ Optional: db.staff.createIndex({ staff_id: 1 }, { unique: true })\n\/\/ Optional: db.staff.createIndex({ employee_number: 1 }, { unique: true })\n\/\/ Optional: db.staff.createIndex({ contact_email: 1 }, { unique: true, sparse: true })\n{\n _id: ObjectId(),\n staff_id: \"staff_mno\", \/\/ String (unique)\n first_name: \"Bob\", \/\/ String\n last_name: \"Jones\", \/\/ String\n role: \"Conductor\", \/\/ String\n primary_station_id: null, \/\/ String (references stations.station_id, nullable)\n employee_number: \"E12345\", \/\/ String (unique)\n hire_date: ISODate(\"2018-06-01\"), \/\/ Date\n contact_email: \"bob.jones@example-rail.com\", \/\/ String (unique, sparse)\n contact_phone: \"+15559876543\", \/\/ String\n is_active: true \/\/ Boolean\n}\n","conversations":[{"role":"user","content":"Can you help me count the total number of active staff members in the database?"},{"role":"assistant","content":"db.staff.countDocuments({ is_active: true });"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.maintenance_records ( record_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, asset_type character varying(32) NOT NULL, maintenance_type character varying(128) NOT NULL, staff_id character varying(64), start_datetime timestamp NOT NULL, end_datetime timestamp, description text NOT NULL, cost numeric(12, 2), status character varying(32) NOT NULL DEFAULT 'Completed', PRIMARY KEY (record_id), FOREIGN KEY (staff_id) REFERENCES train_station_management.staff(staff_id) )\n","conversations":[{"role":"user","content":"What is the reason behind the cost variation for maintenance of asset_id 'ASSET456' over the past year?"},{"role":"assistant","content":"I'm sorry, but I can't provide information on the reasons behind cost variations for maintenance. The data in the maintenance_records table includes only the cost amount and other basic details of each maintenance record, but it does not contain explanations or factors influencing cost changes."}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nUse Hashes. Key pattern: 'component:'. Example: HSET component:LGSTRUT01 part_number \"PN-5521-A\" component_name \"Landing Gear Strut\" material_id \"mat:TI64\" supplier_id \"sup:ACME_AERO\" ... Consider Sets for reverse lookups (e.g., 'material_components:' -> Set).\n","conversations":[{"role":"user","content":"Can you help me retrieve the list of components made of a specific material along with their supplier details?"},{"role":"assistant","content":"SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id"},{"role":"user","content":"Can you also include the part number for each component in the result?"},{"role":"assistant","content":"SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id\nHGET component: part_number"},{"role":"user","content":"If I want to filter out components from a specific supplier, how can I modify the query?"},{"role":"assistant","content":"SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id\nHGET component: part_number\nIF HGET component: supplier_id != 'sup:ACME_AERO' THEN INCLUDE"},{"role":"user","content":"Can you also sort the results based on the part number?"},{"role":"assistant","content":"SMEMBERS material_components:mat:TI64\nHGETALL component:\nHGET component: supplier_id\nHGET component: part_number\nIF HGET component: supplier_id != 'sup:ACME_AERO' THEN INCLUDE\nSORT BY part_number ASC"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.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) )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record\/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions\/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment\/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\n","conversations":[{"role":"user","content":"Can you provide a list of all medical records created by doctors for patients who are associated with 'PPO' type insurance plans? I need the record ID, patient ID, doctor ID, record date, and insurance plan name."},{"role":"assistant","content":"SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.patient_id IS NOT NULL -- placeholder JOIN, fix below if you have a patient-insurance mapping table\nWHERE ip.plan_type = 'PPO';"},{"role":"user","content":"The SQL seems off because there's no direct mapping between patients and insurance_plans in the schema. Can you adjust the query so that it only lists medical records with the plan details if the doctor creating the record has a contact phone number that matches the plan's contact_phone? Still need the same output columns."},{"role":"assistant","content":"SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL;"},{"role":"user","content":"Actually, please sort the results by record_date in descending order and return only the latest 20 records."},{"role":"assistant","content":"SELECT mr.record_id, mr.patient_id, mr.doctor_id, mr.record_date, ip.plan_name\nFROM healthcare.medical_records mr\nJOIN healthcare.insurance_plans ip ON mr.doctor_id IS NOT NULL -- placeholder JOIN, fix below if you have a doctors table with contact_phone\nWHERE ip.plan_type = 'PPO' AND ip.contact_phone IS NOT NULL\nORDER BY mr.record_date DESC\nLIMIT 20;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\n","conversations":[{"role":"user","content":"Show the contract address, symbol, and current total supply for all Avalanche tokens from token_balances_avalanche."},{"role":"assistant","content":"SELECT tick AS contract_address, tick AS symbol, SUM(total_supply) AS current_total_supply\nFROM token_balances_avalanche\nGROUP BY tick;"},{"role":"user","content":"Now, include the latest price for each token by joining with token_prices_latest."},{"role":"assistant","content":"SELECT tba.tick AS contract_address, tba.tick AS symbol, SUM(tba.total_supply) AS current_total_supply, tpl.price AS latest_price\nFROM token_balances_avalanche tba\nLEFT JOIN token_prices_latest tpl\n ON tpl.address = tba.tick AND tpl.blockchain = 'Avalanche'\nGROUP BY tba.tick, tpl.price;"},{"role":"user","content":"Filter out tokens where the current_total_supply is less than 1000 and sort the results by latest_price descending."},{"role":"assistant","content":"SELECT tba.tick AS contract_address, tba.tick AS symbol, SUM(tba.total_supply) AS current_total_supply, tpl.price AS latest_price\nFROM token_balances_avalanche tba\nLEFT JOIN token_prices_latest tpl\n ON tpl.address = tba.tick AND tpl.blockchain = 'Avalanche'\nGROUP BY tba.tick, tpl.price\nHAVING SUM(tba.total_supply) >= 1000\nORDER BY tpl.price DESC;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.maintenance_records (\n record_id character varying(64) NOT NULL, -- Unique identifier for the maintenance record\n asset_id character varying(64) NOT NULL, -- ID of the asset being maintained (train_id, car_id, platform_id, etc.)\n asset_type character varying(32) NOT NULL, -- Type of asset ('Train', 'Car', 'Platform', 'Track')\n maintenance_type character varying(128) NOT NULL, -- e.g., 'Scheduled Inspection', 'Repair', 'Cleaning'\n staff_id character varying(64), -- Staff member performing\/overseeing maintenance\n start_datetime timestamp NOT NULL, -- When maintenance started\n end_datetime timestamp, -- When maintenance completed (nullable if ongoing)\n description text NOT NULL, -- Details of the maintenance performed\n cost numeric(12, 2), -- Cost associated with the maintenance\n status character varying(32) NOT NULL DEFAULT 'Completed', -- e.g., 'Scheduled', 'In Progress', 'Completed', 'Cancelled'\n PRIMARY KEY (record_id),\n FOREIGN KEY (staff_id) REFERENCES train_station_management.staff(staff_id)\n)\n","conversations":[{"role":"user","content":"What are the qualifications or training history of the staff member who performed the maintenance with record_id 'REC123'?"},{"role":"assistant","content":"I'm sorry, but I can't provide information about the qualifications or training history of staff members as this data is not stored in the maintenance_records table. This table only contains details about maintenance activities, such as asset information, maintenance type, dates, and costs. If you have another question or need assistance with data available in this table, I'm happy to help."}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n\/\/ Use Hashes for platform details. Key format: platform:\n\/\/ 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\n\n\/\/ To link platforms to stations (optional):\n\/\/ SADD station:station_xyz:platforms platform:plat_123 platform:plat_456\n\/\/ Use Hashes for train details. Key format: train:\n\/\/ HSET train:train_789 train_id \"train_789\" train_number \"Acela 2151\" model \"Siemens Velaro\" ... status \"Active\" ...\n\n\/\/ To find train by train_number (optional index):\n\/\/ SET train_number:\"Acela 2151\" train:train_789\n\/\/ Use Hashes for car details. Key format: car:\n\/\/ 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\"\n\n\/\/ To link cars to trains (optional):\n\/\/ SADD train:train_789:cars car:car_abc car:car_def\n\/\/ Use Hashes for details. Key format: route_station:\n\/\/ HSET route_station:rs_ne_1 route_station_id \"rs_ne_1\" route_id \"route_ne_corr\" station_id \"station_bos\" sequence_order 1 ...\n\n\/\/ To find stops for a route, use a Sorted Set (score by sequence_order):\n\/\/ ZADD route:route_ne_corr:stops 1 route_station:rs_ne_1\n\/\/ ZADD route:route_ne_corr:stops 2 route_station:rs_ne_2\n\/\/ Use Hashes for schedule details. Key format: schedule:\n\/\/ 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\"\n\/\/ Use Hashes for details. Key format: schedule_stop:\n\/\/ HSET schedule_stop:stop_sched1122_1 stop_id \"stop_sched1122_1\" schedule_id \"sched_1122\" station_id \"station_bos\" ...\n\n\/\/ To find stops for a schedule, use a Sorted Set (score by sequence_order):\n\/\/ ZADD schedule:sched_1122:stops 1 schedule_stop:stop_sched1122_1\n\/\/ ZADD schedule:sched_1122:stops 2 schedule_stop:stop_sched1122_2\n\/\/ Use Hashes for passenger details. Key format: passenger:\n\/\/ HSET passenger:pass_pqr passenger_id \"pass_pqr\" first_name \"Alice\" last_name \"Smith\" email \"alice.smith@example.com\" ...\n\n\/\/ To find passenger by email (optional index):\n\/\/ SET passenger_email:\"alice.smith@example.com\" passenger:pass_pqr\n\/\/ Use Hashes for booking details. Key format: booking:\n\/\/ HSET booking:book_zyx booking_id \"book_zyx\" passenger_id \"pass_pqr\" schedule_id \"sched_1122\" ... status \"Confirmed\" ...\n\n\/\/ To link bookings to passengers\/schedules (optional):\n\/\/ SADD passenger:pass_pqr:bookings booking:book_zyx\n\/\/ SADD schedule:sched_1122:bookings booking:book_zyx\n\/\/ Use Hashes for ticket details. Key format: ticket:\n\/\/ HSET ticket:tkt_1a2b ticket_id \"tkt_1a2b\" booking_id \"book_zyx\" car_id \"car_abc\" seat_number \"12A\" ... is_checked_in 0 ...\n\n\/\/ To link tickets to bookings (optional):\n\/\/ SADD booking:book_zyx:tickets ticket:tkt_1a2b\n\/\/ Use Hashes for staff details. Key format: staff:\n\/\/ HSET staff:staff_mno staff_id \"staff_mno\" first_name \"Bob\" ... employee_number \"E12345\" ... is_active 1\n\n\/\/ To find staff by employee number (optional index):\n\/\/ SET staff_employee_number:\"E12345\" staff:staff_mno\n\/\/ Use Hashes for maintenance record details. Key format: maintenance_record:\n\/\/ HSET maintenance_record:maint_rec_001 record_id \"maint_rec_001\" asset_id \"train_789\" asset_type \"Train\" ... status \"Completed\"\n\n\/\/ To link records to assets (optional):\n\/\/ SADD train:train_789:maintenance maintenance_record:maint_rec_001\n\/\/ SADD platform:plat_123:maintenance maintenance_record:maint_rec_002\n","conversations":[{"role":"user","content":"Can you provide the total number of cars associated with a specific train with train_id 'train_789'?"},{"role":"assistant","content":"SCARD train:train_789:cars"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.platforms (\n platform_id character varying(64) NOT NULL, -- Unique identifier for the platform\n station_id character varying(64) NOT NULL, -- Foreign key referencing stations\n platform_number character varying(10) NOT NULL, -- Platform identifier (e.g., '1A', '5')\n track_number character varying(10), -- Associated track number, if different\n status character varying(32) NOT NULL DEFAULT 'Operational', -- e.g., Operational, Maintenance, Closed\n length_meters numeric(8,2), -- Length of the platform in meters\n accessible boolean NOT NULL DEFAULT false, -- Is the platform accessible (e.g., wheelchair)?\n PRIMARY KEY (platform_id),\n FOREIGN KEY (station_id) REFERENCES train_station_management.stations(station_id)\n)\n","conversations":[{"role":"user","content":"What is the schedule of trains arriving at platform 1A at station XYZ on December 25th, 2023?"},{"role":"assistant","content":"I'm sorry, but I can't provide information about train schedules or specific arrival times as this data is not included in the platform management table. For train schedules, please refer to the train timetable or contact the station's customer service."}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n\/\/ db.createCollection('platforms')\n\/\/ Optional: db.platforms.createIndex({ platform_id: 1 }, { unique: true })\n\/\/ Optional: db.platforms.createIndex({ station_id: 1 })\n{\n _id: ObjectId(),\n platform_id: \"plat_123\", \/\/ String (unique)\n station_id: \"station_xyz\", \/\/ String (references stations.station_id)\n platform_number: \"1A\", \/\/ String\n track_number: \"T1\", \/\/ String\n status: \"Operational\", \/\/ String ('Operational', 'Maintenance', 'Closed')\n length_meters: 250.50, \/\/ Decimal128 or Double\n accessible: true \/\/ Boolean\n}\n\/\/ db.createCollection('routes')\n\/\/ Optional: db.routes.createIndex({ route_id: 1 }, { unique: true })\n{\n _id: ObjectId(),\n route_id: \"route_ne_corr\", \/\/ String (unique)\n route_name: \"Northeast Corridor\", \/\/ String\n description: \"High-speed rail linking Boston and Washington D.C.\", \/\/ String\n origin_station_id: \"station_bos\", \/\/ String (references stations.station_id)\n destination_station_id: \"station_was\", \/\/ String (references stations.station_id)\n is_active: true \/\/ Boolean\n}\n\/\/ db.createCollection('route_stations')\n\/\/ Optional: db.route_stations.createIndex({ route_station_id: 1 }, { unique: true })\n\/\/ Optional: db.route_stations.createIndex({ route_id: 1, sequence_order: 1 }, { unique: true })\n{\n _id: ObjectId(),\n route_station_id: \"rs_ne_1\", \/\/ String (unique)\n route_id: \"route_ne_corr\", \/\/ String (references routes.route_id)\n station_id: \"station_bos\", \/\/ String (references stations.station_id)\n sequence_order: 1, \/\/ Int32\n distance_from_previous_km: null, \/\/ Decimal128 or Double (null for first stop)\n typical_stop_duration_minutes: null \/\/ Int32 (null for origin\/destination or if no stop)\n}\n\/\/ --- OR --- Embed within the Route document:\n\/\/ {\n\/\/ _id: ObjectId(), route_id: \"route_ne_corr\", ...,\n\/\/ stations: [\n\/\/ { station_id: \"station_bos\", sequence_order: 1, distance_from_previous_km: null, typical_stop_duration_minutes: null },\n\/\/ { station_id: \"station_pvd\", sequence_order: 2, distance_from_previous_km: 70.5, typical_stop_duration_minutes: 5 },\n\/\/ ...\n\/\/ ]\n\/\/ }\n\/\/ db.createCollection('schedules')\n\/\/ Optional: db.schedules.createIndex({ schedule_id: 1 }, { unique: true })\n\/\/ Optional: db.schedules.createIndex({ route_id: 1, departure_datetime: 1 })\n{\n _id: ObjectId(),\n schedule_id: \"sched_1122\", \/\/ String (unique)\n train_id: \"train_789\", \/\/ String (references trains.train_id)\n route_id: \"route_ne_corr\", \/\/ String (references routes.route_id)\n departure_datetime: ISODate(\"2024-05-10T08:00:00-04:00\"), \/\/ Date (with timezone)\n arrival_datetime: ISODate(\"2024-05-10T15:30:00-04:00\"), \/\/ Date (with timezone)\n status: \"Scheduled\", \/\/ String ('Scheduled', 'On Time', 'Delayed', 'Cancelled', 'Arrived')\n notes: \"Track work expected near Philadelphia\" \/\/ String\n}\n\/\/ db.createCollection('schedule_stops')\n\/\/ Optional: db.schedule_stops.createIndex({ stop_id: 1 }, { unique: true })\n\/\/ Optional: db.schedule_stops.createIndex({ schedule_id: 1, sequence_order: 1 }, { unique: true })\n{\n _id: ObjectId(),\n stop_id: \"stop_sched1122_1\", \/\/ String (unique)\n schedule_id: \"sched_1122\", \/\/ String (references schedules.schedule_id)\n station_id: \"station_bos\", \/\/ String (references stations.station_id)\n platform_id: \"plat_bos_3\", \/\/ String (references platforms.platform_id, nullable)\n sequence_order: 1, \/\/ Int32\n scheduled_arrival_time: null, \/\/ Date\n scheduled_departure_time: ISODate(\"2024-05-10T08:00:00-04:00\"), \/\/ Date\n actual_arrival_time: null, \/\/ Date\n actual_departure_time: ISODate(\"2024-05-10T08:01:00-04:00\"), \/\/ Date\n status: \"On Time\" \/\/ String\n}\n\/\/ --- OR --- Embed within the Schedule document using an array 'stops'\n\/\/ db.createCollection('passengers')\n\/\/ Optional: db.passengers.createIndex({ passenger_id: 1 }, { unique: true })\n\/\/ Optional: db.passengers.createIndex({ email: 1 }, { unique: true, sparse: true })\n\/\/ Optional: db.passengers.createIndex({ phone_number: 1 }, { unique: true, sparse: true })\n{\n _id: ObjectId(),\n passenger_id: \"pass_pqr\", \/\/ String (unique)\n first_name: \"Alice\", \/\/ String\n last_name: \"Smith\", \/\/ String\n email: \"alice.smith@example.com\", \/\/ String (unique, sparse)\n phone_number: \"+15551234567\", \/\/ String (unique, sparse)\n date_of_birth: ISODate(\"1990-03-20\"), \/\/ Date\n loyalty_program_id: \"LOYALTY123\", \/\/ String\n created_at: ISODate(\"2023-02-01T11:00:00Z\") \/\/ Date\n}\n\/\/ db.createCollection('staff')\n\/\/ Optional: db.staff.createIndex({ staff_id: 1 }, { unique: true })\n\/\/ Optional: db.staff.createIndex({ employee_number: 1 }, { unique: true })\n\/\/ Optional: db.staff.createIndex({ contact_email: 1 }, { unique: true, sparse: true })\n{\n _id: ObjectId(),\n staff_id: \"staff_mno\", \/\/ String (unique)\n first_name: \"Bob\", \/\/ String\n last_name: \"Jones\", \/\/ String\n role: \"Conductor\", \/\/ String\n primary_station_id: null, \/\/ String (references stations.station_id, nullable)\n employee_number: \"E12345\", \/\/ String (unique)\n hire_date: ISODate(\"2018-06-01\"), \/\/ Date\n contact_email: \"bob.jones@example-rail.com\", \/\/ String (unique, sparse)\n contact_phone: \"+15559876543\", \/\/ String\n is_active: true \/\/ Boolean\n}\n","conversations":[{"role":"user","content":"Can you help me get the total number of operational platforms across all stations?"},{"role":"assistant","content":"db.platforms.countDocuments({ status: 'Operational' });"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.trains (\n train_id character varying(64) NOT NULL, -- Unique identifier for the train set\n train_number character varying(32) NOT NULL, -- Operational number of the train (e.g., 'Acela 2151')\n model character varying(128), -- Model of the train (e.g., 'Siemens Velaro')\n manufacturer character varying(128), -- Manufacturer of the train\n year_manufactured integer, -- Year the train was built\n capacity integer NOT NULL, -- Total passenger capacity\n status character varying(32) NOT NULL DEFAULT 'Active', -- e.g., Active, Maintenance, Retired\n last_maintenance_date date, -- Date of last scheduled maintenance\n next_maintenance_date date, -- Date of next scheduled maintenance\n PRIMARY KEY (train_id),\n UNIQUE (train_number)\n)\n","conversations":[{"role":"user","content":"What is the current location of train number Acela 2151?"},{"role":"assistant","content":"I'm sorry, but I don't have access to real-time location data for trains. The database only contains static information such as train ID, model, capacity, and maintenance schedules. For current location updates, please check with the train operator or a tracking service."}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\n","conversations":[{"role":"user","content":"What is the schedule of trains arriving at station with ID 'ST789' tomorrow?"},{"role":"assistant","content":"I'm sorry, but I can't provide the train schedule for station ID 'ST789' as this information is not available in the current database. The table only contains details about station attributes such as name, location, and number of platforms. For train schedules, please refer to the relevant train service provider or timetable database."}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\n","conversations":[{"role":"user","content":"What is the detailed repair history of the equipment used by the staff with staff_id 'STAFF123' during maintenance tasks?"},{"role":"assistant","content":"I'm sorry, but I can't provide information on the detailed repair history of equipment used by staff members. The data in the maintenance_records table only includes information about maintenance tasks, such as record_id, asset_id, maintenance type, and staff_id, but does not cover equipment repair histories."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"Show the symbol, name, and total supply for all SUI coins with status 'active'."},{"role":"assistant","content":"SELECT scm.symbol, scm.name, scm.coin_type, scm.total_supply\nFROM sui_coins_metadata scm\nWHERE scm.status = 'active';"},{"role":"user","content":"I received an error that column 'total_supply' doesn't exist in sui_coins_metadata."},{"role":"assistant","content":"SELECT scm.symbol, scm.name, scm.coin_type\nFROM sui_coins_metadata scm\nWHERE scm.status = 'active';"},{"role":"user","content":"Now, join with sui_coins to add up the total balance across all owners for each coin_type."},{"role":"assistant","content":"SELECT scm.symbol, scm.name, scm.coin_type, SUM(CAST(sc.balance AS NUMERIC)) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON scm.coin_type = sc.coin_type\nWHERE scm.status = 'active'\nGROUP BY scm.symbol, scm.name, scm.coin_type;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )\n","conversations":[{"role":"user","content":"List all ERC20 tokens with their names and symbols where the price is greater than $100, sorted by price in descending order."},{"role":"assistant","content":"SELECT scm.name, scm.symbol, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.coin_type = tpl.address WHERE tpl.price > 100 ORDER BY tpl.price DESC;"},{"role":"user","content":"I think there's an error in your query - it should be joining on address not coin_type. Also, can you add the decimals to the results?"},{"role":"assistant","content":"SELECT scm.name, scm.symbol, scm.decimals, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.object_id = tpl.address WHERE tpl.price > 100 ORDER BY tpl.price DESC;"},{"role":"user","content":"Now filter these results to only show tokens with decimals equal to 18 and limit to the top 10."},{"role":"assistant","content":"SELECT scm.name, scm.symbol, scm.decimals, tpl.price FROM sui_coins_metadata scm JOIN token_prices_latest tpl ON scm.object_id = tpl.address WHERE tpl.price > 100 AND scm.decimals = 18 ORDER BY tpl.price DESC LIMIT 10;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.platforms ( platform_id text, station_id text, platform_number text, track_number text, status text, length_meters numeric, accessible boolean )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\n","conversations":[{"role":"user","content":"Find maintenance log pairs for the same vehicle where the odometer reading is significantly higher in the second log compared to the first. Show the vehicle ID, service date and odometer for both logs in the pair, for increases greater than 50,000."},{"role":"assistant","content":"WITH RankedLogs AS ( SELECT *, LAG(odometer_reading, 1, odometer_reading) OVER (PARTITION BY vehicle_id ORDER BY service_date) as previous_odometer FROM transportation.maintenance_logs ) SELECT vehicle_id, service_date as current_log_date, odometer_reading as current_odometer, previous_odometer, odometer_reading - previous_odometer as odometer_increase FROM RankedLogs WHERE odometer_reading > previous_odometer + 50000 ORDER BY vehicle_id, service_date;"},{"role":"user","content":"From those pairs with significant increases, only include logs where the service date is after '2023-01-01'."},{"role":"assistant","content":"WITH RankedLogs AS ( SELECT *, LAG(odometer_reading, 1, odometer_reading) OVER (PARTITION BY vehicle_id ORDER BY service_date) as previous_odometer FROM transportation.maintenance_logs ) SELECT vehicle_id, service_date as current_log_date, odometer_reading as current_odometer, previous_odometer, odometer_reading - previous_odometer as odometer_increase FROM RankedLogs WHERE odometer_reading > previous_odometer + 50000 AND service_date > '2023-01-01' ORDER BY vehicle_id, service_date;"},{"role":"user","content":"For the filtered results, also show the service type and total cost of the current log entry."},{"role":"assistant","content":"WITH RankedLogs AS ( SELECT *, LAG(odometer_reading, 1, odometer_reading) OVER (PARTITION BY vehicle_id ORDER BY service_date) as previous_odometer FROM transportation.maintenance_logs ) SELECT vehicle_id, service_date as current_log_date, odometer_reading as current_odometer, previous_odometer, odometer_reading - previous_odometer as odometer_increase, service_type, cost FROM RankedLogs WHERE odometer_reading > previous_odometer + 50000 AND service_date > '2023-01-01' ORDER BY vehicle_id, service_date;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.staff ( staff_id text PRIMARY KEY, first_name text, last_name text, role text, primary_station_id text, employee_number text UNIQUE, hire_date date, contact_email text UNIQUE, contact_phone text, is_active boolean )\n","conversations":[{"role":"user","content":"What are the training programs or certifications completed by a staff member with the role of Platform Supervisor?"},{"role":"assistant","content":"I'm sorry, but I don't have access to information about the training programs or certifications completed by staff members. The data available to me only includes basic staff details such as name, role, and contact information. For details on training or certifications, please refer to the HR department or relevant training records."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text )\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address.text, table_id.text, key_bytes.text, key0.text, key1.text, static_data.text, encoded_lengths.text, dynamic_data.text, is_deleted.boolean, block_number.bigint, log_index.bigint )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )\n","conversations":[{"role":"user","content":"List all ERC20 tokens where the total supply is between 1 million and 10 million, including their names, symbols, and contract addresses."},{"role":"assistant","content":"SELECT ti.tick as name, ti.tick as symbol, tb.tick as contract_address FROM token_info ti JOIN token_balances tb ON ti.tick = tb.tick WHERE CAST(tb.total_supply AS decimal) BETWEEN 1000000 AND 10000000;"},{"role":"user","content":"I think there's an error in your query - it should be tb.total_supply not ti.total_supply. Also, can you add the current price of each token from the token_prices_latest table?"},{"role":"assistant","content":"SELECT ti.tick as name, ti.tick as symbol, tb.tick as contract_address, tpl.price FROM token_info ti JOIN token_balances tb ON ti.tick = tb.tick LEFT JOIN token_prices_latest tpl ON ti.tick = tpl.tick WHERE CAST(tb.total_supply AS decimal) BETWEEN 1000000 AND 10000000;"},{"role":"user","content":"Now sort these results by price in descending order and limit to the top 10."},{"role":"assistant","content":"SELECT ti.tick as name, ti.tick as symbol, tb.tick as contract_address, tpl.price FROM token_info ti JOIN token_balances tb ON ti.tick = tb.tick LEFT JOIN token_prices_latest tpl ON ti.tick = tpl.tick WHERE CAST(tb.total_supply AS decimal) BETWEEN 1000000 AND 10000000 ORDER BY tpl.price DESC LIMIT 10;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.aircraft_models (\n model_id character varying(64) NOT NULL, -- unique identifier for the aircraft model\n model_name character varying(128) NOT NULL, -- commercial name of the model (e.g., 737 MAX, A320neo)\n manufacturer character varying(128) NOT NULL, -- manufacturer name (e.g., Boeing, Airbus)\n passenger_capacity integer, -- typical passenger capacity\n max_range_km integer, -- maximum flight range in kilometers\n engine_type character varying(100), -- type of engines used\n wingspan_m numeric(6,2), -- wingspan in meters\n status character varying(50) NOT NULL, -- e.g., 'In Production', 'Development', 'Discontinued'\n first_flight_date date, -- date of the model's first flight\n PRIMARY KEY (model_id)\n)\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users ( user_id text, username text, email text, password_hash text, full_name text, profile_picture_url text, bio text, location text, created_at timestamp, updated_at timestamp, is_verified boolean )\nCREATE TABLE social_media.posts ( post_id text, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.hashtags ( hashtag_id text PRIMARY KEY, tag_name text, created_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n","conversations":[{"role":"user","content":"List each group conversation with its group name and the number of verified users who have posted in it."},{"role":"assistant","content":"SELECT c.conversation_id, c.group_name, COUNT(DISTINCT u.user_id) AS verified_posters\nFROM social_media.conversations c\nJOIN social_media.posts p ON p.location_lat IS NOT NULL -- Simulate posts linked to conversation (since no mapping, using location as a proxy)\nJOIN social_media.users u ON p.user_id = u.user_id AND u.is_verified = true\nWHERE c.is_group_chat = true\nGROUP BY c.conversation_id, c.group_name;"},{"role":"user","content":"Actually, only show groups created after May 1, 2024."},{"role":"assistant","content":"SELECT c.conversation_id, c.group_name, COUNT(DISTINCT u.user_id) AS verified_posters\nFROM social_media.conversations c\nJOIN social_media.posts p ON p.location_lat IS NOT NULL -- Simulate posts linked to conversation (since no mapping, using location as a proxy)\nJOIN social_media.users u ON p.user_id = u.user_id AND u.is_verified = true\nWHERE c.is_group_chat = true AND c.created_at > '2024-05-01'\nGROUP BY c.conversation_id, c.group_name;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holders (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- Number of held NFTs\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"I need to know the total USD value of all ERC-20 holdings by each wallet. Calculate the sum of (amount * price) using the latest token prices from token_prices_latest, grouped by wallet_address."},{"role":"assistant","content":"SELECT eb.wallet_address,\n SUM(CAST(eb.amount AS numeric) * tpl.price) AS total_usd_value\nFROM erc20_balances eb\nJOIN token_prices_latest tpl\n ON lower(eb.contract_address) = lower(tpl.address)\nGROUP BY eb.wallet_address;"},{"role":"user","content":"Actually, only include tokens where the price is greater than 0.5 USD and limit to the top 10 wallets by total_usd_value."},{"role":"assistant","content":"SELECT eb.wallet_address,\n SUM(CAST(eb.amount AS numeric) * tpl.price) AS total_usd_value\nFROM erc20_balances eb\nJOIN token_prices_latest tpl\n ON lower(eb.contract_address) = lower(tpl.address)\nWHERE tpl.price > 0.5\nGROUP BY eb.wallet_address\nORDER BY total_usd_value DESC\nLIMIT 10;"},{"role":"user","content":"Also show me the count of distinct token contracts held by each wallet as distinct_tokens."},{"role":"assistant","content":"SELECT eb.wallet_address,\n SUM(CAST(eb.amount AS numeric) * tpl.price) AS total_usd_value,\n COUNT(DISTINCT lower(eb.contract_address)) AS distinct_tokens\nFROM erc20_balances eb\nJOIN token_prices_latest tpl\n ON lower(eb.contract_address) = lower(tpl.address)\nWHERE tpl.price > 0.5\nGROUP BY eb.wallet_address\nORDER BY total_usd_value DESC\nLIMIT 10;"},{"role":"user","content":"Finally, filter out wallets that hold fewer than 2 distinct tokens."},{"role":"assistant","content":"SELECT eb.wallet_address,\n SUM(CAST(eb.amount AS numeric) * tpl.price) AS total_usd_value,\n COUNT(DISTINCT lower(eb.contract_address)) AS distinct_tokens\nFROM erc20_balances eb\nJOIN token_prices_latest tpl\n ON lower(eb.contract_address) = lower(tpl.address)\nWHERE tpl.price > 0.5\nGROUP BY eb.wallet_address\nHAVING COUNT(DISTINCT lower(eb.contract_address)) >= 2\nORDER BY total_usd_value DESC\nLIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata ( object_id varchar NOT NULL, coin_type varchar NOT NULL, status varchar NOT NULL, decimals bigint NOT NULL, description varchar NOT NULL, icon_url varchar NOT NULL, symbol varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id varchar NOT NULL, status varchar NOT NULL, collection_type varchar NOT NULL, package_id varchar NOT NULL, previous_transaction varchar NOT NULL, display varchar NOT NULL, owner varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )\n","conversations":[{"role":"user","content":"Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens where the price is greater than $0.10."},{"role":"assistant","content":"SELECT tm.name, tm.contract_address, tm.total_supply FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"},{"role":"user","content":"Can you also include the symbol and decimals for these tokens?"},{"role":"assistant","content":"SELECT tm.name, tm.symbol, tm.contract_address, tm.total_supply, tm.decimals FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"},{"role":"user","content":"Now filter these results to only show tokens with decimals equal to 18."},{"role":"assistant","content":"SELECT tm.name, tm.symbol, tm.contract_address, tm.total_supply, tm.decimals FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 AND tm.decimals = 18 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text )\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE mud_holesky_redstone ( address.text, table_id.text, key_bytes.text, key0.text, key1.text, static_data.text, encoded_lengths.text, dynamic_data.text, is_deleted.boolean, block_number.bigint, log_index.bigint )\nCREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )\n","conversations":[{"role":"user","content":"List all Avalanche tokens from `token_info_avalanche`. Show their tick, creator, and the count of distinct wallet addresses (sender or receiver) that have interacted with this tick in the `token_activities_avalanche` table."},{"role":"assistant","content":"SELECT ti.tick, ti.creator, COUNT(DISTINCT wallet_address) AS distinct_wallets_in_activity FROM token_info_avalanche AS ti LEFT JOIN ( SELECT tick, from_address AS wallet_address FROM token_activities_avalanche UNION ALL SELECT tick, to_address AS wallet_address FROM token_activities_avalanche ) AS ta ON ti.tick = ta.tick GROUP BY ti.tick, ti.creator;"},{"role":"user","content":"From that list, only show tokens where the count of distinct wallets is greater than 10. Order the results by the distinct wallet count in descending order."},{"role":"assistant","content":"SELECT ti.tick, ti.creator, COUNT(DISTINCT wallet_address) AS distinct_wallets_in_activity FROM token_info_avalanche AS ti LEFT JOIN ( SELECT tick, from_address AS wallet_address FROM token_activities_avalanche UNION ALL SELECT tick, to_address AS wallet_address FROM token_activities_avalanche ) AS ta ON ti.tick = ta.tick GROUP BY ti.tick, ti.creator HAVING COUNT(DISTINCT wallet_address) > 10 ORDER BY distinct_wallets_in_activity DESC;"},{"role":"user","content":"Limit the previous result to the top 5 tokens with the highest distinct wallet count in activities."},{"role":"assistant","content":"SELECT ti.tick, ti.creator, COUNT(DISTINCT wallet_address) AS distinct_wallets_in_activity FROM token_info_avalanche AS ti LEFT JOIN ( SELECT tick, from_address AS wallet_address FROM token_activities_avalanche UNION ALL SELECT tick, to_address AS wallet_address FROM token_activities_avalanche ) AS ta ON ti.tick = ta.tick GROUP BY ti.tick, ti.creator HAVING COUNT(DISTINCT wallet_address) > 10 ORDER BY distinct_wallets_in_activity DESC LIMIT 5;"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n\/\/ Use Hashes for ticket details. Key format: ticket:\n\/\/ HSET ticket:tkt_1a2b ticket_id \"tkt_1a2b\" booking_id \"book_zyx\" car_id \"car_abc\" seat_number \"12A\" ... is_checked_in 0 ...\n\n\/\/ To link tickets to bookings (optional):\n\/\/ SADD booking:book_zyx:tickets ticket:tkt_1a2b\n\/\/ Use Hashes for maintenance record details. Key format: maintenance_record:\n\/\/ HSET maintenance_record:maint_rec_001 record_id \"maint_rec_001\" asset_id \"train_789\" asset_type \"Train\" ... status \"Completed\"\n\n\/\/ To link records to assets (optional):\n\/\/ SADD train:train_789:maintenance maintenance_record:maint_rec_001\n\/\/ SADD platform:plat_123:maintenance maintenance_record:maint_rec_002\n","conversations":[{"role":"user","content":"\u7279\u5b9a\u306e\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0ID 'plat_123' \u306b\u95a2\u9023\u3059\u308b\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u8a18\u9332\u3092\u53d6\u5f97\u3059\u308b\u306e\u3092\u624b\u4f1d\u3063\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f\u307e\u305f\u3001\u8a18\u9332\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u3082\u542b\u3081\u3066\u304f\u3060\u3055\u3044\u3002"},{"role":"assistant","content":"SMEMBERS platform:plat_123:maintenance\nHGETALL maintenance_record:"},{"role":"user","content":"\u30b9\u30c6\u30fc\u30bf\u30b9\u304c 'Completed' \u306e\u8a18\u9332\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f"},{"role":"assistant","content":"SMEMBERS platform:plat_123:maintenance\nHGET maintenance_record: status\nHGETALL maintenance_record: (only if status = 'Completed')"},{"role":"user","content":"\u95a2\u9023\u3059\u308b\u8cc7\u7523\u30bf\u30a4\u30d7\u3082\u7d50\u679c\u306b\u542b\u3081\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f"},{"role":"assistant","content":"SMEMBERS platform:plat_123:maintenance\nHGET maintenance_record: status\nHGETALL maintenance_record: (only if status = 'Completed')"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n","conversations":[{"role":"user","content":"Which developers have created games that include at least one item of rarity 'Legendary'? Show the developer_id and the item_name."},{"role":"assistant","content":"SELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.in_game_items igi ON d.developer_id = igi.game_id \/* This assumes developer_id = game_id; adjust join logic as needed *\/\nWHERE igi.rarity = 'Legendary';"},{"role":"user","content":"I think the join is wrong, it should match developers to games and then in_game_items to games. Please revise the SQL."},{"role":"assistant","content":"-- Assuming the existence of a 'games' table with columns (game_id, developer_id)\nSELECT d.developer_id, igi.item_name\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.in_game_items igi ON g.game_id = igi.game_id\nWHERE igi.rarity = 'Legendary';"},{"role":"user","content":"You can only use the given tables. Is it possible to get a list of developers who have legendary items in their games with the available schema?"},{"role":"assistant","content":"-- Based on the given schema alone (without a games table), it's not possible to relate developers to in_game_items directly since there is no relationship between developer_id and game_id in the available tables."},{"role":"user","content":"Okay, then just list all 'Legendary' rarity in-game items, including their item_id, item_name, and cost_amount."},{"role":"assistant","content":"SELECT item_id, item_name, cost_amount\nFROM gaming_technology.in_game_items\nWHERE rarity = 'Legendary';"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.aircraft_models ( model_id text PRIMARY KEY, model_name text, manufacturer text, passenger_capacity int, max_range_km int, engine_type text, wingspan_m numeric, status text, first_flight_date date )\n","conversations":[{"role":"user","content":"What are the environmental impact assessments for the production of the Airbus A350 model?"},{"role":"assistant","content":"I'm sorry, but I don't have access to data regarding the environmental impact assessments for the production of specific aircraft models like the Airbus A350. My information is limited to the technical specifications and basic details stored in the database, such as model name, manufacturer, and capacity. If you have a question related to the available data, I'd be happy to assist."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"Show me all SUI coins with a balance greater than 1000, including their symbol and name."},{"role":"assistant","content":"SELECT sc.object_id, sc.coin_type, sc.balance, scm.symbol, scm.name FROM sui_coins sc JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type WHERE CAST(sc.balance AS DECIMAL) > 1000;"},{"role":"user","content":"Also, include the owner address for each coin in the result."},{"role":"assistant","content":"SELECT sc.object_id, sc.coin_type, sc.balance, sc.owner, scm.symbol, scm.name FROM sui_coins sc JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type WHERE CAST(sc.balance AS DECIMAL) > 1000;"},{"role":"user","content":"Only show coins which are currently 'active', and add the coin description."},{"role":"assistant","content":"SELECT sc.object_id, sc.coin_type, sc.balance, sc.owner, scm.symbol, scm.name, scm.description FROM sui_coins sc JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type WHERE CAST(sc.balance AS DECIMAL) > 1000 AND sc.status = 'active' AND scm.status = 'active';"},{"role":"user","content":"Actually, limit the result to just 10 coins and sort them by balance descending."},{"role":"assistant","content":"SELECT sc.object_id, sc.coin_type, sc.balance, sc.owner, scm.symbol, scm.name, scm.description FROM sui_coins sc JOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type WHERE CAST(sc.balance AS DECIMAL) > 1000 AND sc.status = 'active' AND scm.status = 'active' ORDER BY CAST(sc.balance AS DECIMAL) DESC LIMIT 10;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.platforms ( platform_id.text, station_id.text, platform_number.text, track_number.text, status.text, length_meters.numeric, accessible.boolean )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\n","conversations":[{"role":"user","content":"Can you narrow this down to only show cases where the case type is 'Criminal'?"},{"role":"assistant","content":"SELECT case_name, case_number, date_opened FROM legal_services.cases WHERE lead_lawyer_id = 'lawyer_abc' AND status = 'Open' AND case_type = 'Criminal';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas (\n block_timestamp timestamp(6) NOT NULL, -- Timestamp of the block when token metadata was recorded\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n transaction_hash varchar NOT NULL, -- Hash value of the transaction\n transaction_index bigint NOT NULL, -- Index of the transaction within the block\n from_address varchar NOT NULL, -- Address from which the transaction originated\n contract_address varchar NOT NULL, -- Address of the token contract\n symbol varchar NOT NULL, -- Symbol of the token\n total_supply varchar NOT NULL, -- erc20 contract total supply\n name varchar NOT NULL, -- Name of the token\n decimals bigint NOT NULL, -- Number of decimal places for the token\n is_erc20 integer NOT NULL, -- Flag indicating if the token is an ERC-20 token (0 or 1)\n is_erc721 integer NOT NULL, -- Flag indicating if the token is an ERC-721 token (0 or 1)\n is_erc1155 integer NOT NULL, -- Flag indicating if the token is an ERC-1155 token (0 or 1)\n is_proxy integer NOT NULL, -- Flag indicating if the token is a proxy (0 or 1)\n extra_info varchar NOT NULL, -- Additional information about the token\n pk integer NOT NULL -- Partition key for the table(floor(block_number \/ 5760))\n)\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- Number of held NFTs\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar NOT NULL, -- mint | transfer | burn\n tick varchar NOT NULL, -- Token tick\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Mint amount\n from_address varchar(42) NOT NULL, -- Address sending the inscription (matches from_address in transactions table)\n to_address varchar(42) NOT NULL -- Address receiving the inscription (match to_address in transactions table)\n)\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\n","conversations":[{"role":"user","content":"Show me the top 5 ERC20 tokens with the highest total supply, along with their names and contract addresses, but only include tokens where the price is greater than $0.10."},{"role":"assistant","content":"SELECT tm.name, tm.contract_address, tm.total_supply FROM token_metas tm WHERE tm.is_erc20 = 1 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"},{"role":"user","content":"I think there's a typo in your query - it should be 'total_supply' not 'total_supply'. Also, can you join this with the token_prices_latest table to include the current price of each token?"},{"role":"assistant","content":"SELECT tm.name, tm.contract_address, tm.total_supply, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tm.is_erc20 = 1 AND tpl.price > 0.10 ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"},{"role":"user","content":"The token_prices_latest table isn't in the schema. Can you modify the query to use the erc20_balances table instead to show the total balance held across all wallets for each token?"},{"role":"assistant","content":"SELECT tm.name, tm.contract_address, tm.total_supply, SUM(CAST(eb.amount AS decimal)) AS total_balance FROM token_metas tm JOIN erc20_balances eb ON tm.contract_address = eb.contract_address WHERE tm.is_erc20 = 1 GROUP BY tm.name, tm.contract_address, tm.total_supply ORDER BY CAST(tm.total_supply AS decimal) DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, project_id character varying(32) NOT NULL, project_name character varying(128) NOT NULL, rounds_name character varying(32), investment_value numeric(38,14), investment_date character varying(128), introduction character varying(128), valuation numeric(38,14) )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n","conversations":[{"role":"user","content":"Which projects had two or more fundraising rounds and what are the latest and earliest rounds with their investment values and dates? Also show the associated token symbol and its chain."},{"role":"assistant","content":"WITH rounds AS (\n SELECT\n project_id,\n project_name,\n MIN(investment_date) AS earliest_date,\n MAX(investment_date) AS latest_date\n FROM project_fundraising_record\n GROUP BY project_id, project_name\n HAVING COUNT(DISTINCT rounds_name) >= 2\n),\nearliest AS (\n SELECT\n p.project_id, p.project_name, p.rounds_name AS earliest_round, p.investment_value AS earliest_investment_value, p.investment_date AS earliest_date\n FROM project_fundraising_record p\n JOIN rounds r ON p.project_id = r.project_id AND p.investment_date = r.earliest_date\n),\nlatest AS (\n SELECT\n p.project_id, p.project_name, p.rounds_name AS latest_round, p.investment_value AS latest_investment_value, p.investment_date AS latest_date\n FROM project_fundraising_record p\n JOIN rounds r ON p.project_id = r.project_id AND p.investment_date = r.latest_date\n)\nSELECT\n e.project_name,\n e.earliest_round,\n e.earliest_investment_value,\n e.earliest_date,\n l.latest_round,\n l.latest_investment_value,\n l.latest_date,\n t.token_symbol,\n t.chain\nFROM earliest e\nJOIN latest l ON e.project_id = l.project_id\nLEFT JOIN token_basic_info t ON (\n lower(t.token_name) = lower(e.project_name)\n OR lower(e.project_name) = lower(t.token_symbol)\n OR lower(t.token_symbol) LIKE '%' || lower(e.project_name) || '%'\n OR lower(e.project_name) LIKE '%' || lower(t.token_symbol) || '%'\n)\nORDER BY e.project_name;"},{"role":"user","content":"It seems some projects are missing their token info. Can you adjust the join to try matching where either the project_name is contained in the token_name or token_symbol, or vice versa, all case-insensitive?"},{"role":"assistant","content":"WITH rounds AS (\n SELECT\n project_id,\n project_name,\n MIN(investment_date) AS earliest_date,\n MAX(investment_date) AS latest_date\n FROM project_fundraising_record\n GROUP BY project_id, project_name\n HAVING COUNT(DISTINCT rounds_name) >= 2\n),\nearliest AS (\n SELECT\n p.project_id, p.project_name, p.rounds_name AS earliest_round, p.investment_value AS earliest_investment_value, p.investment_date AS earliest_date\n FROM project_fundraising_record p\n JOIN rounds r ON p.project_id = r.project_id AND p.investment_date = r.earliest_date\n),\nlatest AS (\n SELECT\n p.project_id, p.project_name, p.rounds_name AS latest_round, p.investment_value AS latest_investment_value, p.investment_date AS latest_date\n FROM project_fundraising_record p\n JOIN rounds r ON p.project_id = r.project_id AND p.investment_date = r.latest_date\n)\nSELECT\n e.project_name,\n e.earliest_round,\n e.earliest_investment_value,\n e.earliest_date,\n l.latest_round,\n l.latest_investment_value,\n l.latest_date,\n t.token_symbol,\n t.chain\nFROM earliest e\nJOIN latest l ON e.project_id = l.project_id\nLEFT JOIN token_basic_info t ON (\n lower(t.token_name) LIKE '%' || lower(e.project_name) || '%'\n OR lower(e.project_name) LIKE '%' || lower(t.token_name) || '%'\n OR lower(t.token_symbol) LIKE '%' || lower(e.project_name) || '%'\n OR lower(e.project_name) LIKE '%' || lower(t.token_symbol) || '%'\n)\nORDER BY e.project_name;"},{"role":"user","content":"Actually, only show projects where the latest investment value is greater than $5,000,000 and the token info is matched. Please also order by latest investment value descending."},{"role":"assistant","content":"WITH rounds AS (\n SELECT\n project_id,\n project_name,\n MIN(investment_date) AS earliest_date,\n MAX(investment_date) AS latest_date\n FROM project_fundraising_record\n GROUP BY project_id, project_name\n HAVING COUNT(DISTINCT rounds_name) >= 2\n),\nearliest AS (\n SELECT\n p.project_id, p.project_name, p.rounds_name AS earliest_round, p.investment_value AS earliest_investment_value, p.investment_date AS earliest_date\n FROM project_fundraising_record p\n JOIN rounds r ON p.project_id = r.project_id AND p.investment_date = r.earliest_date\n),\nlatest AS (\n SELECT\n p.project_id, p.project_name, p.rounds_name AS latest_round, p.investment_value AS latest_investment_value, p.investment_date AS latest_date\n FROM project_fundraising_record p\n JOIN rounds r ON p.project_id = r.project_id AND p.investment_date = r.latest_date\n)\nSELECT\n e.project_name,\n e.earliest_round,\n e.earliest_investment_value,\n e.earliest_date,\n l.latest_round,\n l.latest_investment_value,\n l.latest_date,\n t.token_symbol,\n t.chain\nFROM earliest e\nJOIN latest l ON e.project_id = l.project_id\nJOIN token_basic_info t ON (\n lower(t.token_name) LIKE '%' || lower(e.project_name) || '%'\n OR lower(e.project_name) LIKE '%' || lower(t.token_name) || '%'\n OR lower(t.token_symbol) LIKE '%' || lower(e.project_name) || '%'\n OR lower(e.project_name) LIKE '%' || lower(t.token_symbol) || '%'\n)\nWHERE l.latest_investment_value > 5000000\nORDER BY l.latest_investment_value DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\n","conversations":[{"role":"user","content":"Which exchanges hold the largest total USD value of tokens on the BSC chain in the most recent snapshot, and what is the top token (by usd_value) held by each exchange?"},{"role":"assistant","content":"WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"},{"role":"user","content":"Can you add the number of distinct tokens each exchange holds on BSC in the latest snapshot to the result?"},{"role":"assistant","content":"WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value,\n COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n e.token_count,\n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"},{"role":"user","content":"I'd like the results filtered so only exchanges holding more than $2,000,000 in total on BSC are included."},{"role":"assistant","content":"WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT \n c.exchange, \n SUM(c.usd_value) AS total_usd_value,\n COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n GROUP BY c.exchange\n HAVING SUM(c.usd_value) > 2000000\n),\ntop_token_per_exchange AS (\n SELECT c.exchange, c.token_symbol, c.usd_value, ROW_NUMBER() OVER (PARTITION BY c.exchange ORDER BY c.usd_value DESC) AS rn\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n WHERE c.chain = 'BSC'\n)\nSELECT \n t.exchange, \n e.total_usd_value, \n e.token_count,\n t.token_symbol AS top_token_symbol, \n t.usd_value AS top_token_usd_value\nFROM exchange_totals e\nJOIN top_token_per_exchange t ON e.exchange = t.exchange AND t.rn = 1\nORDER BY e.total_usd_value DESC;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.trains ( train_id.text, train_number.text, model.text, manufacturer.text, year_manufactured.integer, capacity.integer, status.text, last_maintenance_date.date, next_maintenance_date.date )\n","conversations":[{"role":"user","content":"What is the average speed of train number T9876 during its last journey?"},{"role":"assistant","content":"I'm sorry, but I can't provide information on the average speed of train number T9876 during its last journey. The data in the trains table does not include details about travel speed or journey-specific performance metrics."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.transactions ( transaction_id text PRIMARY KEY, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )\n","conversations":[{"role":"user","content":"I want to find pairs of transactions where one transaction\u2019s related_account_id matches the other\u2019s account_id, indicating reciprocal transfers between accounts."},{"role":"assistant","content":"SELECT t1.transaction_id AS outgoing_txn, t2.transaction_id AS incoming_txn, t1.account_id, t1.related_account_id, t1.transaction_date AS outgoing_date, t2.transaction_date AS incoming_date, t1.currency\nFROM financial_services.transactions t1\nJOIN financial_services.transactions t2\n ON t1.related_account_id = t2.account_id\n AND t2.related_account_id = t1.account_id;"},{"role":"user","content":"Actually, limit these transactions to those that occurred in the last 90 days."},{"role":"assistant","content":"SELECT t1.transaction_id AS outgoing_txn, t2.transaction_id AS incoming_txn, t1.account_id, t1.related_account_id, t1.transaction_date AS outgoing_date, t2.transaction_date AS incoming_date, t1.currency\nFROM financial_services.transactions t1\nJOIN financial_services.transactions t2\n ON t1.related_account_id = t2.account_id\n AND t2.related_account_id = t1.account_id\nWHERE t1.transaction_date >= CURRENT_DATE - INTERVAL '90 days';"},{"role":"user","content":"And make sure both transactions use the same currency."},{"role":"assistant","content":"SELECT t1.transaction_id AS outgoing_txn, t2.transaction_id AS incoming_txn, t1.account_id, t1.related_account_id, t1.transaction_date AS outgoing_date, t2.transaction_date AS incoming_date, t1.currency\nFROM financial_services.transactions t1\nJOIN financial_services.transactions t2\n ON t1.related_account_id = t2.account_id\n AND t2.related_account_id = t1.account_id\nWHERE t1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\n AND t1.currency = t2.currency;"},{"role":"user","content":"Finally, order the output by the outgoing transaction date descending."},{"role":"assistant","content":"SELECT t1.transaction_id AS outgoing_txn, t2.transaction_id AS incoming_txn, t1.account_id, t1.related_account_id, t1.transaction_date AS outgoing_date, t2.transaction_date AS incoming_date, t1.currency\nFROM financial_services.transactions t1\nJOIN financial_services.transactions t2\n ON t1.related_account_id = t2.account_id\n AND t2.related_account_id = t1.account_id\nWHERE t1.transaction_date >= CURRENT_DATE - INTERVAL '90 days'\n AND t1.currency = t2.currency\nORDER BY t1.transaction_date DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.routes ( route_id character varying(64) NOT NULL, route_number character varying(32) NOT NULL UNIQUE, description text, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, distance_km numeric(10, 2), estimated_duration_minutes integer, type character varying(32) NOT NULL, PRIMARY KEY (route_id) )\nCREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )\nCREATE TABLE transportation.locations ( location_id character varying(64) NOT NULL, name character varying(255) NOT NULL, type character varying(64) NOT NULL, address_line1 character varying(255), city character varying(128), state_province character varying(128), postal_code character varying(32), country character varying(64) NOT NULL, latitude numeric(9, 6), longitude numeric(9, 6), timezone character varying(64), PRIMARY KEY (location_id) )\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, trip_id character varying(64), log_timestamp timestamp with time zone NOT NULL, fuel_type character varying(32) NOT NULL, quantity numeric(10, 3) NOT NULL, unit character varying(16) NOT NULL, cost_per_unit numeric(8, 4), total_cost numeric(10, 2) NOT NULL, odometer_reading integer, location_id character varying(64), PRIMARY KEY (fuel_log_id) )\nCREATE TABLE transportation.passengers ( passenger_id character varying(64) NOT NULL, first_name character varying(128) NOT NULL, last_name character varying(128) NOT NULL, email character varying(128) UNIQUE, phone_number character varying(32) UNIQUE, date_of_birth date, loyalty_program_id character varying(64), created_at timestamp with time zone NOT NULL, PRIMARY KEY (passenger_id) )\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n","conversations":[{"role":"user","content":"List all vehicles and their last maintenance service date along with the odometer reading, including only those that have not had a fuel refill in the past 30 days."},{"role":"assistant","content":"SELECT m.vehicle_id,\n m.last_service_date,\n m.last_odometer\nFROM (\n SELECT l.vehicle_id,\n MAX(l.service_date) AS last_service_date,\n (SELECT odometer_reading\n FROM transportation.maintenance_logs\n WHERE vehicle_id = l.vehicle_id\n ORDER BY service_date DESC\n LIMIT 1) AS last_odometer\n FROM transportation.maintenance_logs l\n GROUP BY l.vehicle_id\n) AS m\nLEFT JOIN (\n SELECT fl.vehicle_id,\n MAX(fl.log_timestamp) AS last_fuel_date\n FROM transportation.fuel_logs fl\n GROUP BY fl.vehicle_id\n) AS f ON m.vehicle_id = f.vehicle_id\nWHERE COALESCE(f.last_fuel_date, '1900-01-01'::timestamp) < NOW() - INTERVAL '30 days';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract\n amount varchar NOT NULL, -- Wallet's on-chain balance at the corresponding block height\n pk integer NOT NULL -- Partition key for the table(floor(block_number \/ 7200))\n)\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n name varchar NOT NULL, -- name fields for the functionType in contract\n symbol varchar NOT NULL, -- symbol fields for the functionType in contract\n deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract\n deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n description varchar NOT NULL, -- description fields for the functionType in contract\n slug varchar NOT NULL, -- slug fields for the functionType in contract\n media_info varchar NOT NULL, -- media_info fields for the functionType in contract\n image_url varchar NOT NULL, -- image_url fields for the functionType in contract\n banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n banner varchar NOT NULL, -- banner fields for the functionType in contract\n token_count bigint NOT NULL, -- token_count fields for the functionType in contract\n floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract\n floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract\n floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time \/ 1000 \/ 86400 \/ 30))\n)\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"What is the total USD value held across all wallets for the ERC20 token with symbol 'DAI'?"},{"role":"assistant","content":"SELECT SUM((eb.amount::numeric \/ POWER(10, tm.decimals)) * tpl.price) AS total_usd\nFROM erc20_balances eb\nJOIN token_metas tm ON eb.contract_address = tm.contract_address AND tm.symbol = 'DAI'\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum';"},{"role":"user","content":"Could you break it down to show the top 5 wallets by USD value for this token?"},{"role":"assistant","content":"SELECT eb.wallet_address,\n SUM((eb.amount::numeric \/ POWER(10, tm.decimals)) * tpl.price) AS usd_value\nFROM erc20_balances eb\nJOIN token_metas tm ON eb.contract_address = tm.contract_address AND tm.symbol = 'DAI'\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nGROUP BY eb.wallet_address\nORDER BY usd_value DESC\nLIMIT 5;"},{"role":"user","content":"I received a type error because amount is stored as text. Can you cast the fields to numeric explicitly in the query?"},{"role":"assistant","content":"SELECT eb.wallet_address,\n SUM((CAST(eb.amount AS numeric) \/ POWER(10, tm.decimals)) * CAST(tpl.price AS numeric)) AS usd_value\nFROM erc20_balances eb\nJOIN token_metas tm ON eb.contract_address = tm.contract_address AND tm.symbol = 'DAI'\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nGROUP BY eb.wallet_address\nORDER BY usd_value DESC\nLIMIT 5;"},{"role":"user","content":"Also include the latest price timestamp alongside the USD value for each wallet."},{"role":"assistant","content":"SELECT eb.wallet_address,\n SUM((CAST(eb.amount AS numeric) \/ POWER(10, tm.decimals)) * tpl.price) AS usd_value,\n MAX(tpl.timestamp) AS price_timestamp\nFROM erc20_balances eb\nJOIN token_metas tm ON eb.contract_address = tm.contract_address AND tm.symbol = 'DAI'\nJOIN token_prices_latest tpl ON tm.contract_address = tpl.address AND tpl.blockchain = 'Ethereum'\nGROUP BY eb.wallet_address\nORDER BY usd_value DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players (\n player_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the player\n username character varying(100) NOT NULL UNIQUE, -- player's chosen display name\n email character varying(255) NOT NULL UNIQUE, -- player's email address for login\/recovery\n password_hash text NOT NULL, -- securely hashed password\n registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the player account was created\n last_login timestamp with time zone, -- timestamp of the last successful login\n country_code character(2), -- player's country (ISO 3166-1 alpha-2)\n status character varying(20) NOT NULL DEFAULT 'active', -- account status (e.g., active, banned, suspended)\n profile_data jsonb, -- flexible field for avatar url, bio, preferences etc.\n PRIMARY KEY (player_id)\n)\nCREATE TABLE gaming_technology.games (\n game_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game\n title character varying(200) NOT NULL, -- official title of the game\n developer_id uuid NOT NULL, -- FK linking to the developers table\n publisher_id uuid, -- FK linking to a potential publishers table (optional)\n genre character varying(100), -- primary genre (e.g., RPG, FPS, Strategy)\n release_date date, -- official release date\n description text, -- short description or synopsis of the game\n platform character varying(50) NOT NULL, -- primary platform (e.g., PC, PlayStation 5, Xbox Series X, Mobile)\n engine character varying(100), -- game engine used (e.g., Unreal Engine 5, Unity)\n website character varying(255), -- official website URL\n PRIMARY KEY (game_id)\n -- FOREIGN KEY (developer_id) REFERENCES gaming_technology.developers(developer_id) -- Example FK constraint\n)\nCREATE TABLE gaming_technology.developers (\n developer_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the developer studio\n name character varying(150) NOT NULL UNIQUE, -- name of the development studio\n country character varying(100), -- country where the studio is based\n founded_year integer, -- year the studio was founded\n website character varying(255), -- developer's official website\n created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (developer_id)\n)\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers (\n server_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game server instance\n game_id uuid NOT NULL, -- FK linking to the game this server hosts\n server_name character varying(150), -- display name for the server\n region character varying(50) NOT NULL, -- geographical region (e.g., us-east-1, eu-west-2)\n ip_address character varying(45), -- IP address (IPv4 or IPv6)\n port integer, -- network port number\n current_players integer NOT NULL DEFAULT 0, -- number of players currently connected\n max_players integer NOT NULL, -- maximum player capacity\n status character varying(30) NOT NULL DEFAULT 'offline', -- server status (e.g., online, offline, maintenance)\n last_heartbeat timestamp with time zone, -- last time the server reported its status\n PRIMARY KEY (server_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.achievements (\n achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for an achievement definition\n game_id uuid NOT NULL, -- FK linking to the game the achievement belongs to\n name character varying(150) NOT NULL, -- name of the achievement\n description text NOT NULL, -- how to unlock the achievement\n icon_url character varying(255), -- URL for the achievement's icon\n points integer DEFAULT 0, -- points awarded for unlocking (optional)\n hidden boolean DEFAULT false, -- whether the achievement details are hidden until unlocked\n PRIMARY KEY (achievement_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_achievements (\n player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for this unlock instance\n player_id uuid NOT NULL, -- FK linking to the player who unlocked it\n achievement_id uuid NOT NULL, -- FK linking to the achievement definition\n unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the achievement was unlocked\n PRIMARY KEY (player_achievement_id),\n UNIQUE (player_id, achievement_id) -- Ensure a player can only unlock an achievement once\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (achievement_id) REFERENCES gaming_technology.achievements(achievement_id)\n)\n","conversations":[{"role":"user","content":"Show a list of all game developers with their name and founded year."},{"role":"assistant","content":"SELECT\n name,\n founded_year\nFROM gaming_technology.developers;"},{"role":"user","content":"Please filter the list to only include developers founded in the year 1998."},{"role":"assistant","content":"SELECT\n name,\n founded_year\nFROM gaming_technology.developers\nWHERE\n founded_year = 1998;"},{"role":"user","content":"Can you also include the number of games each of these developers has released?"},{"role":"assistant","content":"SELECT\n T1.name,\n T1.founded_year,\n COUNT(T2.game_id) AS game_count\nFROM gaming_technology.developers AS T1\nLEFT JOIN gaming_technology.games AS T2\n ON T1.developer_id = T2.developer_id\nWHERE\n T1.founded_year = 1998\nGROUP BY\n T1.developer_id,\n T1.name,\n T1.founded_year;"},{"role":"user","content":"Now, only show the developers who have released exactly 2 games."},{"role":"assistant","content":"SELECT\n T1.name,\n T1.founded_year,\n COUNT(T2.game_id) AS game_count\nFROM gaming_technology.developers AS T1\nJOIN gaming_technology.games AS T2\n ON T1.developer_id = T2.developer_id\nWHERE\n T1.founded_year = 1998\nGROUP BY\n T1.developer_id,\n T1.name,\n T1.founded_year\nHAVING\n COUNT(T2.game_id) = 2;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\n","conversations":[{"role":"user","content":"Show me the total number of invoices issued."},{"role":"assistant","content":"SELECT COUNT(*) FROM invoices;"},{"role":"user","content":"How many invoices were issued in each status?"},{"role":"assistant","content":"SELECT status, COUNT(*) FROM invoices GROUP BY status;"},{"role":"user","content":"Only include statuses that have more than 10 invoices."},{"role":"assistant","content":"SELECT status, COUNT(*) FROM invoices GROUP BY status HAVING COUNT(*) > 10;"},{"role":"user","content":"Also, only consider invoices issued in the year 2023 and order the results by the count in descending order."},{"role":"assistant","content":"SELECT status, COUNT(*) FROM invoices WHERE EXTRACT(YEAR FROM issue_date) = 2023 GROUP BY status HAVING COUNT(*) > 10 ORDER BY COUNT(*) DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id.text, license_plate.text, vin.text, make.text, model.text, year.integer, type.text, capacity.integer, fuel_type.text, status.text, depot_id.text, acquisition_date.date )\n","conversations":[{"role":"user","content":"Show me all vehicles that are due for their next service before the end of this month, along with their last service date and type."},{"role":"assistant","content":"SELECT v.vehicle_id, v.make, v.model, s.service_date, s.service_type FROM transportation.vehicles v JOIN transportation.service_logs s ON v.vehicle_id = s.vehicle_id WHERE s.next_service_due <= DATE('now', 'start of month', '+1 month', '-1 day') ORDER BY s.next_service_due;"},{"role":"user","content":"Can you include the mechanic who performed the last service and order the results by how soon the next service is due?"},{"role":"assistant","content":"SELECT v.vehicle_id, v.make, v.model, s.service_date, s.service_type, s.mechanic, s.next_service_due FROM transportation.vehicles v JOIN transportation.service_logs s ON v.vehicle_id = s.vehicle_id WHERE s.next_service_due <= DATE('now', 'start of month', '+1 month', '-1 day') ORDER BY s.next_service_due ASC;"},{"role":"user","content":"Now filter this to only show vehicles where the last service was an 'Engine Tune-up'."},{"role":"assistant","content":"SELECT v.vehicle_id, v.make, v.model, s.service_date, s.service_type, s.mechanic, s.next_service_due FROM transportation.vehicles v JOIN transportation.service_logs s ON v.vehicle_id = s.vehicle_id WHERE s.next_service_due <= DATE('now', 'start of month', '+1 month', '-1 day') AND s.service_type = 'Engine Tune-up' ORDER BY s.next_service_due ASC;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.aircraft_models ( model_id text, model_name text, manufacturer text, passenger_capacity integer, max_range_km integer, engine_type text, wingspan_m numeric, status text, first_flight_date date )\n","conversations":[{"role":"user","content":"What are the safety ratings or crash statistics for the Boeing 787 Dreamliner?"},{"role":"assistant","content":"I'm sorry, but I don't have access to safety ratings or crash statistics for specific aircraft models like the Boeing 787 Dreamliner. My data is limited to the information in the aircraft_models table, which includes details such as model name, manufacturer, passenger capacity, and technical specifications. For safety-related information, I recommend consulting official aviation authorities or safety reports."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n","conversations":[{"role":"user","content":"For each blockchain (chain), find the token with the highest ROI in the smart_money_token_performance table, and include that token's narrative from smart_money_token_inflow, its net_flow, and avg_cost."},{"role":"assistant","content":"WITH ranked_tokens AS ( SELECT p.chain, p.token_symbol, p.token_address, p.roi, p.avg_cost, i.narrative, i.net_flow, ROW_NUMBER() OVER (PARTITION BY p.chain ORDER BY p.roi DESC) AS rn FROM smart_money_token_performance p LEFT JOIN smart_money_token_inflow i ON p.token_address = i.token_address AND p.chain = i.chain ) SELECT chain, token_symbol, roi, narrative, net_flow, avg_cost FROM ranked_tokens WHERE rn = 1;"},{"role":"user","content":"Please exclude any tokens where net_flow is negative or NULL from these results."},{"role":"assistant","content":"WITH ranked_tokens AS ( SELECT p.chain, p.token_symbol, p.token_address, p.roi, p.avg_cost, i.narrative, i.net_flow, ROW_NUMBER() OVER (PARTITION BY p.chain ORDER BY p.roi DESC) AS rn FROM smart_money_token_performance p JOIN smart_money_token_inflow i ON p.token_address = i.token_address AND p.chain = i.chain WHERE i.net_flow > 0 ) SELECT chain, token_symbol, roi, narrative, net_flow, avg_cost FROM ranked_tokens WHERE rn = 1;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.stations ( station_id text PRIMARY KEY, station_name text, city text, state_province text, country_code text, address text, timezone text, number_of_platforms int, created_at timestamp, last_updated_at timestamp )\n","conversations":[{"role":"user","content":"What is the maintenance schedule for the platforms at the station with ID 'ST234' for the next month?"},{"role":"assistant","content":"I'm sorry, but I don't have access to the maintenance schedule for the platforms at any station. The data I have only includes basic station information such as station ID, name, location, and number of platforms. For maintenance schedules, you may need to contact the station management or relevant authorities."}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE manufacturing.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(128) NOT NULL, -- e.g., 'Aircraft Mechanic', 'Quality Inspector', 'Assembly Technician'\n skill_certifications text, -- comma-separated list or JSON of certifications\n hire_date date NOT NULL,\n assigned_line_id character varying(64), -- FK to the assembly line the employee is currently assigned to (can be null)\n employment_status character varying(50) NOT NULL, -- e.g., 'Active', 'On Leave', 'Terminated'\n supervisor_employee_id character varying(64), -- FK to the employee's supervisor (self-reference, nullable)\n PRIMARY KEY (employee_id)\n)\n","conversations":[{"role":"user","content":"What is the current salary of employee with ID 'EMP123'?"},{"role":"assistant","content":"I'm sorry, but I can't provide information about an employee's salary as it is not included in the data available in the 'employees' table."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"List all ERC20 tokens from the metadata table. Show their symbol, name, contract address, and total supply."},{"role":"assistant","content":"SELECT symbol, name, contract_address, total_supply FROM token_metas WHERE is_erc20 = 1"},{"role":"user","content":"Add the latest USD price for each of these tokens by joining with the latest prices table."},{"role":"assistant","content":"SELECT t1.symbol, t1.name, t1.contract_address, t1.total_supply, t2.price FROM token_metas AS t1 JOIN token_prices_latest AS t2 ON t1.contract_address = t2.address WHERE t1.is_erc20 = 1"},{"role":"user","content":"Filter the results to only include tokens where the latest price is above 5 USD and sort by price descending. Limit to the top 10."},{"role":"assistant","content":"SELECT t1.symbol, t1.name, t1.contract_address, t1.total_supply, t2.price FROM token_metas AS t1 JOIN token_prices_latest AS t2 ON t1.contract_address = t2.address WHERE t1.is_erc20 = 1 AND t2.price > 5 ORDER BY t2.price DESC LIMIT 10"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.routes ( route_id text, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes integer, type text )\n","conversations":[{"role":"user","content":"Show a list of all routes including their route number, type, distance in km, and estimated duration in minutes."},{"role":"assistant","content":"SELECT\n route_number,\n type,\n distance_km,\n estimated_duration_minutes\nFROM transportation.routes;"},{"role":"user","content":"Filter this list to only show routes of type 'Express'."},{"role":"assistant","content":"SELECT\n route_number,\n type,\n distance_km,\n estimated_duration_minutes\nFROM transportation.routes\nWHERE\n type = 'Express';"},{"role":"user","content":"Sort the results by distance in descending order and limit to the top 5."},{"role":"assistant","content":"SELECT\n route_number,\n type,\n distance_km,\n estimated_duration_minutes\nFROM transportation.routes\nWHERE\n type = 'Express'\nORDER BY\n distance_km DESC\nLIMIT 5;"},{"role":"user","content":"Add the description and a column 'duration_per_km' showing the duration per kilometer."},{"role":"assistant","content":"SELECT\n route_number,\n type,\n description,\n distance_km,\n estimated_duration_minutes,\n CAST(estimated_duration_minutes AS NUMERIC) \/ NULLIF(distance_km, 0) AS duration_per_km\nFROM transportation.routes\nWHERE\n type = 'Express'\nORDER BY\n distance_km DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\n","conversations":[{"role":"user","content":"Show me all trips that were delayed by more than 1 hour, including their vehicle and driver IDs, along with the origin and destination location IDs."},{"role":"assistant","content":"SELECT trip_id, vehicle_id, driver_id, origin_location_id, destination_location_id FROM transportation.trips WHERE EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))\/3600 > 1 AND status = 'Completed';"},{"role":"user","content":"Now include the passenger count for these trips, but only show trips that had more than 5 passengers."},{"role":"assistant","content":"SELECT trip_id, vehicle_id, driver_id, origin_location_id, destination_location_id, passenger_count FROM transportation.trips WHERE EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))\/3600 > 1 AND status = 'Completed' AND passenger_count > 5;"},{"role":"user","content":"Can you order these results by the delay time in descending order, showing the longest delays first?"},{"role":"assistant","content":"SELECT trip_id, vehicle_id, driver_id, origin_location_id, destination_location_id, passenger_count, (actual_departure - scheduled_departure) AS delay_time FROM transportation.trips WHERE EXTRACT(EPOCH FROM (actual_departure - scheduled_departure))\/3600 > 1 AND status = 'Completed' AND passenger_count > 5 ORDER BY delay_time DESC;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.staff ( staff_id.text, first_name.text, last_name.text, role.text, primary_station_id.text, employee_number.text, hire_date.date, contact_email.text, contact_phone.text, is_active.boolean )\n","conversations":[{"role":"user","content":"What is the current job satisfaction level or feedback from staff members working at a specific train station?"},{"role":"assistant","content":"I'm sorry, but I can't provide information on job satisfaction levels or feedback from staff members as this data is not included in the staff table."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )\n","conversations":[{"role":"user","content":"Show me all NFT holders who own more than 10 of the same token, including the contract address, token ID, and wallet address."},{"role":"assistant","content":"SELECT nh.contract_address, nh.token_id, nh.wallet_address, CAST(nh.amount AS decimal) AS token_count FROM nft_holder_historical nh WHERE CAST(nh.amount AS decimal) > 10;"},{"role":"user","content":"Can you join this with the nft_metadata table to include the token name and image URI for each token?"},{"role":"assistant","content":"SELECT nh.contract_address, nh.token_id, nh.wallet_address, CAST(nh.amount AS decimal) AS token_count, nm.name AS token_name, nm.image_uri FROM nft_holder_historical nh JOIN nft_metadata nm ON nh.contract_address = nm.contract_address AND nh.token_id = nm.token_id WHERE CAST(nh.amount AS decimal) > 10;"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nIndex 'aircraft_models'. Mapping: { properties: { model_id: { type: 'keyword' }, model_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, manufacturer: { type: 'keyword' }, passenger_capacity: { type: 'integer' }, max_range_km: { type: 'integer' }, engine_type: { type: 'keyword' }, wingspan_m: { type: 'float' }, status: { type: 'keyword' }, first_flight_date: { type: 'date' } } }. Document _id can be set to model_id.\nIndex 'components'. Mapping: { properties: { component_id: { type: 'keyword' }, part_number: { type: 'keyword' }, component_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, description: { type: 'text' }, material_id: { type: 'keyword' }, supplier_id: { type: 'keyword' }, weight_kg: { type: 'scaled_float', scaling_factor: 1000 }, cost_usd: { type: 'scaled_float', scaling_factor: 100 }, criticality_level: { type: 'keyword' } } }. Document _id can be component_id.\nIndex 'materials'. Mapping: { properties: { material_id: { type: 'keyword' }, material_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, specification: { type: 'keyword' }, description: { type: 'text' }, density_kg_m3: { type: 'float' }, tensile_strength_mpa: { type: 'integer' } } }. Document _id can be material_id.\nIndex 'assembly_lines'. Mapping: { properties: { line_id: { type: 'keyword' }, line_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, location_building: { type: 'keyword' }, location_area: { type: 'keyword' }, aircraft_model_id: { type: 'keyword' }, capacity_units_per_month: { type: 'integer' }, status: { type: 'keyword' } } }. Document _id can be line_id.\nIndex 'assembly_steps'. Mapping: { properties: { step_id: { type: 'keyword' }, line_id: { type: 'keyword' }, step_number: { type: 'integer' }, step_name: { type: 'text', fields: { keyword: { type: 'keyword', ignore_above: 256 } } }, description: { type: 'text' }, standard_duration_hours: { type: 'float' }, required_skill_level: { type: 'keyword' }, workstation: { type: 'keyword' } } }. Document _id can be step_id.\nIndex 'aircraft_builds'. Mapping: { properties: { build_id: { type: 'keyword' }, serial_number: { type: 'keyword' }, model_id: { type: 'keyword' }, assembly_line_id: { type: 'keyword' }, build_start_date: { type: 'date' }, estimated_completion_date: { type: 'date' }, actual_completion_date: { type: 'date' }, current_status: { type: 'keyword' }, customer_order_id: { type: 'keyword' } } }. Document _id can be build_id.\nIndex 'inspections'. Mapping: { properties: { inspection_id: { type: 'keyword' }, build_id: { type: 'keyword' }, component_id: { type: 'keyword' }, step_id: { type: 'keyword' }, inspection_type: { type: 'keyword' }, inspector_employee_id: { type: 'keyword' }, inspection_timestamp: { type: 'date' }, result: { type: 'keyword' }, remarks: { type: 'text' } } }. Document _id can be inspection_id. Consider parent\/child relationship with build_id for routing.\nIndex 'component_inventory'. Mapping: { properties: { inventory_record_id: { type: 'keyword' }, component_id: { type: 'keyword' }, quantity: { type: 'integer' }, location_warehouse: { type: 'keyword' }, location_bin: { type: 'keyword' }, received_date: { type: 'date' }, expiry_date: { type: 'date' }, batch_number: { type: 'keyword' }, last_updated: { type: 'date' } } }. Document _id can be inventory_record_id.\n","conversations":[{"role":"user","content":"I need to get the total quantity of components in inventory for a specific warehouse location. Can you help with that?"},{"role":"assistant","content":"SELECT location_warehouse, SUM(quantity) AS total_quantity\nFROM component_inventory\nWHERE location_warehouse = 'specific_warehouse'\nGROUP BY location_warehouse;"},{"role":"user","content":"Can you also include the component names for the inventory records in that warehouse?"},{"role":"assistant","content":"SELECT ci.location_warehouse, c.component_name, SUM(ci.quantity) AS total_quantity\nFROM component_inventory ci\nJOIN components c ON ci.component_id = c.component_id\nWHERE ci.location_warehouse = 'specific_warehouse'\nGROUP BY ci.location_warehouse, c.component_name;"},{"role":"user","content":"What if I want to filter out components with a total quantity less than 20?"},{"role":"assistant","content":"SELECT ci.location_warehouse, c.component_name, SUM(ci.quantity) AS total_quantity\nFROM component_inventory ci\nJOIN components c ON ci.component_id = c.component_id\nWHERE ci.location_warehouse = 'specific_warehouse'\nGROUP BY ci.location_warehouse, c.component_name\nHAVING SUM(ci.quantity) >= 20;"},{"role":"user","content":"Can you sort the results by total quantity in descending order?"},{"role":"assistant","content":"SELECT ci.location_warehouse, c.component_name, SUM(ci.quantity) AS total_quantity\nFROM component_inventory ci\nJOIN components c ON ci.component_id = c.component_id\nWHERE ci.location_warehouse = 'specific_warehouse'\nGROUP BY ci.location_warehouse, c.component_name\nHAVING SUM(ci.quantity) >= 20\nORDER BY total_quantity DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\nCREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )\n","conversations":[{"role":"user","content":"Show me the total number of trades and the sum of total_amount for each status in the trades table."},{"role":"assistant","content":"SELECT\n t.status,\n COUNT(t.trade_id) AS trade_count,\n SUM(t.total_amount) AS total_amount_by_status\nFROM financial_services.trades t\nGROUP BY t.status;"},{"role":"user","content":"Now, only include statuses where trade_count is greater than 100, and restrict to trades executed in the last 30 days."},{"role":"assistant","content":"SELECT\n t.status,\n COUNT(t.trade_id) AS trade_count,\n SUM(t.total_amount) AS total_amount_by_status\nFROM financial_services.trades t\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY t.status\nHAVING COUNT(t.trade_id) > 100;"},{"role":"user","content":"Exclude any statuses where the sum of commission is null or less than 1000."},{"role":"assistant","content":"SELECT\n t.status,\n COUNT(t.trade_id) AS trade_count,\n SUM(t.total_amount) AS total_amount_by_status,\n SUM(t.commission) AS total_commission\nFROM financial_services.trades t\nWHERE t.trade_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY t.status\nHAVING COUNT(t.trade_id) > 100\n AND SUM(t.commission) >= 1000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.metadata ( metadata_id character varying(64) NOT NULL, asset_id character varying(64) NOT NULL, key character varying(128) NOT NULL, value text NOT NULL, PRIMARY KEY (metadata_id) )\n","conversations":[{"role":"user","content":"I need to retrieve asset IDs along with their category and website metadata values for assets that have both entries."},{"role":"assistant","content":"SELECT m_cat.asset_id,\n m_cat.value AS category,\n m_web.value AS website_url\nFROM trading_platform.metadata m_cat\nJOIN trading_platform.metadata m_web\n ON m_cat.asset_id = m_web.asset_id\nWHERE m_cat.key = 'category'\n AND m_web.key = 'website';"},{"role":"user","content":"Actually, filter to include only those assets where the category value is 'defi'."},{"role":"assistant","content":"SELECT m_cat.asset_id,\n m_cat.value AS category,\n m_web.value AS website_url\nFROM trading_platform.metadata m_cat\nJOIN trading_platform.metadata m_web\n ON m_cat.asset_id = m_web.asset_id\nWHERE m_cat.key = 'category'\n AND m_web.key = 'website'\n AND m_cat.value = 'defi';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.hashtags ( hashtag_id character varying(64) NOT NULL, tag_name character varying(100) NOT NULL UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (hashtag_id) )\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\nCREATE TABLE social_media.notifications ( notification_id text PRIMARY KEY, recipient_user_id text, sender_user_id text, notification_type text, target_entity_id text, target_entity_type text, created_at timestamp, read_at timestamp )\nCREATE TABLE social_media.user_settings ( setting_id text, user_id text, theme text, email_notifications_enabled boolean, push_notifications_enabled boolean, private_profile boolean, updated_at timestamp )\n","conversations":[{"role":"user","content":"I need to get the most recent message each verified user has sent in any group chat, showing username, group_name, message_id, and sent_at."},{"role":"assistant","content":"WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nWHERE ur.rn = 1\n AND u.is_verified = true;"},{"role":"user","content":"Actually, I only want messages sent in the past 30 days."},{"role":"assistant","content":"WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n AND m.sent_at >= NOW() - INTERVAL '30 days'\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nWHERE ur.rn = 1\n AND u.is_verified = true;"},{"role":"user","content":"Also, exclude any users who have disabled push notifications."},{"role":"assistant","content":"WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n AND m.sent_at >= NOW() - INTERVAL '30 days'\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nJOIN social_media.user_settings s ON s.user_id = u.user_id\nWHERE ur.rn = 1\n AND u.is_verified = true\n AND s.push_notifications_enabled = true;"},{"role":"user","content":"And order the results by sent_at descending."},{"role":"assistant","content":"WITH user_recent AS (\n SELECT m.sender_user_id, m.message_id, m.conversation_id, m.sent_at,\n ROW_NUMBER() OVER (PARTITION BY m.sender_user_id ORDER BY m.sent_at DESC) AS rn\n FROM social_media.messages m\n JOIN social_media.conversations c ON m.conversation_id = c.conversation_id\n WHERE c.is_group_chat = true\n AND m.sent_at >= NOW() - INTERVAL '30 days'\n)\nSELECT u.username, c.group_name, ur.message_id, ur.sent_at\nFROM user_recent ur\nJOIN social_media.users u ON ur.sender_user_id = u.user_id\nJOIN social_media.conversations c ON ur.conversation_id = c.conversation_id\nJOIN social_media.user_settings s ON s.user_id = u.user_id\nWHERE ur.rn = 1\n AND u.is_verified = true\n AND s.push_notifications_enabled = true\nORDER BY ur.sent_at DESC;"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nNode Label ':AircraftModel'. Properties: { model_id: String (Constraint: UNIQUE), model_name: String, manufacturer: String, passenger_capacity: Integer, max_range_km: Integer, engine_type: String, wingspan_m: Float, status: String, first_flight_date: Date }. Index on model_id.\nNode Label ':Material'. Properties: { material_id: String (Constraint: UNIQUE), material_name: String, specification: String, description: String, density_kg_m3: Float, tensile_strength_mpa: Integer }. Index on material_id.\nNode Label ':AssemblyLine'. Properties: { line_id: String (Constraint: UNIQUE), line_name: String, location_building: String, location_area: String, capacity_units_per_month: Integer, status: String }. Relationship: (:AssemblyLine)-[:BUILDS_MODEL]->(:AircraftModel {model_id}). Index on line_id.\nNode Label ':AssemblyStep'. Properties: { step_id: String (Constraint: UNIQUE), step_number: Integer, step_name: String, description: String, standard_duration_hours: Float, required_skill_level: String, workstation: String }. Relationship: (:AssemblyLine {line_id})-[:HAS_STEP {sequence: }]->(:AssemblyStep). Index on step_id.\nNode Label ':AircraftBuild'. Properties: { build_id: String (Constraint: UNIQUE), serial_number: String (Constraint: UNIQUE), build_start_date: Datetime, estimated_completion_date: Date, actual_completion_date: Datetime, current_status: String, customer_order_id: String }. Relationships: (:AircraftBuild)-[:IS_MODEL]->(:AircraftModel {model_id}), (:AircraftBuild)-[:ASSEMBLED_ON]->(:AssemblyLine {line_id}). Index on build_id, serial_number, current_status.\nNode Label ':Employee'. Properties: { employee_id: String (Constraint: UNIQUE), first_name: String, last_name: String, job_title: String, skill_certifications: String[], hire_date: Date, employment_status: String }. Relationships: (:Employee)-[:ASSIGNED_TO]->(:AssemblyLine {line_id}), (:Employee)-[:REPORTS_TO]->(:Employee {employee_id as supervisor_id}). Index on employee_id.\nNode Label ':InventoryBatch'. Properties: { inventory_record_id: String (Constraint: UNIQUE), quantity: Integer, location_warehouse: String, location_bin: String, received_date: Datetime, expiry_date: Date, batch_number: String, last_updated: Datetime }. Relationship: (:InventoryBatch)-[:IS_INSTANCE_OF]->(:Component {component_id}). Index on inventory_record_id, component_id.\n","conversations":[{"role":"user","content":"Can you help me fetch the inventory details for components associated with a specific aircraft build, including the batch number, quantity, and warehouse location?"},{"role":"assistant","content":"MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"},{"role":"user","content":"Can you modify this to show only inventory batches received after a specific date, say June 1, 2023?"},{"role":"assistant","content":"MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01')\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"},{"role":"user","content":"What if I also want to exclude batches with quantities less than 10?"},{"role":"assistant","content":"MATCH (ab:AircraftBuild {build_id: 'specific_build_id'})-[:IS_MODEL]->(am:AircraftModel),\n(ib:InventoryBatch)-[:IS_INSTANCE_OF]->(c:Component)\nWHERE ib.received_date > datetime('2023-06-01') AND ib.quantity >= 10\nRETURN ib.inventory_record_id, ib.batch_number, ib.quantity, ib.location_warehouse"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.trips ( trip_id text PRIMARY KEY, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count int, cargo_manifest_id text )\nCREATE TABLE transportation.locations ( location_id text PRIMARY KEY, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text PRIMARY KEY, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading int, location_id text )\n","conversations":[{"role":"user","content":"For each route, list the route number, description, and the combined total maintenance cost for all vehicles that have ever operated on that route."},{"role":"assistant","content":"WITH VehicleTotalMaintenance AS ( SELECT vehicle_id, SUM(cost) AS total_cost FROM transportation.maintenance_logs GROUP BY vehicle_id ), RouteVehicles AS ( SELECT DISTINCT route_id, vehicle_id FROM transportation.trips ) SELECT R.route_number, R.description, SUM(VTM.total_cost) AS total_vehicle_maintenance_cost FROM transportation.routes AS R JOIN RouteVehicles AS RV ON R.route_id = RV.route_id JOIN VehicleTotalMaintenance AS VTM ON RV.vehicle_id = VTM.vehicle_id GROUP BY R.route_id, R.route_number, R.description;"},{"role":"user","content":"Refine this list to only show routes where the total combined vehicle maintenance cost exceeds 10000."},{"role":"assistant","content":"WITH VehicleTotalMaintenance AS ( SELECT vehicle_id, SUM(cost) AS total_cost FROM transportation.maintenance_logs GROUP BY vehicle_id ), RouteVehicles AS ( SELECT DISTINCT route_id, vehicle_id FROM transportation.trips ) SELECT R.route_number, R.description, SUM(VTM.total_cost) AS total_vehicle_maintenance_cost FROM transportation.routes AS R JOIN RouteVehicles AS RV ON R.route_id = RV.route_id JOIN VehicleTotalMaintenance AS VTM ON RV.vehicle_id = VTM.vehicle_id GROUP BY R.route_id, R.route_number, R.description HAVING SUM(VTM.total_cost) > 10000;"},{"role":"user","content":"For these routes with high maintenance costs, please also include the total number of completed trips associated with the route."},{"role":"assistant","content":"WITH VehicleTotalMaintenance AS ( SELECT vehicle_id, SUM(cost) AS total_cost FROM transportation.maintenance_logs GROUP BY vehicle_id ), RouteVehicles AS ( SELECT DISTINCT route_id, vehicle_id FROM transportation.trips ), RouteCompletedTrips AS ( SELECT route_id, COUNT(*) AS completed_trip_count FROM transportation.trips WHERE status = 'Completed' GROUP BY route_id ) SELECT R.route_number, R.description, SUM(VTM.total_cost) AS total_vehicle_maintenance_cost, RCT.completed_trip_count FROM transportation.routes AS R JOIN RouteVehicles AS RV ON R.route_id = RV.route_id JOIN VehicleTotalMaintenance AS VTM ON RV.vehicle_id = VTM.vehicle_id LEFT JOIN RouteCompletedTrips AS RCT ON R.route_id = RCT.route_id GROUP BY R.route_id, R.route_number, R.description, RCT.completed_trip_count HAVING SUM(VTM.total_cost) > 10000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE trading_platform.orders (\n order_id character varying(64) NOT NULL, -- unique identifier for the order\n user_id character varying(64) NOT NULL, -- identifier of the user placing the order\n wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)\n created_at timestamp NOT NULL, -- time when the order was created\n PRIMARY KEY (order_id)\n)\nCREATE TABLE trading_platform.assets (\n asset_id character varying(64) NOT NULL, -- unique identifier for the asset\n name character varying(128) NOT NULL, -- name of the asset\n symbol character varying(32) NOT NULL, -- symbol of the asset\n type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)\n PRIMARY KEY (asset_id)\n)\nCREATE TABLE trading_platform.utxos (\n utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO\n output_index integer NOT NULL, -- index of the output in the transaction\n address character varying(128) NOT NULL, -- address that can spend the UTXO\n amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO\n spent boolean NOT NULL, -- whether the UTXO has been spent\n PRIMARY KEY (utxo_id)\n)\nCREATE TABLE trading_platform.dapps (\n dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp\n name character varying(128) NOT NULL, -- name of the DApp\n description text NOT NULL, -- description of the DApp\n url character varying(256) NOT NULL, -- URL of the DApp\n PRIMARY KEY (dapp_id)\n)\nCREATE TABLE trading_platform.peers (\n peer_id character varying(64) NOT NULL, -- unique identifier for the peer\n ip_address character varying(15) NOT NULL, -- IP address of the peer\n port integer NOT NULL, -- port number of the peer\n last_seen timestamp NOT NULL, -- last time the peer was active\n PRIMARY KEY (peer_id)\n)\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\nCREATE TABLE trading_platform.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n user_id character varying(64) NOT NULL, -- identifier of the user receiving the notification\n message text NOT NULL, -- message of the notification\n sent_at timestamp NOT NULL, -- time when the notification was sent\n read_at timestamp, -- time when the notification was read\n PRIMARY KEY (notification_id)\n)\n","conversations":[{"role":"user","content":"Get each user's ID, the count of wallets they own, and the total amount of their unspent UTXOs across all wallets."},{"role":"assistant","content":"SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent\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.user_id;"},{"role":"user","content":"Only include users who have more than one wallet."},{"role":"assistant","content":"SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent\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.user_id\nHAVING COUNT(DISTINCT w.wallet_id) > 1;"},{"role":"user","content":"Also include the date of the earliest wallet created by each user."},{"role":"assistant","content":"SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent,\n MIN(w.created_at) AS first_wallet_date\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.user_id\nHAVING COUNT(DISTINCT w.wallet_id) > 1;"},{"role":"user","content":"Sort the results by total_unspent descending and limit to the top 10."},{"role":"assistant","content":"SELECT w.user_id,\n COUNT(DISTINCT w.wallet_id) AS wallet_count,\n COALESCE(SUM(u.amount), 0) AS total_unspent,\n MIN(w.created_at) AS first_wallet_date\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.user_id\nHAVING COUNT(DISTINCT w.wallet_id) > 1\nORDER BY total_unspent DESC\nLIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.posts (\n post_id character varying(64) NOT NULL, -- unique identifier for the post\n user_id character varying(64) NOT NULL, -- identifier of the user who created the post (FK to users.user_id)\n content text, -- textual content of the post\n media_url text, -- URL to attached media (image\/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of post creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last post edit\n visibility character varying(20) NOT NULL DEFAULT 'public', -- visibility ('public', 'friends', 'private')\n location_lat numeric(9,6), -- latitude of post location\n location_lon numeric(9,6), -- longitude of post location\n PRIMARY KEY (post_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.post_hashtags (\n post_hashtag_id character varying(64) NOT NULL, -- unique identifier for the post-hashtag link\n post_id character varying(64) NOT NULL, -- identifier of the post (FK to posts.post_id)\n hashtag_id character varying(64) NOT NULL, -- identifier of the hashtag (FK to hashtags.hashtag_id)\n PRIMARY KEY (post_hashtag_id),\n CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) -- prevent duplicate tags on a post\n)\nCREATE TABLE social_media.messages (\n message_id character varying(64) NOT NULL, -- unique identifier for the message\n conversation_id character varying(64) NOT NULL, -- identifier for the conversation thread (FK to conversations.conversation_id)\n sender_user_id character varying(64) NOT NULL, -- identifier of the sender (FK to users.user_id)\n content text, -- textual content of the message\n media_url text, -- URL to attached media (image\/video)\n media_type character varying(20), -- type of media ('image', 'video', null)\n sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when message was sent\n read_at timestamp, -- timestamp when message was read by recipient(s)\n PRIMARY KEY (message_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\n","conversations":[{"role":"user","content":"Show me all notifications that are related to posts created by users who have a verified profile. Include the notification type, the recipient username, and the post ID."},{"role":"assistant","content":"SELECT\n n.notification_type,\n u_recipient.username AS recipient_username,\n n.target_entity_id AS post_id\nFROM social_media.notifications AS n\nJOIN social_media.posts AS p\n ON n.target_entity_id = p.post_id\nJOIN social_media.users AS u_creator\n ON p.user_id = u_creator.user_id\nJOIN social_media.users AS u_recipient\n ON n.recipient_user_id = u_recipient.user_id\nWHERE\n n.target_entity_type = 'post' AND u_creator.is_verified = true;"},{"role":"user","content":"Actually, I only want to see notifications of type 'like' or 'comment'."},{"role":"assistant","content":"SELECT\n n.notification_type,\n u_recipient.username AS recipient_username,\n n.target_entity_id AS post_id\nFROM social_media.notifications AS n\nJOIN social_media.posts AS p\n ON n.target_entity_id = p.post_id\nJOIN social_media.users AS u_creator\n ON p.user_id = u_creator.user_id\nJOIN social_media.users AS u_recipient\n ON n.recipient_user_id = u_recipient.user_id\nWHERE\n n.target_entity_type = 'post' AND u_creator.is_verified = true AND n.notification_type IN ('like', 'comment');"},{"role":"user","content":"Can you also include the creation timestamp of the notification and order the results with the most recent notifications first?"},{"role":"assistant","content":"SELECT\n n.notification_type,\n u_recipient.username AS recipient_username,\n n.target_entity_id AS post_id,\n n.created_at AS notification_created_at\nFROM social_media.notifications AS n\nJOIN social_media.posts AS p\n ON n.target_entity_id = p.post_id\nJOIN social_media.users AS u_creator\n ON p.user_id = u_creator.user_id\nJOIN social_media.users AS u_recipient\n ON n.recipient_user_id = u_recipient.user_id\nWHERE\n n.target_entity_type = 'post' AND u_creator.is_verified = true AND n.notification_type IN ('like', 'comment')\nORDER BY\n n.created_at DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles (\n vehicle_id character varying(64) NOT NULL, -- unique identifier for the vehicle\n license_plate character varying(32) NOT NULL UNIQUE, -- vehicle license plate\n vin character varying(17) UNIQUE, -- vehicle identification number\n make character varying(64) NOT NULL, -- manufacturer of the vehicle\n model character varying(64) NOT NULL, -- model of the vehicle\n year integer NOT NULL, -- manufacturing year\n type character varying(32) NOT NULL, -- type of vehicle (e.g., Bus, Train, Truck, Car, Van)\n capacity integer, -- passenger or cargo capacity\n fuel_type character varying(32) NOT NULL, -- e.g., Diesel, Gasoline, Electric, Hydrogen\n status character varying(32) NOT NULL, -- e.g., Active, Maintenance, Decommissioned\n depot_id character varying(64), -- identifier of the home depot\/base\n acquisition_date date, -- date the vehicle was acquired\n PRIMARY KEY (vehicle_id)\n)\n","conversations":[{"role":"user","content":"For each vehicle, list its vehicle_id, license_plate, and any older vehicle of the same type (showing older_vehicle_id and older year)."},{"role":"assistant","content":"SELECT cur.vehicle_id,\n cur.license_plate,\n old.vehicle_id AS older_vehicle_id,\n old.year AS older_vehicle_year\nFROM transportation.vehicles cur\nJOIN transportation.vehicles old\n ON cur.type = old.type\n AND old.year < cur.year\nORDER BY cur.vehicle_id, old.year DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"Which wallets hold at least 100 units of any ERC1155 NFT, and what is the token ID and contract address of the NFT for each such holding?"},{"role":"assistant","content":"SELECT wallet_address, contract_address, token_id, amount\nFROM nft_holders\nWHERE contract_type = 'ERC1155' AND CAST(amount AS DECIMAL) >= 100;"},{"role":"user","content":"Can you show the symbol and name of each NFT contract by joining the token_metas table?"},{"role":"assistant","content":"SELECT nh.wallet_address, nh.contract_address, nh.token_id, nh.amount, tm.symbol, tm.name\nFROM nft_holders nh\nJOIN token_metas tm ON nh.contract_address = tm.contract_address\nWHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS DECIMAL) >= 100;"},{"role":"user","content":"Only include NFTs where the symbol starts with the letter 'B'."},{"role":"assistant","content":"SELECT nh.wallet_address, nh.contract_address, nh.token_id, nh.amount, tm.symbol, tm.name\nFROM nft_holders nh\nJOIN token_metas tm ON nh.contract_address = tm.contract_address\nWHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS DECIMAL) >= 100 AND tm.symbol LIKE 'B%';"},{"role":"user","content":"Order the results by amount descending and limit to the top 5."},{"role":"assistant","content":"SELECT nh.wallet_address, nh.contract_address, nh.token_id, nh.amount, tm.symbol, tm.name\nFROM nft_holders nh\nJOIN token_metas tm ON nh.contract_address = tm.contract_address\nWHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS DECIMAL) >= 100 AND tm.symbol LIKE 'B%'\nORDER BY CAST(nh.amount AS DECIMAL) DESC\nLIMIT 5;"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\n\/\/ Use Hashes for ticket details. Key format: ticket:\n\/\/ HSET ticket:tkt_1a2b ticket_id \"tkt_1a2b\" booking_id \"book_zyx\" car_id \"car_abc\" seat_number \"12A\" ... is_checked_in 0 ...\n\n\/\/ To link tickets to bookings (optional):\n\/\/ SADD booking:book_zyx:tickets ticket:tkt_1a2b\n\/\/ Use Hashes for maintenance record details. Key format: maintenance_record:\n\/\/ HSET maintenance_record:maint_rec_001 record_id \"maint_rec_001\" asset_id \"train_789\" asset_type \"Train\" ... status \"Completed\"\n\n\/\/ To link records to assets (optional):\n\/\/ SADD train:train_789:maintenance maintenance_record:maint_rec_001\n\/\/ SADD platform:plat_123:maintenance maintenance_record:maint_rec_002\n","conversations":[{"role":"user","content":"\u7279\u5b9a\u306e\u4e88\u7d04ID 'book_zyx' \u306b\u95a2\u9023\u3059\u308b\u3059\u3079\u3066\u306e\u30c1\u30b1\u30c3\u30c8\u306e\u8a73\u7d30\u3092\u53d6\u5f97\u3059\u308b\u306e\u3092\u624b\u4f1d\u3063\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f\u307e\u305f\u3001\u95a2\u9023\u3059\u308b\u8eca\u4e21\u60c5\u5831\u3082\u542b\u3081\u3066\u304f\u3060\u3055\u3044\u3002"},{"role":"assistant","content":"SMEMBERS booking:book_zyx:tickets\nHGETALL ticket:\nHGETALL car:"},{"role":"user","content":"\u30c1\u30a7\u30c3\u30af\u30a4\u30f3\u6e08\u307f\u306e\u30c1\u30b1\u30c3\u30c8\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3088\u3046\u306b\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3057\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f"},{"role":"assistant","content":"SMEMBERS booking:book_zyx:tickets\nHGET ticket: is_checked_in\nHGETALL ticket: (only if is_checked_in = 1)\nHGETALL car:"},{"role":"user","content":"\u5ea7\u5e2d\u756a\u53f7\u3082\u7d50\u679c\u306b\u542b\u3081\u3066\u3001\u5ea7\u5e2d\u756a\u53f7\u9806\u306b\u4e26\u3079\u66ff\u3048\u308b\u3053\u3068\u306f\u53ef\u80fd\u3067\u3059\u304b\uff1f"},{"role":"assistant","content":"SMEMBERS booking:book_zyx:tickets\nHGET ticket: is_checked_in\nHGETALL ticket: (only if is_checked_in = 1)\nHGETALL car:\n(Sort results by seat_number in ascending order)"},{"role":"user","content":"\u8eca\u4e21ID\u3054\u3068\u306b\u30c1\u30b1\u30c3\u30c8\u306e\u7dcf\u6570\u3092\u8ffd\u52a0\u3057\u3066\u3044\u305f\u3060\u3051\u307e\u3059\u304b\uff1f"},{"role":"assistant","content":"SMEMBERS booking:book_zyx:tickets\nHGET ticket: is_checked_in\nHGETALL ticket: (only if is_checked_in = 1)\nHGETALL car:\n(Group by car_id and count total tickets per car_id)\n(Sort results by seat_number in ascending order)"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"List all ERC20 tokens where the price is greater than $10, including their names, symbols, and contract addresses."},{"role":"assistant","content":"SELECT tm.name, tm.symbol, tm.contract_address FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tpl.price > 10 AND tm.is_erc20 = 1;"},{"role":"user","content":"I think there's an error in your query - it should be 'tpl.price > 10' not 'tpl.price > 10'. Also, can you add the current price to the results?"},{"role":"assistant","content":"SELECT tm.name, tm.symbol, tm.contract_address, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tpl.price > 10 AND tm.is_erc20 = 1;"},{"role":"user","content":"Now sort these results by price in descending order and limit to the top 10."},{"role":"assistant","content":"SELECT tm.name, tm.symbol, tm.contract_address, tpl.price FROM token_metas tm JOIN token_prices_latest tpl ON tm.contract_address = tpl.address WHERE tpl.price > 10 AND tm.is_erc20 = 1 ORDER BY tpl.price DESC LIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\n","conversations":[{"role":"user","content":"Which chain has the highest total trading volume in the last 24 hours, and what is the top token by volume on that chain?"},{"role":"assistant","content":"WITH chain_volume AS (SELECT chain, SUM(volume_24h) AS total_volume_24h FROM token_dexpool_info GROUP BY chain), top_chain AS (SELECT chain FROM chain_volume ORDER BY total_volume_24h DESC LIMIT 1), top_token AS (SELECT token_symbol, volume_24h FROM token_dexpool_info WHERE chain = (SELECT chain FROM top_chain) ORDER BY volume_24h DESC LIMIT 1) SELECT c.chain, c.total_volume_24h, t.token_symbol, t.volume_24h AS top_token_volume FROM chain_volume c JOIN top_chain tc ON c.chain = tc.chain JOIN top_token t ON TRUE;"},{"role":"user","content":"Can you show the top 3 tokens by trading volume for that chain as well, including their price?"},{"role":"assistant","content":"WITH top_chain AS (SELECT chain FROM token_dexpool_info GROUP BY chain ORDER BY SUM(volume_24h) DESC LIMIT 1) SELECT token_symbol, price, volume_24h FROM token_dexpool_info WHERE chain = (SELECT chain FROM top_chain) ORDER BY volume_24h DESC LIMIT 3;"},{"role":"user","content":"Actually, please include the market cap for each of those top 3 tokens."},{"role":"assistant","content":"WITH top_chain AS (SELECT chain FROM token_dexpool_info GROUP BY chain ORDER BY SUM(volume_24h) DESC LIMIT 1) SELECT token_symbol, price, volume_24h, market_cap FROM token_dexpool_info WHERE chain = (SELECT chain FROM top_chain) ORDER BY volume_24h DESC LIMIT 3;"},{"role":"user","content":"I only want tokens where the market cap is above 100 million. Show those top 3 tokens by volume for the chain."},{"role":"assistant","content":"WITH top_chain AS (SELECT chain FROM token_dexpool_info GROUP BY chain ORDER BY SUM(volume_24h) DESC LIMIT 1) SELECT token_symbol, price, volume_24h, market_cap FROM token_dexpool_info WHERE chain = (SELECT chain FROM top_chain) AND market_cap > 100000000 ORDER BY volume_24h DESC LIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text PRIMARY KEY, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions ( transaction_id text PRIMARY KEY, account_id text, related_account_id text, transaction_type text, amount numeric, currency text, transaction_date timestamp, effective_date date, description text, status text, reference_number text )\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data ( data_point_id bigserial PRIMARY KEY, security_id text, data_timestamp timestamp, open_price numeric, high_price numeric, low_price numeric, close_price numeric, adjusted_close_price numeric, volume bigint, source text )\nCREATE TABLE financial_services.employees ( employee_id text PRIMARY KEY, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n","conversations":[{"role":"user","content":"Show the number of employees in each department."},{"role":"assistant","content":"SELECT department, COUNT(*) AS employee_count\nFROM financial_services.employees\ngroup BY department;"},{"role":"user","content":"Exclude departments that have less than 3 employees."},{"role":"assistant","content":"SELECT department, COUNT(*) AS employee_count\nFROM financial_services.employees\ngroup BY department\nHAVING COUNT(*) >= 3;"},{"role":"user","content":"Can you also show the average hire_date for employees in each department?"},{"role":"assistant","content":"SELECT department, COUNT(*) AS employee_count, AVG(hire_date) AS average_hire_date\nFROM financial_services.employees\ngroup BY department\nHAVING COUNT(*) >= 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp chain character varying(128) NOT NULL, -- the chain that the token resides address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX exchange character varying(512) NOT NULL, -- a centralized exchange name token_address character varying(128) NOT NULL, -- token contract address token_symbol character varying(512), --token symbol balance numeric(38,10), -- token balance usd_value numeric(38,14), -- value of the token held in USD price double precision, --price of the token in USD ,PRIMARY KEY (snapshot_time, exchange, address, chain, token_address) )\n","conversations":[{"role":"user","content":"Show me projects that raised funds in 2022 and have a corresponding token held by CEXes on the 'Ethereum' chain. Display the project name, fundraising round name, investment value, the associated token symbol, and the total USD value of that token held by CEXes on Ethereum."},{"role":"assistant","content":"SELECT pfr.project_name, pfr.rounds_name, pfr.investment_value, ctb.token_symbol, SUM(ctb.usd_value) AS total_ethereum_cex_usd_value FROM project_fundraising_record AS pfr JOIN cex_token_balance AS ctb ON LOWER(pfr.project_name) LIKE '%' || LOWER(ctb.token_symbol) || '%' OR LOWER(ctb.token_symbol) LIKE '%' || LOWER(pfr.project_name) || '%' WHERE pfr.investment_date LIKE '2022%' AND ctb.chain = 'Ethereum' GROUP BY pfr.project_name, pfr.rounds_name, pfr.investment_value, ctb.token_symbol;"},{"role":"user","content":"Refine the results to only include projects where the fundraising investment value is greater than $1,000,000."},{"role":"assistant","content":"SELECT pfr.project_name, pfr.rounds_name, pfr.investment_value, ctb.token_symbol, SUM(ctb.usd_value) AS total_ethereum_cex_usd_value FROM project_fundraising_record AS pfr JOIN cex_token_balance AS ctb ON LOWER(pfr.project_name) LIKE '%' || LOWER(ctb.token_symbol) || '%' OR LOWER(ctb.token_symbol) LIKE '%' || LOWER(pfr.project_name) || '%' WHERE pfr.investment_date LIKE '2022%' AND ctb.chain = 'Ethereum' AND pfr.investment_value > 1000000 GROUP BY pfr.project_name, pfr.rounds_name, pfr.investment_value, ctb.token_symbol;"},{"role":"user","content":"Order the results by total USD value held by CEXes in descending order and show the top 5."},{"role":"assistant","content":"SELECT pfr.project_name, pfr.rounds_name, pfr.investment_value, ctb.token_symbol, SUM(ctb.usd_value) AS total_ethereum_cex_usd_value FROM project_fundraising_record AS pfr JOIN cex_token_balance AS ctb ON LOWER(pfr.project_name) LIKE '%' || LOWER(ctb.token_symbol) || '%' OR LOWER(ctb.token_symbol) LIKE '%' || LOWER(pfr.project_name) || '%' WHERE pfr.investment_date LIKE '2022%' AND ctb.chain = 'Ethereum' AND pfr.investment_value > 1000000 GROUP BY pfr.project_name, pfr.rounds_name, pfr.investment_value, ctb.token_symbol ORDER BY total_ethereum_cex_usd_value DESC LIMIT 5;"},{"role":"user","content":"Include the project's valuation from the fundraising record in the output."},{"role":"assistant","content":"SELECT pfr.project_name, pfr.rounds_name, pfr.investment_value, pfr.valuation, ctb.token_symbol, SUM(ctb.usd_value) AS total_ethereum_cex_usd_value FROM project_fundraising_record AS pfr JOIN cex_token_balance AS ctb ON LOWER(pfr.project_name) LIKE '%' || LOWER(ctb.token_symbol) || '%' OR LOWER(ctb.token_symbol) LIKE '%' || LOWER(pfr.project_name) || '%' WHERE pfr.investment_date LIKE '2022%' AND ctb.chain = 'Ethereum' AND pfr.investment_value > 1000000 GROUP BY pfr.project_name, pfr.rounds_name, pfr.investment_value, pfr.valuation, ctb.token_symbol ORDER BY total_ethereum_cex_usd_value DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n","conversations":[{"role":"user","content":"Show all active customers who live in the same zip_code."},{"role":"assistant","content":"SELECT a.customer_id AS cust1,\n b.customer_id AS cust2,\n a.zip_code\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.zip_code = b.zip_code\n AND a.customer_id < b.customer_id\nWHERE a.status = 'Active'\n AND b.status = 'Active';"},{"role":"user","content":"Please ensure we don't list duplicate pairs and order by zip_code and cust1."},{"role":"assistant","content":"SELECT a.customer_id AS cust1,\n b.customer_id AS cust2,\n a.zip_code\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.zip_code = b.zip_code\n AND a.customer_id < b.customer_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\nORDER BY a.zip_code, a.customer_id;"},{"role":"user","content":"Include the city and state in the result as well."},{"role":"assistant","content":"SELECT a.customer_id AS cust1,\n b.customer_id AS cust2,\n a.zip_code,\n a.city,\n a.state\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.zip_code = b.zip_code\n AND a.customer_id < b.customer_id\nWHERE a.status = 'Active'\n AND b.status = 'Active'\nORDER BY a.zip_code, a.customer_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.posts ( post_id text PRIMARY KEY, user_id text, content text, media_url text, media_type text, created_at timestamp, updated_at timestamp, visibility text, location_lat numeric, location_lon numeric )\nCREATE TABLE social_media.user_settings ( setting_id text PRIMARY KEY, user_id text, theme text, email_notifications_enabled bool, push_notifications_enabled bool, private_profile bool, updated_at timestamp )\n","conversations":[{"role":"user","content":"List all user IDs and the number of posts each has made where the post includes a media file (media_url is not null), along with whether their profile is private."},{"role":"assistant","content":"SELECT p.user_id, COUNT(*) AS media_post_count, us.private_profile\nFROM social_media.posts p\nJOIN social_media.user_settings us ON p.user_id = us.user_id\nWHERE p.media_url IS NOT NULL\nGROUP BY p.user_id, us.private_profile;"},{"role":"user","content":"Show only users with at least 3 such posts and order by media_post_count descending."},{"role":"assistant","content":"SELECT p.user_id, COUNT(*) AS media_post_count, us.private_profile\nFROM social_media.posts p\nJOIN social_media.user_settings us ON p.user_id = us.user_id\nWHERE p.media_url IS NOT NULL\nGROUP BY p.user_id, us.private_profile\nHAVING COUNT(*) >= 3\nORDER BY media_post_count DESC;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.maintenance_records ( record_id text PRIMARY KEY, asset_id text, asset_type text, maintenance_type text, staff_id text, start_datetime timestamp, end_datetime timestamp, description text, cost numeric, status text )\n","conversations":[{"role":"user","content":"What are the specific tools or equipment used during the maintenance with record_id 'REC456'?"},{"role":"assistant","content":"I'm sorry, but I can't provide information about the specific tools or equipment used during a maintenance record. The data in the maintenance_records table does not include details about tools or equipment used."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.notifications ( notification_id.text, user_id.text, message.text, sent_at.timestamp, read_at.timestamp )\n","conversations":[{"role":"user","content":"For each user, show their username and the timestamp of their most recent notification. Include users who have never received notifications."},{"role":"assistant","content":"SELECT T1.username, max(T2.sent_at) FROM users AS T1 LEFT JOIN trading_platform.notifications AS T2 ON T1.user_id = T2.user_id GROUP BY T1.username"},{"role":"user","content":"Could you also include the total number of notifications for each user?"},{"role":"assistant","content":"SELECT T1.username, count(T2.notification_id), max(T2.sent_at) FROM users AS T1 LEFT JOIN trading_platform.notifications AS T2 ON T1.user_id = T2.user_id GROUP BY T1.username"},{"role":"user","content":"Actually, only show users whose latest notification is unread."},{"role":"assistant","content":"WITH LatestNotification AS ( SELECT user_id, sent_at, read_at, ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY sent_at DESC) AS rn FROM trading_platform.notifications ) SELECT T1.username, T2.sent_at FROM users AS T1 JOIN LatestNotification AS T2 ON T1.user_id = T2.user_id WHERE T2.rn = 1 AND T2.read_at IS NULL"},{"role":"user","content":"Also, include the count of unread notifications for these users."},{"role":"assistant","content":"WITH LatestNotification AS ( SELECT user_id, sent_at, read_at, ROW_NUMBER() OVER(PARTITION BY user_id ORDER BY sent_at DESC) AS rn FROM trading_platform.notifications ) SELECT T1.username, count(CASE WHEN T3.read_at IS NULL THEN T3.notification_id ELSE NULL END), T2.sent_at FROM users AS T1 JOIN LatestNotification AS T2 ON T1.user_id = T2.user_id AND T2.rn = 1 AND T2.read_at IS NULL JOIN trading_platform.notifications AS T3 ON T1.user_id = T3.user_id GROUP BY T1.username, T2.sent_at"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_metadata (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n token_id varchar NOT NULL, -- The number of the token\n contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n amount bigint NOT NULL, -- amount fields for the functionType in contract\n minter varchar NOT NULL, -- minter fields for the functionType in contract\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract\n mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract\n mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract\n mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract\n token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract\n metadata varchar NOT NULL, -- metadata fields for the functionType in contract\n name varchar NOT NULL, -- name fields for the functionType in contract\n image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n status varchar NOT NULL, -- status fields for the functionType in contract\n rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract\n rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract\n unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(mint_time \/ 1000 \/ 86400 \/ 30))\n)\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"Show me wallet addresses that hold more than 1000 of any ERC1155 token, along with the token ID and contract address."},{"role":"assistant","content":"SELECT wallet_address, token_id, contract_address FROM erc20_balances WHERE CAST(amount AS decimal) > 1000;"},{"role":"user","content":"I think there's an error in your query - it should be using the nft_metadata table for ERC1155 tokens. Also, can you include the token name from the nft_metadata table?"},{"role":"assistant","content":"SELECT nm.owner as wallet_address, nm.token_id, nm.contract_address, nm.name FROM nft_metadata nm WHERE nm.erc_type = 'ERC1155' AND CAST(nm.amount AS decimal) > 1000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_collections (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n name varchar NOT NULL, -- name fields for the functionType in contract\n symbol varchar NOT NULL, -- symbol fields for the functionType in contract\n deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract\n deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n description varchar NOT NULL, -- description fields for the functionType in contract\n slug varchar NOT NULL, -- slug fields for the functionType in contract\n media_info varchar NOT NULL, -- media_info fields for the functionType in contract\n image_url varchar NOT NULL, -- image_url fields for the functionType in contract\n banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n banner varchar NOT NULL, -- banner fields for the functionType in contract\n token_count bigint NOT NULL, -- token_count fields for the functionType in contract\n floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract\n floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract\n floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time \/ 1000 \/ 86400 \/ 30))\n)\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"For each NFT collection deployed on Ethereum, count the number of distinct wallets that have ever held any token from that collection."},{"role":"assistant","content":"SELECT\n nc.contract_address,\n nc.name,\n COUNT(DISTINCT nh.wallet_address) AS holder_count\nFROM nft_collections nc\nJOIN nft_holder_historical nh\n ON nc.contract_address = nh.contract_address\nWHERE nc.blockchain = 'Ethereum'\nGROUP BY nc.contract_address, nc.name;"},{"role":"user","content":"Include each collection's token_count and floor_price from nft_collections."},{"role":"assistant","content":"SELECT\n nc.contract_address,\n nc.name,\n nc.token_count,\n nc.floor_price,\n COUNT(DISTINCT nh.wallet_address) AS holder_count\nFROM nft_collections nc\nJOIN nft_holder_historical nh\n ON nc.contract_address = nh.contract_address\nWHERE nc.blockchain = 'Ethereum'\nGROUP BY\n nc.contract_address,\n nc.name,\n nc.token_count,\n nc.floor_price;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.utxos (\n utxo_id character varying(64) NOT NULL, -- unique identifier for the UTXO\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that created the UTXO\n output_index integer NOT NULL, -- index of the output in the transaction\n address character varying(128) NOT NULL, -- address that can spend the UTXO\n amount numeric(38,14) NOT NULL, -- amount of the asset in the UTXO\n spent boolean NOT NULL, -- whether the UTXO has been spent\n PRIMARY KEY (utxo_id)\n)\n","conversations":[{"role":"user","content":"For each address, show the total amount contained in UTXOs that have been spent."},{"role":"assistant","content":"SELECT address, SUM(amount) FROM utxos WHERE spent = TRUE GROUP BY address;"},{"role":"user","content":"Only include addresses where this total spent amount is greater than 500 and order the results by the total amount descending."},{"role":"assistant","content":"SELECT address, SUM(amount) FROM utxos WHERE spent = TRUE GROUP BY address HAVING SUM(amount) > 500 ORDER BY SUM(amount) DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )\n","conversations":[{"role":"user","content":"Show me the top 3 tokens by 24-hour trading volume in the 'NFT' narrative, along with their price and market cap."},{"role":"assistant","content":"SELECT token_name, token_symbol, total_volume, price, market_cap FROM token_basic_info WHERE narrative = 'NFT' ORDER BY CAST(total_volume AS double precision) DESC LIMIT 3;"},{"role":"user","content":"Can you also include their 7-day price change percentage and filter for tokens with a market cap over $100 million?"},{"role":"assistant","content":"SELECT token_name, token_symbol, total_volume, price, market_cap, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' AND market_cap > 100000000 ORDER BY CAST(total_volume AS double precision) DESC LIMIT 3;"},{"role":"user","content":"Actually, I want to see tokens with positive 7-day price changes and order by market cap instead."},{"role":"assistant","content":"SELECT token_name, token_symbol, total_volume, price, market_cap, price_change_percentage_7d FROM token_basic_info WHERE narrative = 'NFT' AND market_cap > 100000000 AND price_change_percentage_7d > 0 ORDER BY market_cap DESC LIMIT 3;"},{"role":"user","content":"Now include their highest and lowest prices in the last 24 hours as well."},{"role":"assistant","content":"SELECT token_name, token_symbol, total_volume, price, market_cap, price_change_percentage_7d, highest_price_24h, lowest_price_24h FROM token_basic_info WHERE narrative = 'NFT' AND market_cap > 100000000 AND price_change_percentage_7d > 0 ORDER BY market_cap DESC LIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_activities ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar NOT NULL, tick varchar NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )\n","conversations":[{"role":"user","content":"For all NFT collections on the Ethereum blockchain, show me the collection name and the current floor price. Sort by floor price descending."},{"role":"assistant","content":"SELECT name, floor_price FROM nft_collections WHERE blockchain = 'Ethereum' ORDER BY CAST(floor_price AS FLOAT) DESC;"},{"role":"user","content":"Include also the collection symbol and the number of tokens in each collection."},{"role":"assistant","content":"SELECT name, symbol, floor_price, token_count FROM nft_collections WHERE blockchain = 'Ethereum' ORDER BY CAST(floor_price AS FLOAT) DESC;"},{"role":"user","content":"Can you also show the owner of each collection in the result?"},{"role":"assistant","content":"SELECT name, symbol, floor_price, token_count, owner FROM nft_collections WHERE blockchain = 'Ethereum' ORDER BY CAST(floor_price AS FLOAT) DESC;"},{"role":"user","content":"Now only include collections whose floor price is greater than 1 ETH."},{"role":"assistant","content":"SELECT name, symbol, floor_price, token_count, owner FROM nft_collections WHERE blockchain = 'Ethereum' AND CAST(floor_price AS FLOAT) > 1 AND floor_price_symbol = 'ETH' ORDER BY CAST(floor_price AS FLOAT) DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\n","conversations":[{"role":"user","content":"What is the average number of wallets each user owns?"},{"role":"assistant","content":"SELECT\n AVG(wallet_count) AS avg_wallets_per_user\nFROM (\n SELECT user_id, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY user_id\n) AS sub;"},{"role":"user","content":"Actually, calculate the average only for users who own more than one wallet."},{"role":"assistant","content":"SELECT\n AVG(wallet_count) AS avg_wallets_per_user\nFROM (\n SELECT user_id, COUNT(*) AS wallet_count\n FROM web3.wallets\n GROUP BY user_id\n HAVING COUNT(*) > 1\n) AS sub;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )\n","conversations":[{"role":"user","content":"Can you give me the list of server names and their regions, along with the total number of players currently online in each region?"},{"role":"assistant","content":"SELECT region, SUM(current_players) AS total_current_players, STRING_AGG(server_name, ', ') AS server_names\nFROM gaming_technology.servers\nWHERE status = 'online'\nGROUP BY region;"},{"role":"user","content":"I want to include the count of servers in each region as well. Can you modify the query?"},{"role":"assistant","content":"SELECT region, COUNT(server_id) AS server_count, SUM(current_players) AS total_current_players, STRING_AGG(server_name, ', ') AS server_names\nFROM gaming_technology.servers\nWHERE status = 'online'\nGROUP BY region;"},{"role":"user","content":"Add only those regions where the server count is more than 2."},{"role":"assistant","content":"SELECT region, COUNT(server_id) AS server_count, SUM(current_players) AS total_current_players, STRING_AGG(server_name, ', ') AS server_names\nFROM gaming_technology.servers\nWHERE status = 'online'\nGROUP BY region\nHAVING COUNT(server_id) > 2;"},{"role":"user","content":"Can you also sort the results by total_current_players in descending order?"},{"role":"assistant","content":"SELECT region, COUNT(server_id) AS server_count, SUM(current_players) AS total_current_players, STRING_AGG(server_name, ', ') AS server_names\nFROM gaming_technology.servers\nWHERE status = 'online'\nGROUP BY region\nHAVING COUNT(server_id) > 2\nORDER BY total_current_players DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"Show me all ERC20 token transfers where the amount is over 5000, including the sender and receiver addresses."},{"role":"assistant","content":"SELECT from_address, to_address, amt, tick, tx_hash FROM token_activities WHERE type = 'transfer' AND CAST(amt AS DECIMAL) > 5000;"},{"role":"user","content":"Add the token symbol and decimals for each transfer by joining to the latest token price table."},{"role":"assistant","content":"SELECT ta.from_address, ta.to_address, ta.amt, ta.tick, ta.tx_hash, tpl.symbol, tpl.decimals FROM token_activities ta JOIN token_prices_latest tpl ON ta.tick = tpl.symbol WHERE ta.type = 'transfer' AND CAST(ta.amt AS DECIMAL) > 5000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata ( object_id varchar NOT NULL, coin_type varchar NOT NULL, status varchar NOT NULL, decimals bigint NOT NULL, description varchar NOT NULL, icon_url varchar NOT NULL, symbol varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_balances ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone ( address varchar NOT NULL, table_id varchar NOT NULL, key_bytes varchar NOT NULL, key0 varchar NOT NULL, key1 varchar NOT NULL, static_data varchar NOT NULL, encoded_lengths varchar NOT NULL, dynamic_data varchar NOT NULL, is_deleted boolean NOT NULL, block_number bigint NOT NULL, log_index bigint NOT NULL )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )\n","conversations":[{"role":"user","content":"List all NFTs minted on the Ethereum blockchain in the last 14 days, including their contract address, token ID, name, and minter."},{"role":"assistant","content":"SELECT contract_address, token_id, name, minter\nFROM nft_metadata\nWHERE blockchain = 'Ethereum' AND mint_time >= (extract(epoch FROM now()) - 14*24*60*60);"},{"role":"user","content":"Show also the collection name for each NFT by joining with the nft_collections table."},{"role":"assistant","content":"SELECT nm.contract_address, nm.token_id, nm.name, nm.minter, nc.name AS collection_name\nFROM nft_metadata nm\nJOIN nft_collections nc ON nm.blockchain = nc.blockchain AND nm.contract_address = nc.contract_address\nWHERE nm.blockchain = 'Ethereum' AND nm.mint_time >= (extract(epoch FROM now()) - 14*24*60*60);"},{"role":"user","content":"I only want NFTs where the rarity_score is above 80, and order the results by rarity_score descending."},{"role":"assistant","content":"SELECT nm.contract_address, nm.token_id, nm.name, nm.minter, nc.name AS collection_name, nm.rarity_score\nFROM nft_metadata nm\nJOIN nft_collections nc ON nm.blockchain = nc.blockchain AND nm.contract_address = nc.contract_address\nWHERE nm.blockchain = 'Ethereum' AND nm.mint_time >= (extract(epoch FROM now()) - 14*24*60*60)\n AND nm.rarity_score > 80\nORDER BY nm.rarity_score DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(50) NOT NULL UNIQUE, -- user's unique handle\n email character varying(128) NOT NULL UNIQUE, -- user's email address\n password_hash text NOT NULL, -- hashed password\n full_name character varying(100), -- user's full name\n profile_picture_url text, -- URL to the profile picture\n bio text, -- short user biography\n location character varying(100), -- user's location\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of account creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last profile update\n is_verified boolean NOT NULL DEFAULT false, -- verification status\n PRIMARY KEY (user_id)\n)\nCREATE TABLE social_media.comments (\n comment_id character varying(64) NOT NULL, -- unique identifier for the comment\n post_id character varying(64) NOT NULL, -- identifier of the post being commented on (FK to posts.post_id)\n user_id character varying(64) NOT NULL, -- identifier of the user who made the comment (FK to users.user_id)\n parent_comment_id character varying(64), -- identifier of the parent comment if it's a reply (FK to comments.comment_id)\n content text NOT NULL, -- textual content of the comment\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of comment creation\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last comment edit\n PRIMARY KEY (comment_id)\n)\nCREATE TABLE social_media.likes (\n like_id character varying(64) NOT NULL, -- unique identifier for the like\n user_id character varying(64) NOT NULL, -- identifier of the user who liked (FK to users.user_id)\n post_id character varying(64), -- identifier of the post being liked (FK to posts.post_id, nullable)\n comment_id character varying(64), -- identifier of the comment being liked (FK to comments.comment_id, nullable)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the like occurred\n PRIMARY KEY (like_id),\n CONSTRAINT unique_user_like UNIQUE (user_id, post_id, comment_id), -- prevent duplicate likes\n CONSTRAINT check_like_target CHECK (post_id IS NOT NULL OR comment_id IS NOT NULL) -- ensure it likes something\n)\nCREATE TABLE social_media.follows (\n follow_id character varying(64) NOT NULL, -- unique identifier for the follow relationship\n follower_user_id character varying(64) NOT NULL, -- identifier of the user who is following (FK to users.user_id)\n following_user_id character varying(64) NOT NULL, -- identifier of the user being followed (FK to users.user_id)\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of when the follow started\n PRIMARY KEY (follow_id),\n CONSTRAINT unique_follow UNIQUE (follower_user_id, following_user_id) -- prevent duplicate follows\n)\nCREATE TABLE social_media.hashtags (\n hashtag_id character varying(64) NOT NULL, -- unique identifier for the hashtag\n tag_name character varying(100) NOT NULL UNIQUE, -- the actual hashtag text (without '#')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when the hashtag was first used\n PRIMARY KEY (hashtag_id)\n)\nCREATE TABLE social_media.conversations (\n conversation_id character varying(64) NOT NULL, -- unique identifier for the conversation\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when conversation was initiated\n last_message_at timestamp, -- timestamp of the last message in the conversation\n is_group_chat boolean NOT NULL DEFAULT false, -- indicates if it's a group chat or direct message\n group_name character varying(100), -- name of the group chat (if applicable)\n PRIMARY KEY (conversation_id)\n)\nCREATE TABLE social_media.conversation_participants (\n participant_id character varying(64) NOT NULL, -- unique identifier for the participant entry\n conversation_id character varying(64) NOT NULL, -- identifier of the conversation (FK to conversations.conversation_id)\n user_id character varying(64) NOT NULL, -- identifier of the user in the conversation (FK to users.user_id)\n joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp when user joined the conversation\n last_read_at timestamp, -- timestamp indicating up to when the user has read messages\n PRIMARY KEY (participant_id),\n CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) -- prevent user being added multiple times\n)\nCREATE TABLE social_media.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n recipient_user_id character varying(64) NOT NULL, -- user receiving the notification (FK to users.user_id)\n sender_user_id character varying(64), -- user triggering the notification (FK to users.user_id, can be null for system notifications)\n notification_type character varying(30) NOT NULL, -- type of notification ('like', 'comment', 'follow', 'mention', 'message')\n target_entity_id character varying(64), -- ID of the related entity (post_id, comment_id, user_id, conversation_id)\n target_entity_type character varying(20), -- type of the related entity ('post', 'comment', 'user', 'conversation')\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp notification was created\n read_at timestamp, -- timestamp notification was marked as read\n PRIMARY KEY (notification_id)\n)\nCREATE TABLE social_media.user_settings (\n setting_id character varying(64) NOT NULL, -- unique identifier for the setting entry\n user_id character varying(64) NOT NULL UNIQUE, -- user the settings belong to (FK to users.user_id)\n theme character varying(20) DEFAULT 'light', -- UI theme ('light', 'dark')\n email_notifications_enabled boolean DEFAULT true, -- enable\/disable email notifications\n push_notifications_enabled boolean DEFAULT true, -- enable\/disable push notifications\n private_profile boolean DEFAULT false, -- is the user profile private\n updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last setting change\n PRIMARY KEY (setting_id)\n)\n","conversations":[{"role":"user","content":"Show all users who have liked comments made by users with a specified location, say 'Paris'. For each, show their username, the comment_id, and the location of the comment's author."},{"role":"assistant","content":"SELECT l.user_id AS liker_user_id, u_liker.username, l.comment_id, u_author.location AS comment_author_location\nFROM social_media.likes l\nJOIN social_media.comments c ON l.comment_id = c.comment_id\nJOIN social_media.users u_author ON c.user_id = u_author.user_id\nJOIN social_media.users u_liker ON l.user_id = u_liker.user_id\nWHERE u_author.location = 'Paris';"},{"role":"user","content":"Actually, please also include the full name of the user who made the comment, and restrict to likes created after April 1, 2024."},{"role":"assistant","content":"SELECT l.user_id AS liker_user_id, u_liker.username, l.comment_id, u_author.location AS comment_author_location, u_author.full_name AS comment_author_full_name\nFROM social_media.likes l\nJOIN social_media.comments c ON l.comment_id = c.comment_id\nJOIN social_media.users u_author ON c.user_id = u_author.user_id\nJOIN social_media.users u_liker ON l.user_id = u_liker.user_id\nWHERE u_author.location = 'Paris' AND l.created_at >= '2024-04-01';"},{"role":"user","content":"I see duplicate users for the same comment. Show only unique username-comment_id pairs, and order the results by liker username ascending."},{"role":"assistant","content":"SELECT DISTINCT u_liker.username, l.comment_id, u_author.location AS comment_author_location, u_author.full_name AS comment_author_full_name\nFROM social_media.likes l\nJOIN social_media.comments c ON l.comment_id = c.comment_id\nJOIN social_media.users u_author ON c.user_id = u_author.user_id\nJOIN social_media.users u_liker ON l.user_id = u_liker.user_id\nWHERE u_author.location = 'Paris' AND l.created_at >= '2024-04-01'\nORDER BY u_liker.username ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n token_id varchar NOT NULL, -- The number of the token\n contract_name varchar NOT NULL, -- contract_name fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n amount bigint NOT NULL, -- amount fields for the functionType in contract\n minter varchar NOT NULL, -- minter fields for the functionType in contract\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n mint_block_number bigint NOT NULL, -- mint_block_number fields for the functionType in contract\n mint_time bigint NOT NULL, -- mint_time fields for the functionType in contract\n mint_transaction_hash varchar NOT NULL, -- mint_transaction_hash fields for the functionType in contract\n mint_price varchar NOT NULL, -- mint_price fields for the functionType in contract\n token_uri varchar NOT NULL, -- token_uri fields for the functionType in contract\n metadata varchar NOT NULL, -- metadata fields for the functionType in contract\n name varchar NOT NULL, -- name fields for the functionType in contract\n image_uri varchar NOT NULL, -- image_uri fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n status varchar NOT NULL, -- status fields for the functionType in contract\n rarity_score real NOT NULL, -- rarity_score fields for the functionType in contract\n rarity_rank integer NOT NULL, -- rarity_rank fields for the functionType in contract\n unique_attribute_count integer NOT NULL, -- unique_attribute_count fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(mint_time \/ 1000 \/ 86400 \/ 30))\n)\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"Show me wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount, sorted by amount in descending order."},{"role":"assistant","content":"SELECT b.wallet_address, t.symbol, b.amount FROM erc20_balances b JOIN sui_coins_metadata t ON b.contract_address = t.coin_type WHERE CAST(b.amount AS decimal) > 1000 ORDER BY CAST(b.amount AS decimal) DESC;"},{"role":"user","content":"Can you also include the current price of each token from the token_prices_latest table?"},{"role":"assistant","content":"SELECT b.wallet_address, t.symbol, b.amount, p.price FROM erc20_balances b JOIN sui_coins_metadata t ON b.contract_address = t.coin_type JOIN token_prices_latest p ON b.contract_address = p.address WHERE CAST(b.amount AS decimal) > 1000 ORDER BY CAST(b.amount AS decimal) DESC;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE train_station_management.train_cars ( car_id.text, train_id.text, car_number.text, car_type.text, class.text, capacity.integer, features.text )\n","conversations":[{"role":"user","content":"What is the fuel efficiency of the train car with car_id 'TC456'?"},{"role":"assistant","content":"I'm sorry, but I don't have access to information about the fuel efficiency of specific train cars. The data available in the train_cars table only includes details such as car_id, train_id, car_number, car_type, class, capacity, and features. If you have another question or need assistance with something else, I'm happy to help."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\nCREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )\n","conversations":[{"role":"user","content":"I want a list of each department's top 3 longest-tenured active employees, showing their full names, hire_date, and their manager\u2019s full names."},{"role":"assistant","content":"WITH ranked AS (\n SELECT\n e.department,\n e.employee_id,\n e.first_name || ' ' || e.last_name AS employee_full_name,\n e.hire_date,\n e.manager_id,\n ROW_NUMBER() OVER (PARTITION BY e.department ORDER BY e.hire_date ASC) AS rn\n FROM financial_services.employees e\n WHERE e.status = 'Active'\n)\nSELECT\n r.department,\n r.employee_full_name,\n r.hire_date,\n m.first_name || ' ' || m.last_name AS manager_full_name\nFROM ranked r\nLEFT JOIN financial_services.employees m ON r.manager_id = m.employee_id\nWHERE r.rn <= 3;"},{"role":"user","content":"Actually, only include employees hired before '2018-01-01'."},{"role":"assistant","content":"WITH ranked AS (\n SELECT\n e.department,\n e.employee_id,\n e.first_name || ' ' || e.last_name AS employee_full_name,\n e.hire_date,\n e.manager_id,\n ROW_NUMBER() OVER (PARTITION BY e.department ORDER BY e.hire_date ASC) AS rn\n FROM financial_services.employees e\n WHERE e.status = 'Active'\n AND e.hire_date < '2018-01-01'\n)\nSELECT\n r.department,\n r.employee_full_name,\n r.hire_date,\n m.first_name || ' ' || m.last_name AS manager_full_name\nFROM ranked r\nLEFT JOIN financial_services.employees m ON r.manager_id = m.employee_id\nWHERE r.rn <= 3;"},{"role":"user","content":"Also, only consider departments that have at least 5 active employees in total before applying the top 3 filter."},{"role":"assistant","content":"WITH dept_counts AS (\n SELECT department\n FROM financial_services.employees\n WHERE status = 'Active'\n GROUP BY department\n HAVING COUNT(*) >= 5\n),\nranked AS (\n SELECT\n e.department,\n e.employee_id,\n e.first_name || ' ' || e.last_name AS employee_full_name,\n e.hire_date,\n e.manager_id,\n ROW_NUMBER() OVER (PARTITION BY e.department ORDER BY e.hire_date ASC) AS rn\n FROM financial_services.employees e\n JOIN dept_counts d ON e.department = d.department\n WHERE e.status = 'Active'\n AND e.hire_date < '2018-01-01'\n)\nSELECT\n r.department,\n r.employee_full_name,\n r.hire_date,\n m.first_name || ' ' || m.last_name AS manager_full_name\nFROM ranked r\nLEFT JOIN financial_services.employees m ON r.manager_id = m.employee_id\nWHERE r.rn <= 3;"},{"role":"user","content":"Finally, sort the result by department ascending and hire_date ascending."},{"role":"assistant","content":"WITH dept_counts AS (\n SELECT department\n FROM financial_services.employees\n WHERE status = 'Active'\n GROUP BY department\n HAVING COUNT(*) >= 5\n),\nranked AS (\n SELECT\n e.department,\n e.employee_id,\n e.first_name || ' ' || e.last_name AS employee_full_name,\n e.hire_date,\n e.manager_id,\n ROW_NUMBER() OVER (PARTITION BY e.department ORDER BY e.hire_date ASC) AS rn\n FROM financial_services.employees e\n JOIN dept_counts d ON e.department = d.department\n WHERE e.status = 'Active'\n AND e.hire_date < '2018-01-01'\n)\nSELECT\n r.department,\n r.employee_full_name,\n r.hire_date,\n m.first_name || ' ' || m.last_name AS manager_full_name\nFROM ranked r\nLEFT JOIN financial_services.employees m ON r.manager_id = m.employee_id\nWHERE r.rn <= 3\nORDER BY r.department ASC, r.hire_date ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, token_symbol character varying(100), token_amount numeric(38,2), usd_value numeric(38,2), avg_price numeric(38,6), type int, address_amount integer, narrative character varying(100), chain character varying(100) )\n","conversations":[{"role":"user","content":"Show the top 3 tokens on Polygon with the greatest positive price change over the last 6 hours, including their symbol, price, 6h change, and the number of smart money buy addresses in the last 24h."},{"role":"assistant","content":"SELECT tdi.token_symbol, tdi.price, tdi.price_change_percentage_6h, \n COALESCE(SUM(CASE WHEN smti.type = 1 AND smti.chain = 'Polygon' THEN smti.address_amount ELSE 0 END), 0) AS buy_address_count\nFROM token_dexpool_info tdi\nLEFT JOIN smart_money_token_inflow smti\n ON tdi.token_symbol = smti.token_symbol AND tdi.chain = smti.chain\nWHERE tdi.chain = 'Polygon' AND tdi.price_change_percentage_6h > 0\nGROUP BY tdi.token_symbol, tdi.price, tdi.price_change_percentage_6h\nORDER BY tdi.price_change_percentage_6h DESC\nLIMIT 3;"},{"role":"user","content":"Instead of just Polygon, can you show the top 3 tokens with the greatest positive 6h price change across both Polygon and BSC? Still include the number of smart money buys."},{"role":"assistant","content":"SELECT tdi.token_symbol, tdi.chain, tdi.price, tdi.price_change_percentage_6h, \n COALESCE(SUM(CASE WHEN smti.type = 1 THEN smti.address_amount ELSE 0 END), 0) AS buy_address_count\nFROM token_dexpool_info tdi\nLEFT JOIN smart_money_token_inflow smti\n ON tdi.token_symbol = smti.token_symbol AND tdi.chain = smti.chain\nWHERE tdi.chain IN ('Polygon', 'BSC') AND tdi.price_change_percentage_6h > 0\nGROUP BY tdi.token_symbol, tdi.chain, tdi.price, tdi.price_change_percentage_6h\nORDER BY tdi.price_change_percentage_6h DESC\nLIMIT 3;"},{"role":"user","content":"Now, only display tokens with at least 10 smart money buy addresses. Also, add their 24h trading volume."},{"role":"assistant","content":"SELECT tdi.token_symbol, tdi.chain, tdi.price, tdi.price_change_percentage_6h, tdi.volume_24h, \n COALESCE(SUM(CASE WHEN smti.type = 1 THEN smti.address_amount ELSE 0 END), 0) AS buy_address_count\nFROM token_dexpool_info tdi\nLEFT JOIN smart_money_token_inflow smti\n ON tdi.token_symbol = smti.token_symbol AND tdi.chain = smti.chain\nWHERE tdi.chain IN ('Polygon', 'BSC') AND tdi.price_change_percentage_6h > 0\nGROUP BY tdi.token_symbol, tdi.chain, tdi.price, tdi.price_change_percentage_6h, tdi.volume_24h\nHAVING COALESCE(SUM(CASE WHEN smti.type = 1 THEN smti.address_amount ELSE 0 END), 0) >= 10\nORDER BY tdi.price_change_percentage_6h DESC\nLIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"Which SUI coins have 'exists' status and what is the total balance across all owners for each coin_type? Please include coin_type, symbol, name, and total_balance."},{"role":"assistant","content":"SELECT sc.coin_type,\n sm.symbol,\n sm.name,\n SUM(CAST(sc.balance AS numeric)) AS total_balance\nFROM sui_coins AS sc\nJOIN sui_coins_metadata AS sm\n ON sc.coin_type = sm.coin_type\n AND sm.status = 'exists'\nWHERE sc.status = 'exists'\nGROUP BY sc.coin_type, sm.symbol, sm.name\nORDER BY total_balance DESC;"},{"role":"user","content":"Only include coin types where total_balance is greater than 1000000."},{"role":"assistant","content":"SELECT sc.coin_type,\n sm.symbol,\n sm.name,\n SUM(CAST(sc.balance AS numeric)) AS total_balance\nFROM sui_coins AS sc\nJOIN sui_coins_metadata AS sm\n ON sc.coin_type = sm.coin_type\n AND sm.status = 'exists'\nWHERE sc.status = 'exists'\nGROUP BY sc.coin_type, sm.symbol, sm.name\nHAVING SUM(CAST(sc.balance AS numeric)) > 1000000\nORDER BY total_balance DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text, first_name text, last_name text, company_name text, email text, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.law_firms ( firm_id text, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.cases ( case_id text, case_number text, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.documents ( document_id text, case_id text, document_name text, document_type text, storage_path text, uploaded_by_lawyer_id text, upload_timestamp timestamp, version integer, description text )\nCREATE TABLE legal_services.time_entries ( entry_id text, case_id text, lawyer_id text, date_worked date, hours_spent numeric, billing_rate numeric, description text, is_billable boolean, is_billed boolean, invoice_id text, created_at timestamp )\n","conversations":[{"role":"user","content":"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;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.users ( user_id.text, username.text, email.text, password_hash.text, created_at.timestamp )\n","conversations":[{"role":"user","content":"How many users registered on each weekday? Return the weekday name and registration count."},{"role":"assistant","content":"SELECT\n to_char(created_at, 'FMDay') AS weekday,\n COUNT(*) AS registration_count\nFROM web3.users\nGROUP BY 1\nORDER BY registration_count DESC;"},{"role":"user","content":"Actually, only include weekdays with more than 100 registrations."},{"role":"assistant","content":"SELECT\n to_char(created_at, 'FMDay') AS weekday,\n COUNT(*) AS registration_count\nFROM web3.users\nGROUP BY 1\nHAVING COUNT(*) > 100\nORDER BY registration_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\nCREATE TABLE healthcare.doctors ( doctor_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, specialty character varying(100) NOT NULL, license_number character varying(50) UNIQUE NOT NULL, phone_number character varying(20), email character varying(128) UNIQUE, hospital_affiliation_id character varying(64), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (doctor_id) )\nCREATE TABLE healthcare.appointments ( appointment_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, appointment_time timestamp with time zone NOT NULL, duration_minutes integer NOT NULL, reason text, status character varying(32) NOT NULL, location_id character varying(64), notes text, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (appointment_id) )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, diagnosis_code character varying(20) NOT NULL, code_type character varying(10) NOT NULL DEFAULT 'ICD-10', description text, diagnosis_date date NOT NULL, status character varying(32) NOT NULL, is_chronic boolean DEFAULT false, PRIMARY KEY (diagnosis_id) )\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\nCREATE TABLE healthcare.insurance_plans ( plan_id character varying(64) NOT NULL, plan_name character varying(200) NOT NULL, insurance_provider character varying(100) NOT NULL, plan_type character varying(50), contact_phone character varying(20), website character varying(255), PRIMARY KEY (plan_id) )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n","conversations":[{"role":"user","content":"List all patients who have been prescribed medications with dosage greater than 50mg, along with their medication details and prescribing doctor's name."},{"role":"assistant","content":"SELECT p.first_name, p.last_name, pr.dosage, pr.medication_id, pr.frequency, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name FROM healthcare.patients p JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id WHERE pr.dosage LIKE '%50mg%' OR pr.dosage LIKE '%>50%' OR CAST(SUBSTRING(pr.dosage FROM '[0-9]+') AS INTEGER) > 50;"},{"role":"user","content":"Actually, I need to see only prescriptions that were issued in the last 3 months."},{"role":"assistant","content":"SELECT p.first_name, p.last_name, pr.dosage, pr.medication_id, pr.frequency, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name FROM healthcare.patients p JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id WHERE (pr.dosage LIKE '%50mg%' OR pr.dosage LIKE '%>50%' OR CAST(SUBSTRING(pr.dosage FROM '[0-9]+') AS INTEGER) > 50) AND pr.prescription_date >= CURRENT_DATE - INTERVAL '3 months';"},{"role":"user","content":"Can you also include the prescription start date and end date in the results?"},{"role":"assistant","content":"SELECT p.first_name, p.last_name, pr.dosage, pr.medication_id, pr.frequency, pr.start_date, pr.end_date, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name FROM healthcare.patients p JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id WHERE (pr.dosage LIKE '%50mg%' OR pr.dosage LIKE '%>50%' OR CAST(SUBSTRING(pr.dosage FROM '[0-9]+') AS INTEGER) > 50) AND pr.prescription_date >= CURRENT_DATE - INTERVAL '3 months';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text, license_plate text, vin text, make text, model text, year integer, type text, capacity integer, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers (\n driver_id character varying(64) NOT NULL, -- unique identifier for the driver\n employee_id character varying(64) NOT NULL UNIQUE, -- employee reference number\n first_name character varying(128) NOT NULL, -- driver's first name\n last_name character varying(128) NOT NULL, -- driver's last name\n license_number character varying(64) NOT NULL UNIQUE, -- driving license number\n license_expiry_date date NOT NULL, -- expiry date of the license\n contact_number character varying(32), -- phone number\n email character varying(128) UNIQUE, -- email address\n hire_date date NOT NULL, -- date the driver was hired\n status character varying(32) NOT NULL, -- e.g., Active, On Leave, Terminated\n PRIMARY KEY (driver_id)\n)\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.bookings ( booking_id character varying(64) NOT NULL, passenger_id character varying(64) NOT NULL, trip_id character varying(64) NOT NULL, seat_number character varying(16), booking_time timestamp with time zone NOT NULL, status character varying(32) NOT NULL, fare numeric(10, 2) NOT NULL, payment_transaction_id character varying(128), special_requests text, PRIMARY KEY (booking_id) )\n","conversations":[{"role":"user","content":"For each vehicle, show vehicle_id, make, model, the earliest and latest fuel log IDs with their timestamps."},{"role":"assistant","content":"WITH extremes AS (\n SELECT vehicle_id,\n MIN(log_timestamp) AS first_ts,\n MAX(log_timestamp) AS last_ts\n FROM transportation.fuel_logs\n GROUP BY vehicle_id\n)\nSELECT v.vehicle_id,\n v.make,\n v.model,\n fl1.fuel_log_id AS first_log_id,\n extremes.first_ts AS first_log_timestamp,\n fl2.fuel_log_id AS last_log_id,\n extremes.last_ts AS last_log_timestamp\nFROM extremes\nJOIN transportation.vehicles v\n ON v.vehicle_id = extremes.vehicle_id\nJOIN transportation.fuel_logs fl1\n ON fl1.vehicle_id = extremes.vehicle_id\n AND fl1.log_timestamp = extremes.first_ts\nJOIN transportation.fuel_logs fl2\n ON fl2.vehicle_id = extremes.vehicle_id\n AND fl2.log_timestamp = extremes.last_ts;"},{"role":"user","content":"Also include the cost difference between the latest and earliest total_cost as cost_diff."},{"role":"assistant","content":"WITH extremes AS (\n SELECT vehicle_id,\n MIN(log_timestamp) AS first_ts,\n MAX(log_timestamp) AS last_ts\n FROM transportation.fuel_logs\n GROUP BY vehicle_id\n)\nSELECT v.vehicle_id,\n v.make,\n v.model,\n fl1.fuel_log_id AS first_log_id,\n extremes.first_ts AS first_log_timestamp,\n fl2.fuel_log_id AS last_log_id,\n extremes.last_ts AS last_log_timestamp,\n (fl2.total_cost - fl1.total_cost) AS cost_diff\nFROM extremes\nJOIN transportation.vehicles v\n ON v.vehicle_id = extremes.vehicle_id\nJOIN transportation.fuel_logs fl1\n ON fl1.vehicle_id = extremes.vehicle_id\n AND fl1.log_timestamp = extremes.first_ts\nJOIN transportation.fuel_logs fl2\n ON fl2.vehicle_id = extremes.vehicle_id\n AND fl2.log_timestamp = extremes.last_ts;"},{"role":"user","content":"Only include vehicles with at least two fuel log entries and cost_diff > 100, and order by cost_diff DESC."},{"role":"assistant","content":"WITH extremes AS (\n SELECT vehicle_id,\n MIN(log_timestamp) AS first_ts,\n MAX(log_timestamp) AS last_ts,\n COUNT(*) AS log_count\n FROM transportation.fuel_logs\n GROUP BY vehicle_id\n HAVING COUNT(*) >= 2\n)\nSELECT v.vehicle_id,\n v.make,\n v.model,\n fl1.fuel_log_id AS first_log_id,\n extremes.first_ts AS first_log_timestamp,\n fl2.fuel_log_id AS last_log_id,\n extremes.last_ts AS last_log_timestamp,\n (fl2.total_cost - fl1.total_cost) AS cost_diff\nFROM extremes\nJOIN transportation.vehicles v\n ON v.vehicle_id = extremes.vehicle_id\nJOIN transportation.fuel_logs fl1\n ON fl1.vehicle_id = extremes.vehicle_id\n AND fl1.log_timestamp = extremes.first_ts\nJOIN transportation.fuel_logs fl2\n ON fl2.vehicle_id = extremes.vehicle_id\n AND fl2.log_timestamp = extremes.last_ts\nWHERE (fl2.total_cost - fl1.total_cost) > 100\nORDER BY cost_diff DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.peers ( peer_id.text, ip_address.text, port.integer, last_seen.timestamp )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\n","conversations":[{"role":"user","content":"Show me asset IDs and DApp names for metadata entries linking assets to DApps where metadata.value matches a dapp_id."},{"role":"assistant","content":"SELECT m.asset_id, d.name AS dapp_name\nFROM trading_platform.metadata m\nJOIN trading_platform.dapps d\n ON m.value = d.dapp_id;"},{"role":"user","content":"Filter where metadata.key starts with 'link'."},{"role":"assistant","content":"SELECT m.asset_id, d.name AS dapp_name\nFROM trading_platform.metadata m\nJOIN trading_platform.dapps d\n ON m.value = d.dapp_id\nWHERE m.key LIKE 'link%';"},{"role":"user","content":"Include the metadata.key in the select list."},{"role":"assistant","content":"SELECT m.asset_id, d.name AS dapp_name, m.key AS metadata_key\nFROM trading_platform.metadata m\nJOIN trading_platform.dapps d\n ON m.value = d.dapp_id\nWHERE m.key LIKE 'link%';"},{"role":"user","content":"Order the final result by asset_id and limit to 5."},{"role":"assistant","content":"SELECT m.asset_id, d.name AS dapp_name, m.key AS metadata_key\nFROM trading_platform.metadata m\nJOIN trading_platform.dapps d\n ON m.value = d.dapp_id\nWHERE m.key LIKE 'link%'\nORDER BY m.asset_id\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\n","conversations":[{"role":"user","content":"Show me all claims handled by agents who were hired in the last 3 years, along with the agent's full name and agency."},{"role":"assistant","content":"SELECT c.claim_id, c.policy_id, c.incident_date, c.status, CONCAT(a.first_name, ' ', a.last_name) AS agent_name, a.agency_name FROM insurance.claims c JOIN insurance.agents a ON c.claim_handler_id = a.agent_id WHERE a.hire_date >= CURRENT_DATE - INTERVAL '3 years';"},{"role":"user","content":"Now filter this to only show claims that were settled for more than $10,000."},{"role":"assistant","content":"SELECT c.claim_id, c.policy_id, c.incident_date, c.status, c.settlement_amount, CONCAT(a.first_name, ' ', a.last_name) AS agent_name, a.agency_name FROM insurance.claims c JOIN insurance.agents a ON c.claim_handler_id = a.agent_id WHERE a.hire_date >= CURRENT_DATE - INTERVAL '3 years' AND c.settlement_amount > 10000;"},{"role":"user","content":"I also want to see how long it took to settle these claims (difference between reported_date and settlement_date)."},{"role":"assistant","content":"SELECT c.claim_id, c.policy_id, c.incident_date, c.status, c.settlement_amount, (c.settlement_date - c.reported_date) AS days_to_settle, CONCAT(a.first_name, ' ', a.last_name) AS agent_name, a.agency_name FROM insurance.claims c JOIN insurance.agents a ON c.claim_handler_id = a.agent_id WHERE a.hire_date >= CURRENT_DATE - INTERVAL '3 years' AND c.settlement_amount > 10000;"},{"role":"user","content":"Now order the results by the longest settlement time first."},{"role":"assistant","content":"SELECT c.claim_id, c.policy_id, c.incident_date, c.status, c.settlement_amount, (c.settlement_date - c.reported_date) AS days_to_settle, CONCAT(a.first_name, ' ', a.last_name) AS agent_name, a.agency_name FROM insurance.claims c JOIN insurance.agents a ON c.claim_handler_id = a.agent_id WHERE a.hire_date >= CURRENT_DATE - INTERVAL '3 years' AND c.settlement_amount > 10000 ORDER BY days_to_settle DESC;"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n","conversations":[{"role":"user","content":"Show me the total market cap and the total smart money inflow USD value for each narrative. Join the `token_basic_info` and `smart_money_token_inflow` tables based on narrative."},{"role":"assistant","content":"WITH Narratives AS ( SELECT DISTINCT narrative FROM token_basic_info WHERE narrative IS NOT NULL UNION SELECT DISTINCT narrative FROM smart_money_token_inflow WHERE narrative IS NOT NULL ) SELECT n.narrative, SUM(tbi.market_cap) AS total_market_cap, SUM(smi.usd_value) AS total_inflow_usd FROM Narratives n LEFT JOIN token_basic_info tbi ON n.narrative = tbi.narrative LEFT JOIN smart_money_token_inflow smi ON n.narrative = smi.narrative GROUP BY n.narrative ORDER BY total_inflow_usd DESC NULLS LAST;"},{"role":"user","content":"From that list, only show narratives where the total market cap is greater than 1,000,000,000."},{"role":"assistant","content":"WITH Narratives AS ( SELECT DISTINCT narrative FROM token_basic_info WHERE narrative IS NOT NULL UNION SELECT DISTINCT narrative FROM smart_money_token_inflow WHERE narrative IS NOT NULL ) SELECT n.narrative, SUM(tbi.market_cap) AS total_market_cap, SUM(smi.usd_value) AS total_inflow_usd FROM Narratives n LEFT JOIN token_basic_info tbi ON n.narrative = tbi.narrative LEFT JOIN smart_money_token_inflow smi ON n.narrative = smi.narrative GROUP BY n.narrative HAVING SUM(tbi.market_cap) > 1000000000 ORDER BY total_inflow_usd DESC NULLS LAST;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp(6) NOT NULL, block_number bigint NOT NULL, transaction_hash varchar NOT NULL, transaction_index bigint NOT NULL, from_address varchar NOT NULL, contract_address varchar NOT NULL, symbol varchar NOT NULL, total_supply varchar NOT NULL, name varchar NOT NULL, decimals bigint NOT NULL, is_erc20 integer NOT NULL, is_erc721 integer NOT NULL, is_erc1155 integer NOT NULL, is_proxy integer NOT NULL, extra_info varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE nft_holder_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata ( object_id varchar NOT NULL, coin_type varchar NOT NULL, status varchar NOT NULL, decimals bigint NOT NULL, description varchar NOT NULL, icon_url varchar NOT NULL, symbol varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE sui_nfts ( object_id varchar NOT NULL, status varchar NOT NULL, collection_type varchar NOT NULL, package_id varchar NOT NULL, previous_transaction varchar NOT NULL, display varchar NOT NULL, owner varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid varchar(36) NOT NULL, blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain varchar(36) NOT NULL, address varchar(42) NOT NULL, decimals bigint NOT NULL, symbol varchar(36) NOT NULL, price real NOT NULL, timestamp timestamp(6) NOT NULL )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(62) NOT NULL, to_address varchar(62) NOT NULL )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, log_index integer NOT NULL, type varchar(20) NOT NULL, tick varchar(255) NOT NULL, id varchar(255) NOT NULL, amt decimal(38,0) NOT NULL, from_address varchar(42) NOT NULL, to_address varchar(42) NOT NULL )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(20) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL, minted decimal(38,0) NOT NULL, holders decimal(38,0) NOT NULL, txs decimal(38,0) NOT NULL, updated_timestamp timestamp(3) NOT NULL, completed_timestamp timestamp(3) NOT NULL, id varchar(255) NOT NULL )\n","conversations":[{"role":"user","content":"Show me the top 5 NFT collections with the highest floor price on Ethereum, along with their names and contract addresses, but only include collections with more than 5000 tokens."},{"role":"assistant","content":"SELECT nc.name, nc.contract_address, nc.floor_price FROM nft_collections nc WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"},{"role":"user","content":"Can you join this with the nft_metadata table to include the average rarity score for these collections?"},{"role":"assistant","content":"SELECT nc.name, nc.contract_address, nc.floor_price, AVG(nm.rarity_score) as avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 GROUP BY nc.name, nc.contract_address, nc.floor_price ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"},{"role":"user","content":"Now filter these results to only show collections with an average rarity score above 75."},{"role":"assistant","content":"SELECT nc.name, nc.contract_address, nc.floor_price, AVG(nm.rarity_score) as avg_rarity_score FROM nft_collections nc JOIN nft_metadata nm ON nc.contract_address = nm.contract_address WHERE nc.blockchain = 'Ethereum' AND nc.token_count > 5000 GROUP BY nc.name, nc.contract_address, nc.floor_price HAVING AVG(nm.rarity_score) > 75 ORDER BY CAST(nc.floor_price AS decimal) DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, token_address character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_24h double precision, price_change_percentage_7d double precision, highest_price_24h double precision, lowest_price_24h double precision, market_cap double precision, market_cap_rank bigint, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank bigint )\n \"CREATE TABLE narrative_info (\",\n \"narrative character varying(512) NOT NULL, -- the id of narrative\",\n \"top_3_coins text, -- the top 3 tokens in the narrative\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative\",\n \"price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative\",\n \"market_cap double precision, -- the market cap of the narrative\",\n \"volume_24h double precision, -- the trade volume of the narrative\",\n \"trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative\",\n \"token_num bigint, -- total token number in the narrative\",\n \",PRIMARY KEY (narrative));\"\n\nCREATE TABLE cex_token_balance ( snapshot_time character varying(32) NOT NULL, chain character varying(128) NOT NULL, address character varying(128) NOT NULL, exchange character varying(512) NOT NULL, token_address character varying(128) NOT NULL, token_symbol character varying(512), balance numeric(38,10), usd_value numeric(38,14), price double precision )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, token_symbol character varying(100), pnl numeric(38,2), net_flow numeric(38,2), avg_cost numeric(38,16), price double precision, realized_ratio numeric(10,2), roi numeric(10,2), chain character varying(100) )\n","conversations":[{"role":"user","content":"Show me the top 5 projects by valuation that completed fundraising rounds in the last 3 months, along with their narrative information if available."},{"role":"assistant","content":"SELECT pfr.project_name, pfr.valuation, pfr.rounds_name, pfr.investment_date, ni.narrative, ni.trend_rank FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name LEFT JOIN narrative_info ni ON tbi.narrative = ni.narrative WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) ORDER BY pfr.valuation DESC LIMIT 5;"},{"role":"user","content":"Can you also include the 24-hour trading volume for these projects' narratives and filter to only include projects with valuation over $50 million?"},{"role":"assistant","content":"SELECT pfr.project_name, pfr.valuation, pfr.rounds_name, pfr.investment_date, ni.narrative, ni.trend_rank, ni.volume_24h FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name LEFT JOIN narrative_info ni ON tbi.narrative = ni.narrative WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 3 MONTH) AND pfr.valuation > 50000000 ORDER BY pfr.valuation DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id uuid PRIMARY KEY, name text, country text, founded_year int, website text, created_at timestamptz )\n","conversations":[{"role":"user","content":"For each developer, can you find the next developer in the same country using a self join, returning developer_ids and names?"},{"role":"assistant","content":"SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN developers d2\n ON d1.country = d2.country\n AND d2.founded_year > d1.founded_year;"},{"role":"user","content":"Exclude developers who don't have a next developer, and ensure we only pick the closest next by founded_year."},{"role":"assistant","content":"SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN LATERAL (\n SELECT d2.developer_id, d2.name, d2.founded_year\n FROM developers d2\n WHERE d2.country = d1.country\n AND d2.founded_year > d1.founded_year\n ORDER BY d2.founded_year ASC\n LIMIT 1\n) d2 ON true;"},{"role":"user","content":"Finally, only include pairs where the difference in founded years is at most 5 years."},{"role":"assistant","content":"SELECT d1.developer_id AS current_dev,\n d1.name AS current_name,\n d2.developer_id AS next_dev,\n d2.name AS next_name,\n d2.founded_year - d1.founded_year AS years_diff\nFROM developers d1\nJOIN LATERAL (\n SELECT d2.developer_id, d2.name, d2.founded_year\n FROM developers d2\n WHERE d2.country = d1.country\n AND d2.founded_year > d1.founded_year\n ORDER BY d2.founded_year ASC\n LIMIT 1\n) d2 ON true\nWHERE (d2.founded_year - d1.founded_year) <= 5\nORDER BY d1.developer_id, years_diff ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id text, project_id text, project_name text, rounds_name text, investment_value numeric, investment_date text, introduction text, valuation numeric )\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE token_dexpool_info ( pair_address text, token_name text, token_symbol text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_6h numeric, price_change_percentage_24h numeric, makers_24h numeric, volume_24h numeric, liquidity numeric, market_cap numeric, trend_rank numeric )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\n","conversations":[{"role":"user","content":"For each fundraising round, can you list the total amount invested and the corresponding number of projects in that round, as well as the highest token market cap associated with any project of that round? Please show the round name, total investment, project count, and max token market cap."},{"role":"assistant","content":"SELECT r.rounds_name, SUM(r.investment_value) AS total_investment, COUNT(DISTINCT r.project_id) AS project_count, MAX(b.market_cap) AS max_token_market_cap\nFROM project_fundraising_record r\nLEFT JOIN token_basic_info b ON LOWER(r.project_name) = LOWER(b.token_name)\nGROUP BY r.rounds_name;"},{"role":"user","content":"Actually, can you restrict this to only rounds where the max token market cap is above 100 million? Also, order by total investment descending."},{"role":"assistant","content":"SELECT rounds_name, total_investment, project_count, max_token_market_cap\nFROM (\n SELECT r.rounds_name, SUM(r.investment_value) AS total_investment, COUNT(DISTINCT r.project_id) AS project_count, MAX(b.market_cap) AS max_token_market_cap\n FROM project_fundraising_record r\n LEFT JOIN token_basic_info b ON LOWER(r.project_name) = LOWER(b.token_name)\n GROUP BY r.rounds_name\n) t\nWHERE max_token_market_cap > 100000000\nORDER BY total_investment DESC;"},{"role":"user","content":"I got empty results. Could you update the join condition to also allow a match when either the project name is contained in the token name or vice versa, case-insensitively?"},{"role":"assistant","content":"SELECT rounds_name, total_investment, project_count, max_token_market_cap\nFROM (\n SELECT r.rounds_name, SUM(r.investment_value) AS total_investment, COUNT(DISTINCT r.project_id) AS project_count, MAX(b.market_cap) AS max_token_market_cap\n FROM project_fundraising_record r\n LEFT JOIN token_basic_info b\n ON LOWER(r.project_name) = LOWER(b.token_name)\n OR LOWER(b.token_name) LIKE CONCAT('%', LOWER(r.project_name), '%')\n OR LOWER(r.project_name) LIKE CONCAT('%', LOWER(b.token_name), '%')\n GROUP BY r.rounds_name\n) t\nWHERE max_token_market_cap > 100000000\nORDER BY total_investment DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n","conversations":[{"role":"user","content":"Which narrative and chain combination saw the highest total USD buy value in the first half of 2023? Also list the total token amount bought for each."},{"role":"assistant","content":"SELECT narrative, chain, SUM(usd_value) AS total_usd_bought, SUM(token_amount) AS total_token_bought\nFROM smart_money_token_inflow\nWHERE type = 1 AND to_char(cast(token_address AS text), 'YYYY-MM-DD') >= '2023-01-01' \n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') <= '2023-06-30'\nGROUP BY narrative, chain\nORDER BY total_usd_bought DESC\nLIMIT 1;"},{"role":"user","content":"Can you show the top 5 combinations instead of just the top one?"},{"role":"assistant","content":"SELECT narrative, chain, SUM(usd_value) AS total_usd_bought, SUM(token_amount) AS total_token_bought\nFROM smart_money_token_inflow\nWHERE type = 1 AND to_char(cast(token_address AS text), 'YYYY-MM-DD') >= '2023-01-01' \n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') <= '2023-06-30'\nGROUP BY narrative, chain\nORDER BY total_usd_bought DESC\nLIMIT 5;"},{"role":"user","content":"Please add the average price paid for each narrative-chain pair in the result."},{"role":"assistant","content":"SELECT narrative, chain, SUM(usd_value) AS total_usd_bought, SUM(token_amount) AS total_token_bought, AVG(avg_price) AS avg_price\nFROM smart_money_token_inflow\nWHERE type = 1 AND to_char(cast(token_address AS text), 'YYYY-MM-DD') >= '2023-01-01' \n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') <= '2023-06-30'\nGROUP BY narrative, chain\nORDER BY total_usd_bought DESC\nLIMIT 5;"},{"role":"user","content":"Now limit only to combinations where the total token amount bought is greater than 1000."},{"role":"assistant","content":"SELECT narrative, chain, SUM(usd_value) AS total_usd_bought, SUM(token_amount) AS total_token_bought, AVG(avg_price) AS avg_price\nFROM smart_money_token_inflow\nWHERE type = 1 AND to_char(cast(token_address AS text), 'YYYY-MM-DD') >= '2023-01-01'\n AND to_char(cast(token_address AS text), 'YYYY-MM-DD') <= '2023-06-30'\nGROUP BY narrative, chain\nHAVING SUM(token_amount) > 1000\nORDER BY total_usd_bought DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.cases (\n case_id character varying(64) NOT NULL, -- unique identifier for the case\/matter\n case_number character varying(100) UNIQUE, -- official case number (court or internal)\n case_name text NOT NULL, -- descriptive name or title for the case\n client_id character varying(64) NOT NULL, -- FK to clients table\n lead_lawyer_id character varying(64) NOT NULL, -- FK to lawyers table (primary lawyer responsible)\n case_type character varying(100) NOT NULL, -- e.g., Litigation, Corporate, Family Law, IP\n status character varying(50) NOT NULL, -- e.g., Open, Closed, Pending, On Hold, Appealed\n date_opened timestamp NOT NULL, -- date the case was formally opened\n date_closed timestamp, -- date the case was closed (nullable)\n description text, -- detailed description of the case\n court_jurisdiction character varying(128), -- court or jurisdiction if applicable\n PRIMARY KEY (case_id)\n)\n","conversations":[{"role":"user","content":"Calculate the average number of days cases stay open before being closed, grouped by case type. Only consider cases that have a date closed."},{"role":"assistant","content":"SELECT case_type, AVG(DATE_PART('day', date_closed - date_opened)) AS average_duration_days FROM legal_services.cases WHERE status = 'Closed' AND date_closed IS NOT NULL GROUP BY case_type;"},{"role":"user","content":"Exclude case types where the average duration is less than 100 days and order the results by average duration descending."},{"role":"assistant","content":"SELECT case_type, AVG(DATE_PART('day', date_closed - date_opened)) AS average_duration_days FROM legal_services.cases WHERE status = 'Closed' AND date_closed IS NOT NULL GROUP BY case_type HAVING AVG(DATE_PART('day', date_closed - date_opened)) >= 100 ORDER BY average_duration_days DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts (\n account_id character varying(64) NOT NULL, -- unique identifier for the account\n customer_id character varying(64) NOT NULL, -- foreign key linking to the customer\n account_number character varying(128) NOT NULL UNIQUE, -- unique account number visible to customer\n account_type character varying(50) NOT NULL, -- e.g., Checking, Savings, Investment, Loan, Credit Card\n balance numeric(19, 4) NOT NULL DEFAULT 0.00, -- current account balance\n currency character varying(3) NOT NULL, -- currency code (e.g., USD, EUR)\n opened_date date NOT NULL, -- date the account was opened\n status character varying(32) NOT NULL, -- e.g., Open, Closed, Frozen\n interest_rate numeric(5, 4), -- annual interest rate, if applicable\n last_updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of last account update\n PRIMARY KEY (account_id),\n FOREIGN KEY (customer_id) REFERENCES financial_services.customers(customer_id)\n)\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\n","conversations":[{"role":"user","content":"I want to list all employees who currently manage at least one other employee, showing their full name, email, and the total number of direct reports for each manager."},{"role":"assistant","content":"SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email;"},{"role":"user","content":"Can you also include the job_title and department of each manager in the result?"},{"role":"assistant","content":"SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, e.job_title, e.department, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email, e.job_title, e.department;"},{"role":"user","content":"I noticed some managers don't have any reports\u2014that shouldn't be the case. Only show managers who have at least two direct reports."},{"role":"assistant","content":"SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, e.job_title, e.department, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email, e.job_title, e.department\nHAVING COUNT(r.employee_id) >= 2;"},{"role":"user","content":"Please order the output by the number of direct reports in descending order."},{"role":"assistant","content":"SELECT e.employee_id, e.first_name || ' ' || e.last_name AS manager_full_name, e.email, e.job_title, e.department, COUNT(r.employee_id) AS direct_report_count\nFROM financial_services.employees e\nJOIN financial_services.employees r ON e.employee_id = r.manager_id\nWHERE e.status = 'Active'\nGROUP BY e.employee_id, e.first_name, e.last_name, e.email, e.job_title, e.department\nHAVING COUNT(r.employee_id) >= 2\nORDER BY direct_report_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number \/ 7200))\n)\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id varchar NOT NULL, status varchar NOT NULL, collection_type varchar NOT NULL, package_id varchar NOT NULL, previous_transaction varchar NOT NULL, display varchar NOT NULL, owner varchar NOT NULL, name varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n max_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n lim decimal(38,0) NOT NULL, -- Mint limit: limit per inscription\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL, -- Address originating the inscription (matches from_address in transactions table)\n minted decimal(38,0) NOT NULL, -- Sum of minted amount\n holders decimal(38,0) NOT NULL, -- Count of holders\n txs decimal(38,0) NOT NULL, -- Count of transactions\n updated_timestamp timestamp(3) NOT NULL, -- Timestamp of update\n completed_timestamp timestamp(3) NOT NULL, -- Timestamp of minted completed\n id varchar(255) NOT NULL -- id fields for the functionType in contract asc20\n)\n","conversations":[{"role":"user","content":"Get the total balance of each SUI coin per coin_type, including symbol and name from metadata."},{"role":"assistant","content":"SELECT sc.coin_type,\n scm.symbol,\n scm.name,\n SUM(CAST(sc.balance AS NUMERIC)) AS total_balance\nFROM sui_coins AS sc\nJOIN sui_coins_metadata AS scm\n ON sc.coin_type = scm.coin_type\nGROUP BY sc.coin_type, scm.symbol, scm.name;"},{"role":"user","content":"Only include coins where description contains 'governance'."},{"role":"assistant","content":"SELECT sc.coin_type,\n scm.symbol,\n scm.name,\n SUM(CAST(sc.balance AS NUMERIC)) AS total_balance\nFROM sui_coins AS sc\nJOIN sui_coins_metadata AS scm\n ON sc.coin_type = scm.coin_type\nWHERE scm.description ILIKE '%governance%'\nGROUP BY sc.coin_type, scm.symbol, scm.name;"},{"role":"user","content":"Limit to top 5 coins sorted by total_balance descending."},{"role":"assistant","content":"SELECT sc.coin_type,\n scm.symbol,\n scm.name,\n SUM(CAST(sc.balance AS NUMERIC)) AS total_balance\nFROM sui_coins AS sc\nJOIN sui_coins_metadata AS scm\n ON sc.coin_type = scm.coin_type\nWHERE scm.description ILIKE '%governance%'\nGROUP BY sc.coin_type, scm.symbol, scm.name\nORDER BY total_balance DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.game_sessions (\n session_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the game session\n player_id uuid NOT NULL, -- FK linking to the players table\n game_id uuid NOT NULL, -- FK linking to the games table\n server_id uuid, -- FK linking to the servers table (nullable for single-player)\n start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the session began\n end_time timestamp with time zone, -- when the session ended (null if ongoing)\n duration_seconds integer, -- calculated duration of the session in seconds\n score integer, -- player's score for the session, if applicable\n session_data jsonb, -- flexible field for session-specific info (e.g., map played, character used)\n PRIMARY KEY (session_id)\n -- FOREIGN KEY (player_id) REFERENCES gaming_technology.players(player_id),\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id),\n -- FOREIGN KEY (server_id) REFERENCES gaming_technology.servers(server_id)\n)\nCREATE TABLE gaming_technology.servers ( server_id uuid, game_id uuid, server_name text, region text, ip_address text, port integer, current_players integer, max_players integer, status text, last_heartbeat timestamp with time zone )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid, player_id uuid, achievement_id uuid, unlocked_at timestamp with time zone )\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid, player_id uuid, item_id uuid, quantity integer, acquired_at timestamp with time zone, instance_data jsonb )\n","conversations":[{"role":"user","content":"Can you show me, for each player, the total number of different in-game items they have acquired, along with the names and types of these items?"},{"role":"assistant","content":"SELECT pi.player_id, COUNT(DISTINCT pi.item_id) AS unique_items_acquired, STRING_AGG(igi.item_name || ' (' || igi.item_type || ')', ', ') AS item_names_types\nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.in_game_items igi ON pi.item_id = igi.item_id\nGROUP BY pi.player_id;"},{"role":"user","content":"Now, please include the total quantity of items each player has acquired along with the previous information."},{"role":"assistant","content":"SELECT pi.player_id,\n COUNT(DISTINCT pi.item_id) AS unique_items_acquired,\n SUM(pi.quantity) AS total_quantity,\n STRING_AGG(igi.item_name || ' (' || igi.item_type || ')', ', ') AS item_names_types\nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.in_game_items igi ON pi.item_id = igi.item_id\nGROUP BY pi.player_id;"},{"role":"user","content":"I got too many results. Can you show only those players who have at least 3 different items and a total item quantity above 10?"},{"role":"assistant","content":"SELECT pi.player_id,\n COUNT(DISTINCT pi.item_id) AS unique_items_acquired,\n SUM(pi.quantity) AS total_quantity,\n STRING_AGG(igi.item_name || ' (' || igi.item_type || ')', ', ') AS item_names_types\nFROM gaming_technology.player_inventory pi\nJOIN gaming_technology.in_game_items igi ON pi.item_id = igi.item_id\nGROUP BY pi.player_id\nHAVING COUNT(DISTINCT pi.item_id) >= 3 AND SUM(pi.quantity) > 10;"},{"role":"user","content":"Please also show, for each player, the name of the rarest item they own (based on rarity alphabetically highest)."},{"role":"assistant","content":"SELECT t.player_id, t.unique_items_acquired, t.total_quantity, t.item_names_types,\n (\n SELECT igi.item_name\n FROM gaming_technology.player_inventory pi2\n JOIN gaming_technology.in_game_items igi ON pi2.item_id = igi.item_id\n WHERE pi2.player_id = t.player_id\n ORDER BY igi.rarity DESC NULLS LAST\n LIMIT 1\n ) AS rarest_item_name\nFROM (\n SELECT pi.player_id,\n COUNT(DISTINCT pi.item_id) AS unique_items_acquired,\n SUM(pi.quantity) AS total_quantity,\n STRING_AGG(igi.item_name || ' (' || igi.item_type || ')', ', ') AS item_names_types\n FROM gaming_technology.player_inventory pi\n JOIN gaming_technology.in_game_items igi ON pi.item_id = igi.item_id\n GROUP BY pi.player_id\n HAVING COUNT(DISTINCT pi.item_id) >= 3 AND SUM(pi.quantity) > 10\n) t;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE narrative_info ( narrative.text, top_3_coins.text, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, market_cap.numeric, volume_24h.numeric, trend_rank.numeric, token_num.numeric )\n \"CREATE TABLE cex_token_balance (\",\n \"snapshot_time character varying(32) NOT NULL, -- the snapshot time of record, converted from original timestamp\",\n \"chain character varying(128) NOT NULL, -- the chain that the token resides\",\n \"address character varying(128) NOT NULL, -- the address that holds the assets, owned by a CEX\",\n \"exchange character varying(512) NOT NULL, -- a centralized exchange name\",\n \"token_address character varying(128) NOT NULL, -- token contract address\",\n \"token_symbol character varying(512), --token symbol\",\n \"balance numeric(38,10), -- token balance\",\n \"usd_value numeric(38,14), -- value of the token held in USD\",\n \"price double precision, --price of the token in USD\",\n \",PRIMARY KEY (snapshot_time, exchange, address, chain, token_address));\"\n\n","conversations":[{"role":"user","content":"For the 'AI' and 'Gaming' narratives, what is the total USD value held by CEXes for tokens listed in their top 3 coins?"},{"role":"assistant","content":"SELECT T2.narrative, SUM(T1.usd_value) AS TotalCexUSDValue FROM cex_token_balance AS T1 JOIN narrative_info AS T2 ON T2.top_3_coins LIKE '%' || T1.token_symbol || '%' WHERE T2.narrative IN ('AI', 'Gaming') GROUP BY T2.narrative"},{"role":"user","content":"Also show the average price of these tokens in CEX holdings for each narrative."},{"role":"assistant","content":"SELECT T2.narrative, SUM(T1.usd_value) AS TotalCexUSDValue, AVG(T1.price) AS AverageTokenPrice FROM cex_token_balance AS T1 JOIN narrative_info AS T2 ON T2.top_3_coins LIKE '%' || T1.token_symbol || '%' WHERE T2.narrative IN ('AI', 'Gaming') GROUP BY T2.narrative"},{"role":"user","content":"Can you filter the results to only include tokens where the USD value in the CEX holding record is greater than $1000?"},{"role":"assistant","content":"SELECT T2.narrative, SUM(T1.usd_value) AS TotalCexUSDValue, AVG(T1.price) AS AverageTokenPrice FROM cex_token_balance AS T1 JOIN narrative_info AS T2 ON T2.top_3_coins LIKE '%' || T1.token_symbol || '%' WHERE T2.narrative IN ('AI', 'Gaming') AND T1.usd_value > 1000 GROUP BY T2.narrative"},{"role":"user","content":"Order the results by total USD value descending and show both narratives."},{"role":"assistant","content":"SELECT T2.narrative, SUM(T1.usd_value) AS TotalCexUSDValue, AVG(T1.price) AS AverageTokenPrice FROM cex_token_balance AS T1 JOIN narrative_info AS T2 ON T2.top_3_coins LIKE '%' || T1.token_symbol || '%' WHERE T2.narrative IN ('AI', 'Gaming') AND T1.usd_value > 1000 GROUP BY T2.narrative ORDER BY TotalCexUSDValue DESC"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record\/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions\/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment\/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\n","conversations":[{"role":"user","content":"Show me all insurance plans that have more than 5 patients enrolled as their primary insurance, along with the provider name and count of patients, sorted by patient count in descending order."},{"role":"assistant","content":"SELECT ip.insurance_provider, ip.plan_name, COUNT(pi.patient_id) AS patient_count FROM healthcare.insurance_plans ip JOIN healthcare.patient_insurance pi ON ip.plan_id = pi.plan_id WHERE pi.is_primary = true GROUP BY ip.insurance_provider, ip.plan_name HAVING COUNT(pi.patient_id) > 5 ORDER BY patient_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\n","conversations":[{"role":"user","content":"I need to find every offline server alongside an online server in the same region."},{"role":"assistant","content":"SELECT s_off.server_id AS offline_id,\n s_on.server_id AS online_id\nFROM gaming_technology.servers s_off\nJOIN gaming_technology.servers s_on\n ON s_off.region = s_on.region\nWHERE s_off.status = 'offline'\n AND s_on.status = 'online';"},{"role":"user","content":"Include the names of both servers, labeling them offline_server and online_server."},{"role":"assistant","content":"SELECT s_off.server_name AS offline_server,\n s_on.server_name AS online_server\nFROM gaming_technology.servers s_off\nJOIN gaming_technology.servers s_on\n ON s_off.region = s_on.region\nWHERE s_off.status = 'offline'\n AND s_on.status = 'online';"},{"role":"user","content":"Also add the online server's current_players and status."},{"role":"assistant","content":"SELECT s_off.server_name AS offline_server,\n s_on.server_name AS online_server,\n s_on.current_players,\n s_on.status AS online_status\nFROM gaming_technology.servers s_off\nJOIN gaming_technology.servers s_on\n ON s_off.region = s_on.region\nWHERE s_off.status = 'offline'\n AND s_on.status = 'online';"},{"role":"user","content":"Order the results by offline_server ascending."},{"role":"assistant","content":"SELECT s_off.server_name AS offline_server,\n s_on.server_name AS online_server,\n s_on.current_players,\n s_on.status AS online_status\nFROM gaming_technology.servers s_off\nJOIN gaming_technology.servers s_on\n ON s_off.region = s_on.region\nWHERE s_off.status = 'offline'\n AND s_on.status = 'online'\nORDER BY offline_server ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.service_locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the physical location\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n location_name character varying(200), -- e.g., Downtown DMV Office\n address text NOT NULL,\n city character varying(100),\n state character varying(50),\n postal_code character varying(20),\n latitude numeric(9, 6),\n longitude numeric(9, 6),\n operating_hours text, -- description of opening times\n contact_phone character varying(32),\n is_accessible boolean, -- accessibility information (e.g., wheelchair access)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\n","conversations":[{"role":"user","content":"How many total appointments have been recorded?"},{"role":"assistant","content":"SELECT count(*) FROM appointments;"},{"role":"user","content":"What is the count of appointments that have the status 'Completed'?"},{"role":"assistant","content":"SELECT count(*) FROM appointments WHERE status = 'Completed';"},{"role":"user","content":"For completed appointments, list the purpose and the name of the related service."},{"role":"assistant","content":"SELECT T1.purpose, T2.service_name FROM appointments AS T1 JOIN services AS T2 ON T1.service_id = T2.service_id WHERE T1.status = 'Completed';"},{"role":"user","content":"Also include the location name for these completed appointments, specifically those booked via 'Online'."},{"role":"assistant","content":"SELECT T1.purpose, T2.service_name, T3.location_name FROM appointments AS T1 JOIN services AS T2 ON T1.service_id = T2.service_id JOIN service_locations AS T3 ON T1.location_id = T3.location_id WHERE T1.status = 'Completed' AND T1.booking_method = 'Online';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.time_entries ( entry_id 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) )\nCREATE TABLE legal_services.appointments ( appointment_id text, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n","conversations":[{"role":"user","content":"List all lawyers who have never had a time entry that was billed, showing lawyer_id, first_name, and last_name."},{"role":"assistant","content":"SELECT l.lawyer_id, l.first_name, l.last_name \nFROM legal_services.lawyers l \nLEFT JOIN legal_services.time_entries te \n ON l.lawyer_id = te.lawyer_id \n AND te.is_billed = true \nWHERE te.entry_id IS NULL;"},{"role":"user","content":"Actually, I only want lawyers who have at least one time entry overall but none of those entries are billed."},{"role":"assistant","content":"SELECT l.lawyer_id, l.first_name, l.last_name \nFROM legal_services.lawyers l \nJOIN legal_services.time_entries te ON l.lawyer_id = te.lawyer_id \nGROUP BY l.lawyer_id, l.first_name, l.last_name \nHAVING COUNT(te.entry_id) > 0 \n AND SUM(CASE WHEN te.is_billed = true THEN 1 ELSE 0 END) = 0;"},{"role":"user","content":"Now also include the count of unbilled entries and total unbilled hours for each lawyer."},{"role":"assistant","content":"SELECT l.lawyer_id, \n l.first_name, \n l.last_name, \n COUNT(te.entry_id) FILTER (WHERE te.is_billed = false) AS unbilled_entries, \n SUM(te.hours_spent) FILTER (WHERE te.is_billed = false) AS total_unbilled_hours \nFROM legal_services.lawyers l \nJOIN legal_services.time_entries te ON l.lawyer_id = te.lawyer_id \nGROUP BY l.lawyer_id, l.first_name, l.last_name \nHAVING COUNT(te.entry_id) > 0 \n AND SUM(CASE WHEN te.is_billed = true THEN 1 ELSE 0 END) = 0;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_avalanche (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(42) NOT NULL, -- Address sending the inscription\n to_address varchar(42) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"Which NFTs minted in the past 14 days on Ethereum have a rarity_score above 70? For each, show contract address, token ID, name, and minter."},{"role":"assistant","content":"SELECT contract_address, token_id, name, minter\nFROM nft_metadata\nWHERE blockchain = 'Ethereum'\n AND mint_time >= (extract(epoch from now()) - 14*24*60*60)\n AND rarity_score > 70;"},{"role":"user","content":"For these NFTs, can you also include the collection name and symbol by joining with the nft_collections table?"},{"role":"assistant","content":"SELECT nm.contract_address, nm.token_id, nm.name, nm.minter, nc.name AS collection_name, nc.symbol\nFROM nft_metadata nm\nJOIN nft_collections nc\n ON nm.blockchain = nc.blockchain AND nm.contract_address = nc.contract_address\nWHERE nm.blockchain = 'Ethereum'\n AND nm.mint_time >= (extract(epoch from now()) - 14*24*60*60)\n AND nm.rarity_score > 70;"},{"role":"user","content":"Can you filter only those collections where the erc_type is 'ERC1155'?"},{"role":"assistant","content":"SELECT nm.contract_address, nm.token_id, nm.name, nm.minter, nc.name AS collection_name, nc.symbol\nFROM nft_metadata nm\nJOIN nft_collections nc\n ON nm.blockchain = nc.blockchain AND nm.contract_address = nc.contract_address\nWHERE nm.blockchain = 'Ethereum'\n AND nm.mint_time >= (extract(epoch from now()) - 14*24*60*60)\n AND nm.rarity_score > 70\n AND nc.erc_type = 'ERC1155';"},{"role":"user","content":"Now, also include the owner for each NFT, and order the results by rarity_rank ascending."},{"role":"assistant","content":"SELECT nm.contract_address, nm.token_id, nm.name, nm.minter, nm.owner, nc.name AS collection_name, nc.symbol\nFROM nft_metadata nm\nJOIN nft_collections nc\n ON nm.blockchain = nc.blockchain AND nm.contract_address = nc.contract_address\nWHERE nm.blockchain = 'Ethereum'\n AND nm.mint_time >= (extract(epoch from now()) - 14*24*60*60)\n AND nm.rarity_score > 70\n AND nc.erc_type = 'ERC1155'\nORDER BY nm.rarity_rank ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE narrative_info ( narrative.text, top_3_coins.text, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, market_cap.numeric, volume_24h.numeric, trend_rank.numeric, token_num.numeric )\nCREATE TABLE cex_token_balance ( snapshot_time 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) )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\n","conversations":[{"role":"user","content":"For each chain, which centralized exchange holds the largest total USD value in their token balance as of the most recent snapshot?"},{"role":"assistant","content":"WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n)\nSELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value\nFROM cex_token_balance c\nJOIN latest_snapshot l ON c.snapshot_time = l.max_time\nGROUP BY c.chain, c.exchange\nQUALIFY ROW_NUMBER() OVER(PARTITION BY c.chain ORDER BY SUM(c.usd_value) DESC) = 1;"},{"role":"user","content":"Could you also include the number of distinct tokens each exchange holds in those chains?"},{"role":"assistant","content":"WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n GROUP BY c.chain, c.exchange\n),\nranked_exchanges AS (\n SELECT *, ROW_NUMBER() OVER(PARTITION BY chain ORDER BY total_usd_value DESC) AS rn\n FROM exchange_totals\n)\nSELECT chain, exchange, total_usd_value, token_count\nFROM ranked_exchanges\nWHERE rn = 1;"},{"role":"user","content":"I got an error with the QUALIFY clause. Can you rewrite the query using a derived table or CTE instead?"},{"role":"assistant","content":"WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n GROUP BY c.chain, c.exchange\n),\nmax_values AS (\n SELECT chain, MAX(total_usd_value) AS max_usd_value\n FROM exchange_totals\n GROUP BY chain\n)\nSELECT e.chain, e.exchange, e.total_usd_value, e.token_count\nFROM exchange_totals e\nJOIN max_values m ON e.chain = m.chain AND e.total_usd_value = m.max_usd_value;"},{"role":"user","content":"Now, only show exchanges where their usd_value is above $5,000,000."},{"role":"assistant","content":"WITH latest_snapshot AS (\n SELECT MAX(snapshot_time) AS max_time FROM cex_token_balance\n),\nexchange_totals AS (\n SELECT c.chain, c.exchange, SUM(c.usd_value) AS total_usd_value, COUNT(DISTINCT c.token_symbol) AS token_count\n FROM cex_token_balance c\n JOIN latest_snapshot l ON c.snapshot_time = l.max_time\n GROUP BY c.chain, c.exchange\n),\nmax_values AS (\n SELECT chain, MAX(total_usd_value) AS max_usd_value\n FROM exchange_totals\n GROUP BY chain\n)\nSELECT e.chain, e.exchange, e.total_usd_value, e.token_count\nFROM exchange_totals e\nJOIN max_values m ON e.chain = m.chain AND e.total_usd_value = m.max_usd_value\nWHERE e.total_usd_value > 5000000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\nCREATE TABLE trading_platform.orders (\n order_id character varying(64) NOT NULL, -- unique identifier for the order\n user_id character varying(64) NOT NULL, -- identifier of the user placing the order\n wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)\n created_at timestamp NOT NULL, -- time when the order was created\n PRIMARY KEY (order_id)\n)\nCREATE TABLE trading_platform.dapps (\n dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp\n name character varying(128) NOT NULL, -- name of the DApp\n description text NOT NULL, -- description of the DApp\n url character varying(256) NOT NULL, -- URL of the DApp\n PRIMARY KEY (dapp_id)\n)\nCREATE TABLE trading_platform.peers (\n peer_id character varying(64) NOT NULL, -- unique identifier for the peer\n ip_address character varying(15) NOT NULL, -- IP address of the peer\n port integer NOT NULL, -- port number of the peer\n last_seen timestamp NOT NULL, -- last time the peer was active\n PRIMARY KEY (peer_id)\n)\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the log entry\n user_id character varying(64), -- identifier of the user associated with the log entry\n action character varying(128) NOT NULL, -- action performed\n details text NOT NULL, -- details of the action\n logged_at timestamp NOT NULL, -- time when the log entry was created\n PRIMARY KEY (log_id)\n)\n","conversations":[{"role":"user","content":"For each asset, I want to know how many orders have the status 'filled', showing the asset symbol."},{"role":"assistant","content":"SELECT m.value AS asset_symbol,\n COUNT(*) AS filled_order_count\nFROM trading_platform.orders o\nJOIN trading_platform.metadata m\n ON o.asset_id = m.asset_id\n AND m.key = 'symbol'\nWHERE o.status = 'filled'\nGROUP BY m.value;"},{"role":"user","content":"Include assets that have zero filled orders, showing filled_order_count as 0."},{"role":"assistant","content":"WITH asset_symbols AS (\n SELECT DISTINCT asset_id,\n value AS asset_symbol\n FROM trading_platform.metadata\n WHERE key = 'symbol'\n)\nSELECT a.asset_symbol,\n COALESCE(f.filled_order_count, 0) AS filled_order_count\nFROM asset_symbols a\nLEFT JOIN (\n SELECT asset_id,\n COUNT(*) AS filled_order_count\n FROM trading_platform.orders\n WHERE status = 'filled'\n GROUP BY asset_id\n) f\n ON a.asset_id = f.asset_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.trades ( trade_id text PRIMARY KEY, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data ( data_point_id.bigint, security_id.text, data_timestamp.timestamp, open_price.numeric, high_price.numeric, low_price.numeric, close_price.numeric, adjusted_close_price.numeric, volume.bigint, source.text )\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\nCREATE TABLE financial_services.loans ( loan_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL UNIQUE, loan_type character varying(50) NOT NULL, principal_amount numeric(19, 4) NOT NULL, current_principal_balance numeric(19, 4) NOT NULL, interest_rate numeric(6, 4) NOT NULL, term_months integer NOT NULL, origination_date date NOT NULL, maturity_date date NOT NULL, monthly_payment numeric(12, 4), collateral_description text, status character varying(32) NOT NULL, PRIMARY KEY (loan_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id) )\n","conversations":[{"role":"user","content":"For each trade in the past 14 days, show the trade_id, account_id, security_id, and the latest close_price for that security from market_data."},{"role":"assistant","content":"SELECT tr.trade_id, tr.account_id, tr.security_id, md.close_price AS latest_close_price, md.data_timestamp\nFROM financial_services.trades tr\nLEFT JOIN LATERAL (\n SELECT m.close_price, m.data_timestamp\n FROM financial_services.market_data m\n WHERE m.security_id = tr.security_id\n ORDER BY m.data_timestamp DESC\n LIMIT 1\n) md ON TRUE\nWHERE tr.trade_timestamp >= NOW() - INTERVAL '14 days';"},{"role":"user","content":"Only show trades where the total_amount is above 3,000 and the latest_close_price is available."},{"role":"assistant","content":"SELECT tr.trade_id, tr.account_id, tr.security_id, md.close_price AS latest_close_price, md.data_timestamp\nFROM financial_services.trades tr\nLEFT JOIN LATERAL (\n SELECT m.close_price, m.data_timestamp\n FROM financial_services.market_data m\n WHERE m.security_id = tr.security_id\n ORDER BY m.data_timestamp DESC\n LIMIT 1\n) md ON TRUE\nWHERE tr.trade_timestamp >= NOW() - INTERVAL '14 days'\n AND tr.total_amount > 3000\n AND md.close_price IS NOT NULL;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.customers ( customer_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, ssn_hash text, address text, city text, state text, zip_code text, country text, email text, phone_number text, created_at timestamp, status text, risk_profile text )\n","conversations":[{"role":"user","content":"I want to list all pairs of customers living in the same city with different risk profiles."},{"role":"assistant","content":"SELECT a.customer_id AS customer_a,\n b.customer_id AS customer_b,\n a.city,\n a.risk_profile AS risk_a,\n b.risk_profile AS risk_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.city = b.city\n AND a.customer_id < b.customer_id\nWHERE a.risk_profile <> b.risk_profile;"},{"role":"user","content":"Actually, restrict to customers created in the last year."},{"role":"assistant","content":"SELECT a.customer_id AS customer_a,\n b.customer_id AS customer_b,\n a.city,\n a.risk_profile AS risk_a,\n b.risk_profile AS risk_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.city = b.city\n AND a.customer_id < b.customer_id\nWHERE a.risk_profile <> b.risk_profile\n AND a.created_at >= CURRENT_DATE - INTERVAL '1 year'\n AND b.created_at >= CURRENT_DATE - INTERVAL '1 year';"},{"role":"user","content":"Please order the output by city and then by customer_a."},{"role":"assistant","content":"SELECT a.customer_id AS customer_a,\n b.customer_id AS customer_b,\n a.city,\n a.risk_profile AS risk_a,\n b.risk_profile AS risk_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.city = b.city\n AND a.customer_id < b.customer_id\nWHERE a.risk_profile <> b.risk_profile\n AND a.created_at >= CURRENT_DATE - INTERVAL '1 year'\n AND b.created_at >= CURRENT_DATE - INTERVAL '1 year'\nORDER BY a.city, a.customer_id;"},{"role":"user","content":"And only include pairs where both have a non-null phone number."},{"role":"assistant","content":"SELECT a.customer_id AS customer_a,\n b.customer_id AS customer_b,\n a.city,\n a.risk_profile AS risk_a,\n b.risk_profile AS risk_b\nFROM financial_services.customers a\nJOIN financial_services.customers b\n ON a.city = b.city\n AND a.customer_id < b.customer_id\nWHERE a.risk_profile <> b.risk_profile\n AND a.created_at >= CURRENT_DATE - INTERVAL '1 year'\n AND b.created_at >= CURRENT_DATE - INTERVAL '1 year'\n AND a.phone_number IS NOT NULL\n AND b.phone_number IS NOT NULL\nORDER BY a.city, a.customer_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- hashed social security number (or national ID)\n address text NOT NULL, -- customer's primary address\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL,\n email character varying(128) UNIQUE, -- customer's email address\n phone_number character varying(32),\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- timestamp of customer record creation\n status character varying(32) NOT NULL, -- e.g., Active, Inactive, Pending Verification\n risk_profile character varying(50), -- e.g., Low, Medium, High\n PRIMARY KEY (customer_id)\n)\nCREATE TABLE financial_services.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n account_id character varying(64) NOT NULL, -- account involved in the transaction\n related_account_id character varying(64), -- counterpart account for transfers\n transaction_type character varying(50) NOT NULL, -- e.g., Deposit, Withdrawal, Transfer, Payment, Fee, Interest\n amount numeric(19, 4) NOT NULL, -- transaction amount\n currency character varying(3) NOT NULL, -- transaction currency\n transaction_date timestamp NOT NULL, -- exact time of the transaction\n effective_date date NOT NULL, -- date the transaction affects the balance\n description text, -- description or memo of the transaction\n status character varying(32) NOT NULL, -- e.g., Pending, Completed, Failed, Reversed\n reference_number character varying(128), -- external reference if applicable (e.g., check number)\n PRIMARY KEY (transaction_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (related_account_id) REFERENCES financial_services.accounts(account_id)\n)\nCREATE TABLE financial_services.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n account_id character varying(64) NOT NULL, -- investment account executing the trade\n security_id character varying(64) NOT NULL, -- security being traded\n order_id character varying(64), -- related order ID if applicable\n trade_type character varying(10) NOT NULL, -- 'Buy' or 'Sell'\n quantity numeric(19, 8) NOT NULL, -- number of units traded\n price_per_unit numeric(19, 8) NOT NULL, -- price per unit of the security\n total_amount numeric(19, 4) NOT NULL, -- total value of the trade (quantity * price)\n commission numeric(10, 4), -- commission fee charged for the trade\n trade_timestamp timestamp NOT NULL, -- exact time the trade was executed\n settlement_date date, -- date the trade settles\n status character varying(32) NOT NULL, -- e.g., Executed, Settled, Cancelled\n execution_venue character varying(100), -- where the trade was executed\n PRIMARY KEY (trade_id),\n FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id),\n FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id)\n)\nCREATE TABLE financial_services.market_data (\n data_point_id bigserial NOT NULL, -- auto-incrementing primary key\n security_id character varying(64) NOT NULL, -- identifier for the security\n data_timestamp timestamp NOT NULL, -- timestamp for the data point (e.g., end of day, intraday)\n open_price numeric(19, 8), -- opening price for the period\n high_price numeric(19, 8), -- highest price during the period\n low_price numeric(19, 8), -- lowest price during the period\n close_price numeric(19, 8) NOT NULL, -- closing price for the period\n adjusted_close_price numeric(19, 8), -- closing price adjusted for dividends and splits\n volume bigint, -- trading volume during the period\n source character varying(50), -- source of the market data (e.g., Bloomberg, Refinitiv)\n PRIMARY KEY (data_point_id),\n UNIQUE (security_id, data_timestamp), -- Ensure unique data point per security per time\n FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id)\n)\n","conversations":[{"role":"user","content":"Generate a summary for each account showing the total commissions from trades and total fees from completed transactions in April 2024."},{"role":"assistant","content":"SELECT t.account_id,\n SUM(COALESCE(t.commission,0)) AS total_trade_commission,\n SUM(CASE WHEN tr.transaction_type = 'Fee' AND tr.status = 'Completed' THEN tr.amount ELSE 0 END) AS total_transaction_fees\nFROM financial_services.trades t\nLEFT JOIN financial_services.transactions tr\n ON t.account_id = tr.account_id\n AND tr.transaction_date BETWEEN '2024-04-01' AND '2024-04-30'\nWHERE t.trade_timestamp BETWEEN '2024-04-01' AND '2024-04-30'\nGROUP BY t.account_id;"},{"role":"user","content":"Actually, only include accounts where the total_trade_commission is greater than 500."},{"role":"assistant","content":"SELECT t.account_id,\n SUM(COALESCE(t.commission,0)) AS total_trade_commission,\n SUM(CASE WHEN tr.transaction_type = 'Fee' AND tr.status = 'Completed' THEN tr.amount ELSE 0 END) AS total_transaction_fees\nFROM financial_services.trades t\nLEFT JOIN financial_services.transactions tr\n ON t.account_id = tr.account_id\n AND tr.transaction_date BETWEEN '2024-04-01' AND '2024-04-30'\nWHERE t.trade_timestamp BETWEEN '2024-04-01' AND '2024-04-30'\nGROUP BY t.account_id\nHAVING SUM(COALESCE(t.commission,0)) > 500;"},{"role":"user","content":"Also, order the output by total_transaction_fees descending."},{"role":"assistant","content":"SELECT t.account_id,\n SUM(COALESCE(t.commission,0)) AS total_trade_commission,\n SUM(CASE WHEN tr.transaction_type = 'Fee' AND tr.status = 'Completed' THEN tr.amount ELSE 0 END) AS total_transaction_fees\nFROM financial_services.trades t\nLEFT JOIN financial_services.transactions tr\n ON t.account_id = tr.account_id\n AND tr.transaction_date BETWEEN '2024-04-01' AND '2024-04-30'\nWHERE t.trade_timestamp BETWEEN '2024-04-01' AND '2024-04-30'\nGROUP BY t.account_id\nHAVING SUM(COALESCE(t.commission,0)) > 500\nORDER BY total_transaction_fees DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text )\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE erc20_balances_historical ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_bitcoin ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.text, amount.text )\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )\n","conversations":[{"role":"user","content":"Find the total balance per coin_type for active SUI coins, including coin_type, symbol, name, and SUM(balance) as total_balance. Sort by total_balance descending."},{"role":"assistant","content":"SELECT\n c.coin_type,\n m.symbol,\n m.name,\n SUM(CAST(c.balance AS BIGINT)) AS total_balance\nFROM sui_coins c\nJOIN sui_coins_metadata m\n ON c.coin_type = m.coin_type\nWHERE c.status = 'active'\n AND m.status = 'exists'\nGROUP BY c.coin_type, m.symbol, m.name\nORDER BY total_balance DESC;"},{"role":"user","content":"Actually, limit to coins where total_balance is above 1000000."},{"role":"assistant","content":"SELECT\n c.coin_type,\n m.symbol,\n m.name,\n SUM(CAST(c.balance AS BIGINT)) AS total_balance\nFROM sui_coins c\nJOIN sui_coins_metadata m\n ON c.coin_type = m.coin_type\nWHERE c.status = 'active'\n AND m.status = 'exists'\nGROUP BY c.coin_type, m.symbol, m.name\nHAVING SUM(CAST(c.balance AS BIGINT)) > 1000000\nORDER BY total_balance DESC;"},{"role":"user","content":"Also filter metadata where description contains 'Utility'."},{"role":"assistant","content":"SELECT\n c.coin_type,\n m.symbol,\n m.name,\n SUM(CAST(c.balance AS BIGINT)) AS total_balance\nFROM sui_coins c\nJOIN sui_coins_metadata m\n ON c.coin_type = m.coin_type\nWHERE c.status = 'active'\n AND m.status = 'exists'\n AND m.description ILIKE '%Utility%'\nGROUP BY c.coin_type, m.symbol, m.name\nHAVING SUM(CAST(c.balance AS BIGINT)) > 1000000\nORDER BY total_balance DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas (\n block_timestamp timestamp(6) NOT NULL, -- Timestamp of the block when token metadata was recorded\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n transaction_hash varchar NOT NULL, -- Hash value of the transaction\n transaction_index bigint NOT NULL, -- Index of the transaction within the block\n from_address varchar NOT NULL, -- Address from which the transaction originated\n contract_address varchar NOT NULL, -- Address of the token contract\n symbol varchar NOT NULL, -- Symbol of the token\n total_supply varchar NOT NULL, -- erc20 contract total supply\n name varchar NOT NULL, -- Name of the token\n decimals bigint NOT NULL, -- Number of decimal places for the token\n is_erc20 integer NOT NULL, -- Flag indicating if the token is an ERC-20 token (0 or 1)\n is_erc721 integer NOT NULL, -- Flag indicating if the token is an ERC-721 token (0 or 1)\n is_erc1155 integer NOT NULL, -- Flag indicating if the token is an ERC-1155 token (0 or 1)\n is_proxy integer NOT NULL, -- Flag indicating if the token is a proxy (0 or 1)\n extra_info varchar NOT NULL, -- Additional information about the token\n pk integer NOT NULL -- Partition key for the table(floor(block_number \/ 5760))\n)\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- Number of held NFTs\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE token_activities (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar NOT NULL, -- mint | transfer | burn\n tick varchar NOT NULL, -- Token tick\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Mint amount\n from_address varchar(42) NOT NULL, -- Address sending the inscription (matches from_address in transactions table)\n to_address varchar(42) NOT NULL -- Address receiving the inscription (match to_address in transactions table)\n)\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"List all NFT collections where the floor price is greater than 0.5 ETH, including their names and contract addresses."},{"role":"assistant","content":"SELECT name, contract_address FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH';"},{"role":"user","content":"Can you also include the banner image URL and filter to only show ERC721 collections?"},{"role":"assistant","content":"SELECT name, contract_address, banner_image_url FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721';"},{"role":"user","content":"Now sort these results by floor price in descending order and limit to the top 10."},{"role":"assistant","content":"SELECT name, contract_address, banner_image_url, floor_price FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721' ORDER BY CAST(floor_price AS decimal) DESC LIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.trips ( trip_id text PRIMARY KEY, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count int, cargo_manifest_id text )\nCREATE TABLE transportation.locations ( location_id text PRIMARY KEY, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs ( log_id text PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\nCREATE TABLE transportation.bookings ( booking_id text PRIMARY KEY, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n","conversations":[{"role":"user","content":"For each route that originates from a location of type 'Port', list the route number, the name of the origin location, and the total distance accumulated from all completed trips on this route."},{"role":"assistant","content":"SELECT\n r.route_number,\n l_origin.name AS origin_location_name,\n SUM(t.distance_km) AS total_accumulated_distance\nFROM transportation.routes AS r\nJOIN transportation.locations AS l_origin\n ON r.origin_location_id = l_origin.location_id\nJOIN transportation.trips AS t\n ON r.route_id = t.route_id\nWHERE\n l_origin.type = 'Port' AND t.status = 'Completed'\nGROUP BY\n r.route_id,\n r.route_number,\n l_origin.name;"},{"role":"user","content":"Now, only include routes where the accumulated distance is greater than 5000 kilometers and order the results by accumulated distance descending."},{"role":"assistant","content":"SELECT\n r.route_number,\n l_origin.name AS origin_location_name,\n SUM(t.distance_km) AS total_accumulated_distance\nFROM transportation.routes AS r\nJOIN transportation.locations AS l_origin\n ON r.origin_location_id = l_origin.location_id\nJOIN transportation.trips AS t\n ON r.route_id = t.route_id\nWHERE\n l_origin.type = 'Port' AND t.status = 'Completed'\nGROUP BY\n r.route_id,\n r.route_number,\n l_origin.name\nHAVING\n SUM(t.distance_km) > 5000\nORDER BY\n total_accumulated_distance DESC;"},{"role":"user","content":"Also include the number of completed trips for each of these routes and filter further to only show routes that have had more than 5 completed trips."},{"role":"assistant","content":"SELECT\n r.route_number,\n l_origin.name AS origin_location_name,\n SUM(t.distance_km) AS total_accumulated_distance,\n COUNT(t.trip_id) AS completed_trip_count\nFROM transportation.routes AS r\nJOIN transportation.locations AS l_origin\n ON r.origin_location_id = l_origin.location_id\nJOIN transportation.trips AS t\n ON r.route_id = t.route_id\nWHERE\n l_origin.type = 'Port' AND t.status = 'Completed'\nGROUP BY\n r.route_id,\n r.route_number,\n l_origin.name\nHAVING\n SUM(t.distance_km) > 5000 AND COUNT(t.trip_id) > 5\nORDER BY\n total_accumulated_distance DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE nft_holders ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, token_id varchar NOT NULL, contract_type varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n tick varchar NOT NULL, -- Token tick\n max_supply decimal(38,0) NOT NULL, -- Max supply\n lim decimal(38,0) NOT NULL, -- Limit of each mint\n wlim decimal(38,0) NOT NULL, -- Limit of each address can maximum mint\n dec integer NOT NULL, -- Decimal for minimum divie\n creator varchar(42) NOT NULL -- Address originating the inscription (matches from_address in transactions table)\n)\nCREATE TABLE mud_holesky_redstone (\n address varchar NOT NULL, -- address fields for the functionType in contract\n table_id varchar NOT NULL, -- table_id fields for the functionType in contract\n key_bytes varchar NOT NULL, -- key_bytes fields for the functionType in contract\n key0 varchar NOT NULL, -- key0 fields for the functionType in contract\n key1 varchar NOT NULL, -- key1 fields for the functionType in contract\n static_data varchar NOT NULL, -- static_data fields for the functionType in contract\n encoded_lengths varchar NOT NULL, -- encoded_lengths fields for the functionType in contract\n dynamic_data varchar NOT NULL, -- dynamic_data fields for the functionType in contract\n is_deleted boolean NOT NULL, -- is_deleted fields for the functionType in contract\n block_number bigint NOT NULL, -- Block number uniquely identifying the block\n log_index bigint NOT NULL -- Index of the log within the transaction\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"For each ERC1155 NFT contract on Ethereum, show the `contract_address`, `token_id`, total amount held across all wallets, and number of unique holders."},{"role":"assistant","content":"SELECT nh.contract_address,\n nh.token_id,\n SUM(CAST(nh.amount AS bigint)) AS total_amount,\n COUNT(DISTINCT nh.wallet_address) AS holder_count\nFROM nft_holders nh\nJOIN nft_metadata nm\n ON nh.contract_address = nm.contract_address\n AND nh.token_id = nm.token_id\nWHERE nm.blockchain = 'Ethereum'\n AND nm.erc_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id;"},{"role":"user","content":"Only include NFTs where the `total_amount` is greater than 1000."},{"role":"assistant","content":"SELECT nh.contract_address,\n nh.token_id,\n SUM(CAST(nh.amount AS bigint)) AS total_amount,\n COUNT(DISTINCT nh.wallet_address) AS holder_count\nFROM nft_holders nh\nJOIN nft_metadata nm\n ON nh.contract_address = nm.contract_address\n AND nh.token_id = nm.token_id\nWHERE nm.blockchain = 'Ethereum'\n AND nm.erc_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id\nHAVING SUM(CAST(nh.amount AS bigint)) > 1000;"},{"role":"user","content":"Add the NFT `name` from `nft_metadata` in the result."},{"role":"assistant","content":"SELECT nh.contract_address,\n nh.token_id,\n nm.name,\n SUM(CAST(nh.amount AS bigint)) AS total_amount,\n COUNT(DISTINCT nh.wallet_address) AS holder_count\nFROM nft_holders nh\nJOIN nft_metadata nm\n ON nh.contract_address = nm.contract_address\n AND nh.token_id = nm.token_id\nWHERE nm.blockchain = 'Ethereum'\n AND nm.erc_type = 'ERC1155'\nGROUP BY nh.contract_address, nh.token_id, nm.name\nHAVING SUM(CAST(nh.amount AS bigint)) > 1000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.staff ( staff_id text, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level integer, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity integer, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\n","conversations":[{"role":"user","content":"List the full names and email addresses of staff members who have delivered at least one service order in the past 30 days, along with the count of orders they delivered. Sort by count descending."},{"role":"assistant","content":"SELECT st.staff_id,\n st.first_name || ' ' || st.last_name AS full_name,\n st.work_email,\n COUNT(so.order_id) AS delivered_count\nFROM hospitality_technology.staff st\nJOIN hospitality_technology.service_orders so\n ON st.staff_id = so.staff_id_delivered\nWHERE so.status = 'Delivered'\n AND so.delivery_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY st.staff_id, st.first_name, st.last_name, st.work_email\nORDER BY delivered_count DESC;"},{"role":"user","content":"Actually, only include staff who delivered more than 5 orders in that period."},{"role":"assistant","content":"SELECT st.staff_id,\n st.first_name || ' ' || st.last_name AS full_name,\n st.work_email,\n COUNT(so.order_id) AS delivered_count\nFROM hospitality_technology.staff st\nJOIN hospitality_technology.service_orders so\n ON st.staff_id = so.staff_id_delivered\nWHERE so.status = 'Delivered'\n AND so.delivery_timestamp >= CURRENT_DATE - INTERVAL '30 days'\nGROUP BY st.staff_id, st.first_name, st.last_name, st.work_email\nHAVING COUNT(so.order_id) > 5\nORDER BY delivered_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.notifications ( notification_id text PRIMARY KEY, citizen_id text, application_id text, message_subject text, message_body text, channel text, sent_at timestamp, status text, related_entity_type text, related_entity_id text )\n","conversations":[{"role":"user","content":"How many notifications have been sent per channel?"},{"role":"assistant","content":"SELECT channel,\n COUNT(*) AS notification_count\nFROM government_services.notifications\nGROUP BY channel;"},{"role":"user","content":"Exclude any notifications with status = 'Failed'."},{"role":"assistant","content":"SELECT channel,\n COUNT(*) AS notification_count\nFROM government_services.notifications\nWHERE status <> 'Failed'\nGROUP BY channel;"},{"role":"user","content":"Now only include channels that have more than 100 notifications."},{"role":"assistant","content":"SELECT channel,\n COUNT(*) AS notification_count\nFROM government_services.notifications\nWHERE status <> 'Failed'\nGROUP BY channel\nHAVING COUNT(*) > 100;"},{"role":"user","content":"Order the results by notification_count descending and limit to the top 3 channels."},{"role":"assistant","content":"SELECT channel,\n COUNT(*) AS notification_count\nFROM government_services.notifications\nWHERE status <> 'Failed'\nGROUP BY channel\nHAVING COUNT(*) > 100\nORDER BY notification_count DESC\nLIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )\nCREATE TABLE token_basic_info ( coin_id.text, token_name.text, token_symbol.text, token_address.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, highest_price_24h.numeric, lowest_price_24h.numeric, market_cap.numeric, market_cap_rank.numeric, market_cap_change_percentage_24h.text, total_volume.text, narrative.text, trend_rank.numeric )\nCREATE TABLE token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )\nCREATE TABLE cex_token_balance ( snapshot_time.text, chain.text, address.text, exchange.text, token_address.text, token_symbol.text, balance.numeric, usd_value.numeric, price.numeric )\nCREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )\n","conversations":[{"role":"user","content":"Show all tokens on the Ethereum chain in token_dexpool_info that had a price increase in the last 6 hours, along with their 24h trading volume and smart money ROI."},{"role":"assistant","content":"SELECT td.token_symbol,\n td.price_change_percentage_6h,\n td.volume_24h,\n smtp.roi\nFROM token_dexpool_info AS td\nJOIN smart_money_token_performance AS smtp\n ON td.token_symbol = smtp.token_symbol\n AND td.chain = smtp.chain\nWHERE td.chain = 'Ethereum'\n AND td.price_change_percentage_6h > 0;"},{"role":"user","content":"I only want tokens with liquidity over 1,000,000 and ROI above 1. Show the price_change_24h as well."},{"role":"assistant","content":"SELECT td.token_symbol,\n td.price_change_percentage_6h,\n td.price_change_percentage_24h,\n td.volume_24h,\n td.liquidity,\n smtp.roi\nFROM token_dexpool_info AS td\nJOIN smart_money_token_performance AS smtp\n ON td.token_symbol = smtp.token_symbol\n AND td.chain = smtp.chain\nWHERE td.chain = 'Ethereum'\n AND td.price_change_percentage_6h > 0\n AND td.liquidity > 1000000\n AND smtp.roi > 1;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id.text, customer_id.text, product_id.text, agent_id.text, policy_number.text, start_date.date, end_date.date, premium_amount.numeric, coverage_limit.numeric, deductible.numeric, status.text, issued_at.timestamp, cancellation_date.date, cancellation_reason.text )\nCREATE TABLE insurance.claims ( claim_id.text, policy_id.text, customer_id.text, incident_date.timestamp, reported_date.timestamp, description.text, estimated_loss.numeric, status.text, settlement_amount.numeric, settlement_date.date, claim_handler_id.text, police_report_number.text )\nCREATE TABLE insurance.premium_payments ( payment_id.text, policy_id.text, customer_id.text, payment_date.timestamp, amount_paid.numeric, payment_method.text, transaction_reference.text, due_date.date, payment_period_start.date, payment_period_end.date, status.text )\n","conversations":[{"role":"user","content":"Show me all claims with police reports that were filed in the last 3 months, along with their policy details and estimated loss amounts."},{"role":"assistant","content":"SELECT cl.claim_id, cl.policy_id, cl.estimated_loss, cl.incident_date, cl.reported_date, p.premium_amount, p.coverage_limit FROM insurance.claims cl JOIN insurance.policies p ON cl.policy_id = p.policy_id WHERE cl.police_report_number IS NOT NULL AND cl.reported_date >= CURRENT_DATE - INTERVAL '3 months';"},{"role":"user","content":"I also want to see the customer's name and the product type for these policies."},{"role":"assistant","content":"SELECT cl.claim_id, cl.policy_id, cl.estimated_loss, cl.incident_date, cl.reported_date, p.premium_amount, p.coverage_limit, c.first_name AS customer_first_name, c.last_name AS customer_last_name, pr.product_type FROM insurance.claims cl JOIN insurance.policies p ON cl.policy_id = p.policy_id JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.products pr ON p.product_id = pr.product_id WHERE cl.police_report_number IS NOT NULL AND cl.reported_date >= CURRENT_DATE - INTERVAL '3 months';"},{"role":"user","content":"Now filter these results to only show claims where the estimated loss is above $10,000 and sort them by estimated loss in descending order."},{"role":"assistant","content":"SELECT cl.claim_id, cl.policy_id, cl.estimated_loss, cl.incident_date, cl.reported_date, p.premium_amount, p.coverage_limit, c.first_name AS customer_first_name, c.last_name AS customer_last_name, pr.product_type FROM insurance.claims cl JOIN insurance.policies p ON cl.policy_id = p.policy_id JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.products pr ON p.product_id = pr.product_id WHERE cl.police_report_number IS NOT NULL AND cl.reported_date >= CURRENT_DATE - INTERVAL '3 months' AND cl.estimated_loss > 10000 ORDER BY cl.estimated_loss DESC;"},{"role":"user","content":"Finally, include the count of premium payments made for each of these policies and show only policies with at least 3 payments."},{"role":"assistant","content":"SELECT cl.claim_id, cl.policy_id, cl.estimated_loss, cl.incident_date, cl.reported_date, p.premium_amount, p.coverage_limit, c.first_name AS customer_first_name, c.last_name AS customer_last_name, pr.product_type, COUNT(pp.payment_id) AS payment_count FROM insurance.claims cl JOIN insurance.policies p ON cl.policy_id = p.policy_id JOIN insurance.customers c ON p.customer_id = c.customer_id JOIN insurance.products pr ON p.product_id = pr.product_id LEFT JOIN insurance.premium_payments pp ON p.policy_id = pp.policy_id WHERE cl.police_report_number IS NOT NULL AND cl.reported_date >= CURRENT_DATE - INTERVAL '3 months' AND cl.estimated_loss > 10000 GROUP BY cl.claim_id, cl.policy_id, cl.estimated_loss, cl.incident_date, cl.reported_date, p.premium_amount, p.coverage_limit, c.first_name, c.last_name, pr.product_type HAVING COUNT(pp.payment_id) >= 3 ORDER BY cl.estimated_loss DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id text, patient_id text, doctor_id text, appointment_time timestamp, duration_minutes integer, reason text, status text, location_id text, notes text, created_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n","conversations":[{"role":"user","content":"I need to find patients who received prescriptions within 7 days after their latest appointment. Show patient_id, first and last name, appointment_time, prescription_date, and medication_name."},{"role":"assistant","content":"WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id"},{"role":"user","content":"Actually, restrict it to prescriptions where dosage contains 'mg'."},{"role":"assistant","content":"WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\n AND pr.dosage LIKE '%mg%'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id"},{"role":"user","content":"Also, sort the results by prescription_date descending and limit to 5."},{"role":"assistant","content":"WITH latest_appt AS (\n SELECT patient_id, MAX(appointment_time) AS latest_time\n FROM healthcare.appointments\n GROUP BY patient_id\n)\nSELECT p.patient_id,\n p.first_name,\n p.last_name,\n la.latest_time AS appointment_time,\n pr.prescription_date,\n m.medication_name\nFROM latest_appt la\nJOIN healthcare.patients p\n ON p.patient_id = la.patient_id\nJOIN healthcare.prescriptions pr\n ON pr.patient_id = la.patient_id\n AND pr.prescription_date BETWEEN la.latest_time AND la.latest_time + INTERVAL '7 days'\n AND pr.dosage LIKE '%mg%'\nJOIN healthcare.medications m\n ON m.medication_id = pr.medication_id\nORDER BY pr.prescription_date DESC\nLIMIT 5"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record\/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions\/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment\/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions (\n prescription_id character varying(64) NOT NULL, -- unique identifier for the prescription\n record_id character varying(64) NOT NULL, -- FK linking to the medical record where it was prescribed\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to prescribing doctor\n medication_id character varying(64) NOT NULL, -- FK to medications table\n dosage character varying(100) NOT NULL, -- e.g., '100mg', '1 tablet'\n frequency character varying(100) NOT NULL, -- e.g., 'Once daily', 'Twice a day with meals'\n route character varying(50), -- e.g., 'Oral', 'Topical', 'Intravenous'\n start_date date NOT NULL, -- date prescription begins\n end_date date, -- date prescription ends (if applicable)\n quantity_dispensed numeric(10,2), -- amount dispensed (e.g., number of tablets)\n refills_allowed integer NOT NULL DEFAULT 0, -- number of allowed refills\n prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (prescription_id)\n)\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\n","conversations":[{"role":"user","content":"Show me all patients who have been prescribed medications with dosage greater than 100mg, along with their full names and the medication details, including the prescribing doctor's last name."},{"role":"assistant","content":"SELECT p.first_name, p.last_name, m.medication_name, m.generic_name, pr.dosage, d.last_name AS doctor_last_name FROM healthcare.patients p JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id JOIN healthcare.medications m ON pr.medication_id = m.medication_id JOIN healthcare.doctors d ON pr.doctor_id = d.doctor_id WHERE pr.dosage LIKE '%100mg%' OR CAST(SUBSTRING(pr.dosage FROM '([0-9]+)') AS INTEGER) > 100;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id text, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.trips ( trip_id text, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count integer, cargo_manifest_id text )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading integer, location_id text )\nCREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n","conversations":[{"role":"user","content":"List all fuel logs where the fuel type is diesel and the quantity is more than 50 liters, including the vehicle ID and total cost."},{"role":"assistant","content":"SELECT fuel_log_id, vehicle_id, trip_id, log_timestamp, quantity, total_cost FROM transportation.fuel_logs WHERE fuel_type = 'diesel' AND quantity > 50 AND unit = 'liters';"},{"role":"user","content":"Can you also include the trip ID and order the results by the most expensive fuel logs first?"},{"role":"assistant","content":"SELECT fuel_log_id, vehicle_id, trip_id, log_timestamp, quantity, total_cost FROM transportation.fuel_logs WHERE fuel_type = 'diesel' AND quantity > 50 AND unit = 'liters' ORDER BY total_cost DESC;"},{"role":"user","content":"Now filter these results to only show logs from the last 30 days."},{"role":"assistant","content":"SELECT fuel_log_id, vehicle_id, trip_id, log_timestamp, quantity, total_cost FROM transportation.fuel_logs WHERE fuel_type = 'diesel' AND quantity > 50 AND unit = 'liters' AND log_timestamp >= CURRENT_DATE - INTERVAL '30 days' ORDER BY total_cost DESC;"},{"role":"user","content":"There seems to be a typo in your SQL - it should be 'INTERVAL' not 'INTERVAL'. Also, can you include the location name where the fueling occurred?"},{"role":"assistant","content":"SELECT fl.fuel_log_id, fl.vehicle_id, fl.trip_id, fl.log_timestamp, fl.quantity, fl.total_cost, l.name AS location_name FROM transportation.fuel_logs fl LEFT JOIN transportation.locations l ON fl.location_id = l.location_id WHERE fl.fuel_type = 'diesel' AND fl.quantity > 50 AND fl.unit = 'liters' AND fl.log_timestamp >= CURRENT_DATE - INTERVAL '30 days' ORDER BY fl.total_cost DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America\/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.service_orders ( order_id text PRIMARY KEY, reservation_id text, guest_id text, service_id text, staff_id_ordered text, staff_id_delivered text, order_timestamp timestamp, delivery_timestamp timestamp, quantity int, unit_price numeric, total_price numeric, status text, notes text, bill_id text )\nCREATE TABLE hospitality_technology.reviews ( review_id text, property_id text, reservation_id text, guest_id text, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source text, review_date timestamp, is_public boolean, staff_response text, response_staff_id text, response_date timestamp )\n","conversations":[{"role":"user","content":"List all staff members who have responded to at least one review in the last 6 months, including their first and last names and the count of responses."},{"role":"assistant","content":"SELECT s.staff_id, s.first_name, s.last_name, COUNT(r.review_id) AS response_count\nFROM hospitality_technology.reviews AS r\nJOIN hospitality_technology.staff AS s\n ON r.response_staff_id = s.staff_id\nWHERE r.response_date >= CURRENT_DATE - INTERVAL '6 months'\nGROUP BY s.staff_id, s.first_name, s.last_name;"},{"role":"user","content":"Actually, only include responses to public reviews."},{"role":"assistant","content":"SELECT s.staff_id, s.first_name, s.last_name, COUNT(r.review_id) AS response_count\nFROM hospitality_technology.reviews AS r\nJOIN hospitality_technology.staff AS s\n ON r.response_staff_id = s.staff_id\nWHERE r.response_date >= CURRENT_DATE - INTERVAL '6 months'\n AND r.is_public = TRUE\nGROUP BY s.staff_id, s.first_name, s.last_name;"},{"role":"user","content":"Also include the average response time in days for each staff member."},{"role":"assistant","content":"SELECT s.staff_id, s.first_name, s.last_name,\n COUNT(r.review_id) AS response_count,\n AVG(EXTRACT(EPOCH FROM (r.response_date - r.review_date)) \/ 86400) AS avg_response_days\nFROM hospitality_technology.reviews AS r\nJOIN hospitality_technology.staff AS s\n ON r.response_staff_id = s.staff_id\nWHERE r.response_date >= CURRENT_DATE - INTERVAL '6 months'\n AND r.is_public = TRUE\nGROUP BY s.staff_id, s.first_name, s.last_name;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text )\nCREATE TABLE erc20_balances ( block_number.bigint, contract_address.text, wallet_address.text, amount.text, pk.text )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE nft_metadata ( blockchain.text, contract_address.text, token_id.text, contract_name.text, erc_type.text, amount.bigint, minter.text, owner.text, mint_block_number.bigint, mint_time.bigint, mint_transaction_hash.text, mint_price.text, token_uri.text, metadata.text, name.text, image_uri.text, traits.text, updated_at.bigint, status.text, rarity_score.real, rarity_rank.integer, unique_attribute_count.integer, pk.integer )\nCREATE TABLE nft_collections ( blockchain.text, contract_address.text, name.text, symbol.text, deploy_block_number.bigint, deploy_block_time.bigint, erc_type.text, owner.text, traits.text, description.text, slug.text, media_info.text, image_url.text, banner_image_url.text, updated_at.bigint, banner.text, token_count.bigint, floor_price.text, floor_price_symbol.text, floor_price_contract.text, pk.integer )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address.text, table_id.text, key_bytes.text, key0.text, key1.text, static_data.text, encoded_lengths.text, dynamic_data.text, is_deleted.boolean, block_number.bigint, log_index.bigint )\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number.bigint, block_timestamp.timestamp, tick.text, wallet_address.text, total_supply.decimal, amount.decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )\n","conversations":[{"role":"user","content":"Show me all wallet addresses that hold more than 100 of any ERC1155 token, along with the token ID and amount, but only include tokens from collections with a floor price greater than 0.1 ETH."},{"role":"assistant","content":"SELECT nh.wallet_address, nh.token_id, nh.amount FROM nft_holders nh JOIN nft_collections nc ON nh.contract_address = nc.contract_address WHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS decimal) > 100 AND nc.floor_price > '0.1' AND nc.floor_price_symbol = 'ETH';"},{"role":"user","content":"Can you also include the name and image URI of each token from the nft_metadata table?"},{"role":"assistant","content":"SELECT nh.wallet_address, nh.token_id, nh.amount, nm.name, nm.image_uri FROM nft_holders nh JOIN nft_collections nc ON nh.contract_address = nc.contract_address JOIN nft_metadata nm ON nh.contract_address = nm.contract_address AND nh.token_id = nm.token_id WHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS decimal) > 100 AND nc.floor_price > '0.1' AND nc.floor_price_symbol = 'ETH';"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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 )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n","conversations":[{"role":"user","content":"Which token has the highest net USD value difference between buys and sells? Show token_symbol, chain, narrative, average buy price, average sell price, and the net difference."},{"role":"assistant","content":"WITH buys AS (\n SELECT token_address, token_symbol, chain, narrative,\n SUM(usd_value) AS total_buy_usd,\n AVG(avg_price) AS avg_buy_price\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY token_address, token_symbol, chain, narrative\n),\nsells AS (\n SELECT token_address, chain,\n SUM(usd_value) AS total_sell_usd,\n AVG(avg_price) AS avg_sell_price\n FROM smart_money_token_inflow\n WHERE type = 2\n GROUP BY token_address, chain\n)\nSELECT b.token_symbol,\n b.chain,\n b.narrative,\n b.avg_buy_price,\n s.avg_sell_price,\n (b.total_buy_usd - s.total_sell_usd) AS net_difference\nFROM buys b\nJOIN sells s\n ON b.token_address = s.token_address\n AND b.chain = s.chain\nORDER BY net_difference DESC\nLIMIT 1;"},{"role":"user","content":"Could you list the top 5 tokens instead of just the top one?"},{"role":"assistant","content":"WITH buys AS (\n SELECT token_address, token_symbol, chain, narrative,\n SUM(usd_value) AS total_buy_usd,\n AVG(avg_price) AS avg_buy_price\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY token_address, token_symbol, chain, narrative\n),\nsells AS (\n SELECT token_address, chain,\n SUM(usd_value) AS total_sell_usd,\n AVG(avg_price) AS avg_sell_price\n FROM smart_money_token_inflow\n WHERE type = 2\n GROUP BY token_address, chain\n)\nSELECT b.token_symbol,\n b.chain,\n b.narrative,\n b.avg_buy_price,\n s.avg_sell_price,\n (b.total_buy_usd - s.total_sell_usd) AS net_difference\nFROM buys b\nJOIN sells s\n ON b.token_address = s.token_address\n AND b.chain = s.chain\nORDER BY net_difference DESC\nLIMIT 5;"},{"role":"user","content":"Only include tokens where the average sell price is at least twice the average buy price."},{"role":"assistant","content":"WITH buys AS (\n SELECT token_address, token_symbol, chain, narrative,\n SUM(usd_value) AS total_buy_usd,\n AVG(avg_price) AS avg_buy_price\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY token_address, token_symbol, chain, narrative\n),\nsells AS (\n SELECT token_address, chain,\n SUM(usd_value) AS total_sell_usd,\n AVG(avg_price) AS avg_sell_price\n FROM smart_money_token_inflow\n WHERE type = 2\n GROUP BY token_address, chain\n)\nSELECT b.token_symbol,\n b.chain,\n b.narrative,\n b.avg_buy_price,\n s.avg_sell_price,\n (b.total_buy_usd - s.total_sell_usd) AS net_difference\nFROM buys b\nJOIN sells s\n ON b.token_address = s.token_address\n AND b.chain = s.chain\nWHERE s.avg_sell_price >= 2 * b.avg_buy_price\nORDER BY net_difference DESC\nLIMIT 5;"},{"role":"user","content":"Also filter to narratives where total buy USD value is greater than 100000."},{"role":"assistant","content":"WITH buys AS (\n SELECT token_address, token_symbol, chain, narrative,\n SUM(usd_value) AS total_buy_usd,\n AVG(avg_price) AS avg_buy_price\n FROM smart_money_token_inflow\n WHERE type = 1\n GROUP BY token_address, token_symbol, chain, narrative\n),\nSells AS (\n SELECT token_address, chain,\n SUM(usd_value) AS total_sell_usd,\n AVG(avg_price) AS avg_sell_price\n FROM smart_money_token_inflow\n WHERE type = 2\n GROUP BY token_address, chain\n)\nSELECT b.token_symbol,\n b.chain,\n b.narrative,\n b.avg_buy_price,\n s.avg_sell_price,\n (b.total_buy_usd - s.total_sell_usd) AS net_difference\nFROM buys b\nJOIN sells s\n ON b.token_address = s.token_address\n AND b.chain = s.chain\nWHERE s.avg_sell_price >= 2 * b.avg_buy_price\n AND b.total_buy_usd > 100000\nORDER BY net_difference DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\n","conversations":[{"role":"user","content":"Show me all policies that expired in the last 60 days, along with their product IDs and premium amounts."},{"role":"assistant","content":"SELECT policy_id, product_id, premium_amount FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE;"},{"role":"user","content":"Now include only policies that had a deductible of $1000 or more."},{"role":"assistant","content":"SELECT policy_id, product_id, premium_amount, deductible FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE AND deductible >= 1000;"},{"role":"user","content":"I also want to see the count of such expired policies per product ID."},{"role":"assistant","content":"SELECT product_id, COUNT(*) as policy_count FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE AND deductible >= 1000 GROUP BY product_id ORDER BY policy_count DESC;"},{"role":"user","content":"Finally, show me the average premium amount for these expired high-deductible policies grouped by product ID."},{"role":"assistant","content":"SELECT product_id, AVG(premium_amount) as avg_premium FROM insurance.policies WHERE status = 'expired' AND end_date >= CURRENT_DATE - INTERVAL '60 days' AND end_date <= CURRENT_DATE AND deductible >= 1000 GROUP BY product_id ORDER BY avg_premium DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\n","conversations":[{"role":"user","content":"List all pairs of fuel log entries for the same vehicle that occurred more than 7 days apart, showing vehicle_id, first_log_id, second_log_id, and the time difference in days."},{"role":"assistant","content":"SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))\/86400 AS days_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days';"},{"role":"user","content":"Now filter to only include pairs where the quantity increased by at least 50 units."},{"role":"assistant","content":"SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))\/86400 AS days_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days'\nWHERE (f2.quantity - f1.quantity) >= 50;"},{"role":"user","content":"Also display the difference in total_cost between the two logs."},{"role":"assistant","content":"SELECT f1.vehicle_id,\n f1.fuel_log_id AS first_log_id,\n f2.fuel_log_id AS second_log_id,\n EXTRACT(EPOCH FROM (f2.log_timestamp - f1.log_timestamp))\/86400 AS days_difference,\n (f2.quantity - f1.quantity) AS quantity_difference,\n (f2.total_cost - f1.total_cost) AS cost_difference\nFROM transportation.fuel_logs f1\nJOIN transportation.fuel_logs f2\n ON f1.vehicle_id = f2.vehicle_id\n AND f2.log_timestamp > f1.log_timestamp + INTERVAL '7 days'\nWHERE (f2.quantity - f1.quantity) >= 50;"}]} +{"system":"You are an SQL statement expert and you can refuse the user's question if the question is not related to the table structure. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE 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) )\n","conversations":[{"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."}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.employees (\n employee_id character varying(64) NOT NULL, -- unique identifier for the employee\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n job_title character varying(100) NOT NULL, -- e.g., Teller, Branch Manager, Financial Advisor, Analyst\n department character varying(100), -- e.g., Retail Banking, Wealth Management, IT\n branch_id character varying(64), -- Identifier for the branch they work at (if applicable)\n email character varying(128) NOT NULL UNIQUE,\n phone_extension character varying(20),\n hire_date date NOT NULL,\n termination_date date, -- Date of termination, null if currently employed\n manager_id character varying(64), -- Self-referencing key for manager relationship\n status character varying(32) NOT NULL, -- e.g., Active, Terminated, On Leave\n PRIMARY KEY (employee_id),\n FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), -- Assuming a branches table exists\n FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id)\n)\n","conversations":[{"role":"user","content":"Give me a count of employees hired in each department for employees currently active or terminated."},{"role":"assistant","content":"SELECT department, status, COUNT(employee_id) AS employee_count FROM financial_services.employees WHERE status IN ('Active', 'Terminated') GROUP BY department, status;"},{"role":"user","content":"For the terminated employees in those departments, also include the average tenure in days, considering only those with a termination date."},{"role":"assistant","content":"SELECT department, SUM(CASE WHEN status = 'Active' THEN 1 ELSE 0 END) AS active_count, SUM(CASE WHEN status = 'Terminated' THEN 1 ELSE 0 END) AS terminated_count, AVG(CASE WHEN status = 'Terminated' AND termination_date IS NOT NULL THEN EXTRACT(EPOCH FROM (termination_date - hire_date)) \/ 86400.0 ELSE NULL END) AS avg_terminated_tenure_days FROM financial_services.employees GROUP BY department;"},{"role":"user","content":"Only show departments with more than 5 active employees and order by the active employee count descending."},{"role":"assistant","content":"SELECT department, SUM(CASE WHEN status = 'Active' THEN 1 ELSE 0 END) AS active_count, SUM(CASE WHEN status = 'Terminated' THEN 1 ELSE 0 END) AS terminated_count, AVG(CASE WHEN status = 'Terminated' AND termination_date IS NOT NULL THEN EXTRACT(EPOCH FROM (termination_date - hire_date)) \/ 86400.0 ELSE NULL END) AS avg_terminated_tenure_days FROM financial_services.employees GROUP BY department HAVING SUM(CASE WHEN status = 'Active' THEN 1 ELSE 0 END) > 5 ORDER BY active_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.drivers ( driver_id.text, employee_id.text, first_name.text, last_name.text, license_number.text, license_expiry_date.date, contact_number.text, email.text, hire_date.date, status.text )\n","conversations":[{"role":"user","content":"For each driver, show their driver_id, first_name, last_name, along with any other driver whose license_expiry_date is earlier than theirs."},{"role":"assistant","content":"SELECT d1.driver_id AS driver_id,\n d1.first_name,\n d1.last_name,\n d2.driver_id AS earlier_driver_id,\n d2.license_expiry_date AS earlier_expiry_date\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date < d1.license_expiry_date;"},{"role":"user","content":"Exclude pairs where the two expiry dates are not in the same calendar year."},{"role":"assistant","content":"SELECT d1.driver_id AS driver_id,\n d1.first_name,\n d1.last_name,\n d2.driver_id AS earlier_driver_id,\n d2.license_expiry_date AS earlier_expiry_date\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date < d1.license_expiry_date\n AND EXTRACT(YEAR FROM d1.license_expiry_date) = EXTRACT(YEAR FROM d2.license_expiry_date);"},{"role":"user","content":"Also only include pairs where the difference between their expiry dates is more than 30 days."},{"role":"assistant","content":"SELECT d1.driver_id AS driver_id,\n d1.first_name,\n d1.last_name,\n d2.driver_id AS earlier_driver_id,\n d2.license_expiry_date AS earlier_expiry_date,\n DATE_PART('day', d1.license_expiry_date - d2.license_expiry_date) AS days_difference\nFROM transportation.drivers d1\nJOIN transportation.drivers d2\n ON d2.license_expiry_date < d1.license_expiry_date\n AND EXTRACT(YEAR FROM d1.license_expiry_date) = EXTRACT(YEAR FROM d2.license_expiry_date)\nWHERE d1.license_expiry_date - d2.license_expiry_date > INTERVAL '30 days';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )\n","conversations":[{"role":"user","content":"Show the names and types of all assets whose symbol is exactly 3 characters long."},{"role":"assistant","content":"SELECT name, type, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3;"},{"role":"user","content":"Also, I want to order the results alphabetically by asset name."},{"role":"assistant","content":"SELECT name, type, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3 ORDER BY name ASC;"},{"role":"user","content":"Actually, can you only show assets of type 'token' in the result?"},{"role":"assistant","content":"SELECT name, type, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3 AND type = 'token' ORDER BY name ASC;"},{"role":"user","content":"Now, just return the asset name and symbol for these tokens, sorted by symbol descending."},{"role":"assistant","content":"SELECT name, symbol FROM trading_platform.assets WHERE LENGTH(symbol) = 3 AND type = 'token' ORDER BY symbol DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.assets ( asset_id character varying(64) NOT NULL, name character varying(128) NOT NULL, symbol character varying(32) NOT NULL, type character varying(32) NOT NULL, PRIMARY KEY (asset_id) )\nCREATE TABLE trading_platform.peers ( peer_id character varying(64) NOT NULL, ip_address character varying(15) NOT NULL, port integer NOT NULL, last_seen timestamp NOT NULL, PRIMARY KEY (peer_id) )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, status character varying(32) NOT NULL, reviewed_at timestamp NOT NULL, PRIMARY KEY (kyc_audit_id) )\n","conversations":[{"role":"user","content":"Show a list of all asset names along with the current KYC status of each user, including the asset symbol. Join the assets and kyc_audit tables."},{"role":"assistant","content":"SELECT a.name AS asset_name, a.symbol, k.user_id, k.status AS kyc_status \nFROM trading_platform.assets a\nJOIN trading_platform.kyc_audit k ON 1=1"},{"role":"user","content":"I only want the result for users whose KYC status is 'approved' and for assets where the symbol is at least 3 characters long."},{"role":"assistant","content":"SELECT a.name AS asset_name, a.symbol, k.user_id, k.status AS kyc_status \nFROM trading_platform.assets a\nJOIN trading_platform.kyc_audit k ON 1=1\nWHERE k.status = 'approved' AND LENGTH(a.symbol) >= 3"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id character varying(32) NOT NULL, -- fundraising record id project_id character varying(32) NOT NULL, -- the invested project's id project_name character varying(128) NOT NULL, -- name of the invested project rounds_name character varying(32), -- name of the fundraising round investment_value numeric(38,14), -- amount of the fundraising in USD investment_date character varying(128), -- the date of the investment happened introduction character varying(128), -- the introduction of the invested project valuation numeric(38,14), -- the valuation of the project in USD when invested )\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )\nCREATE TABLE cex_token_balance ( snapshot_time 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) )\nCREATE TABLE smart_money_profit ( address text, rank numeric, profit numeric, roi numeric, realized_ratio numeric, most_profit_token text, last_trade_time text, chain text )\nCREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )\nCREATE TABLE smart_money_token_inflow ( token_address.text, token_symbol.text, token_amount.numeric, usd_value.numeric, avg_price.numeric, type.numeric, address_amount.numeric, narrative.text, chain.text )\n","conversations":[{"role":"user","content":"What is the total USD value held by all centralized exchanges (CEX) for the token with the symbol 'BTC'?"},{"role":"assistant","content":"SELECT SUM(usd_value) AS total_btc_cex_value FROM cex_token_balance WHERE token_symbol = 'BTC';"},{"role":"user","content":"Can you break down the total USD value for 'BTC' held by CEXes by chain?"},{"role":"assistant","content":"SELECT chain, SUM(usd_value) AS total_btc_cex_value FROM cex_token_balance WHERE token_symbol = 'BTC' GROUP BY chain ORDER BY total_btc_cex_value DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\n","conversations":[{"role":"user","content":"Count the number of logs for each action type."},{"role":"assistant","content":"SELECT action,\n COUNT(*) AS count\nFROM trading_platform.logs\nGROUP BY action;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\n","conversations":[{"role":"user","content":"Can you show me all developers along with the year they were founded and their website, grouped by country?"},{"role":"assistant","content":"SELECT country, array_agg(name) AS developers, array_agg(founded_year) AS founded_years, array_agg(website) AS websites FROM gaming_technology.developers GROUP BY country;"},{"role":"user","content":"Can you add the number of developers per country to the result?"},{"role":"assistant","content":"SELECT country, COUNT(*) AS developer_count, array_agg(name) AS developers, array_agg(founded_year) AS founded_years, array_agg(website) AS websites FROM gaming_technology.developers GROUP BY country;"},{"role":"user","content":"I'd like to see only countries with at least two developers. Can you modify the query?"},{"role":"assistant","content":"SELECT country, COUNT(*) AS developer_count, array_agg(name) AS developers, array_agg(founded_year) AS founded_years, array_agg(website) AS websites FROM gaming_technology.developers GROUP BY country HAVING COUNT(*) >= 2;"},{"role":"user","content":"Actually, could you also include the earliest founded year of a developer in each country?"},{"role":"assistant","content":"SELECT country, COUNT(*) AS developer_count, MIN(founded_year) AS earliest_founded_year, array_agg(name) AS developers, array_agg(founded_year) AS founded_years, array_agg(website) AS websites FROM gaming_technology.developers GROUP BY country HAVING COUNT(*) >= 2;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.doctors ( doctor_id text, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id text, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed integer, prescription_date timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id text, plan_name text, insurance_provider text, plan_type text, contact_phone text, website text )\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id text, patient_id text, plan_id text, policy_number text, group_number text, subscriber_name text, effective_date date, expiration_date date, is_primary boolean )\n","conversations":[{"role":"user","content":"List patients who have appointments scheduled, their appointment time, the name of their primary insurance plan, and the provider name."},{"role":"assistant","content":"SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, a.appointment_time, ip.plan_name, ip.insurance_provider FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.patient_insurance AS pi ON p.patient_id = pi.patient_id JOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id WHERE pi.is_primary IS TRUE;"},{"role":"user","content":"Only show appointments scheduled after '2024-06-01'."},{"role":"assistant","content":"SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, a.appointment_time, ip.plan_name, ip.insurance_provider FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.patient_insurance AS pi ON p.patient_id = pi.patient_id JOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id WHERE pi.is_primary IS TRUE AND a.appointment_time > '2024-06-01';"},{"role":"user","content":"Further filter results to include only patients whose primary insurance plan type is 'PPO'."},{"role":"assistant","content":"SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, a.appointment_time, ip.plan_name, ip.insurance_provider FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.patient_insurance AS pi ON p.patient_id = pi.patient_id JOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id WHERE pi.is_primary IS TRUE AND a.appointment_time > '2024-06-01' AND ip.plan_type = 'PPO';"},{"role":"user","content":"Can you also include the doctor's full name for these appointments?"},{"role":"assistant","content":"SELECT p.first_name AS patient_first_name, p.last_name AS patient_last_name, a.appointment_time, d.first_name AS doctor_first_name, d.last_name AS doctor_last_name, ip.plan_name, ip.insurance_provider FROM healthcare.appointments AS a JOIN healthcare.patients AS p ON a.patient_id = p.patient_id JOIN healthcare.patient_insurance AS pi ON p.patient_id = pi.patient_id JOIN healthcare.insurance_plans AS ip ON pi.plan_id = ip.plan_id JOIN healthcare.doctors AS d ON a.doctor_id = d.doctor_id WHERE pi.is_primary IS TRUE AND a.appointment_time > '2024-06-01' AND ip.plan_type = 'PPO';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text PRIMARY KEY, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.claim_documents ( document_id text, claim_id text, document_type text, file_name text, file_path text, file_size_bytes integer, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n","conversations":[{"role":"user","content":"Show me all claim documents that are PDFs and were uploaded in the last 30 days, along with their claim IDs and file sizes."},{"role":"assistant","content":"SELECT cd.document_id, cd.claim_id, cd.file_size_bytes, c.policy_id FROM insurance.claim_documents cd JOIN insurance.claims c ON cd.claim_id = c.claim_id WHERE cd.mime_type = 'application\/pdf' AND cd.uploaded_at >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY);"},{"role":"user","content":"I also want to see the policy details for these claims, including the coverage limit and premium amount."},{"role":"assistant","content":"SELECT cd.document_id, cd.claim_id, cd.file_size_bytes, c.policy_id, p.coverage_limit, p.premium_amount FROM insurance.claim_documents cd JOIN insurance.claims c ON cd.claim_id = c.claim_id JOIN insurance.policies p ON c.policy_id = p.policy_id WHERE cd.mime_type = 'application\/pdf' AND cd.uploaded_at >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY);"},{"role":"user","content":"Now filter to only show documents larger than 1MB and include the upload date."},{"role":"assistant","content":"SELECT cd.document_id, cd.claim_id, cd.file_size_bytes, cd.uploaded_at, c.policy_id, p.coverage_limit, p.premium_amount FROM insurance.claim_documents cd JOIN insurance.claims c ON cd.claim_id = c.claim_id JOIN insurance.policies p ON c.policy_id = p.policy_id WHERE cd.mime_type = 'application\/pdf' AND cd.uploaded_at >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) AND cd.file_size_bytes > 1000000;"},{"role":"user","content":"Finally, show me the count of such PDF documents per policy, ordered by count descending."},{"role":"assistant","content":"SELECT c.policy_id, COUNT(cd.document_id) AS pdf_count FROM insurance.claim_documents cd JOIN insurance.claims c ON cd.claim_id = c.claim_id WHERE cd.mime_type = 'application\/pdf' AND cd.uploaded_at >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) AND cd.file_size_bytes > 1000000 GROUP BY c.policy_id ORDER BY pdf_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.doctors ( doctor_id text PRIMARY KEY, first_name text, last_name text, specialty text, license_number text, phone_number text, email text, hospital_affiliation_id text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.medical_records ( record_id text PRIMARY KEY, patient_id text, appointment_id text, doctor_id text, record_date timestamp, chief_complaint text, present_illness_history text, past_medical_history text, physical_examination_notes text, assessment text, treatment_plan text, vitals text, created_at timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications ( medication_id text PRIMARY KEY, medication_name text, generic_name text, manufacturer text, ndc_code text, description text )\nCREATE TABLE healthcare.prescriptions ( prescription_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, medication_id text, dosage text, frequency text, route text, start_date date, end_date date, quantity_dispensed numeric, refills_allowed int, prescription_date timestamp )\n","conversations":[{"role":"user","content":"Show me all patients who have received at least two different medications prescribed by doctors working at the same hospital. Include the patient full name, the medication names, and the shared hospital_affiliation_id."},{"role":"assistant","content":"SELECT DISTINCT p.patient_id, p.first_name, p.last_name, m1.medication_name AS medication1, m2.medication_name AS medication2, d.hospital_affiliation_id\nFROM healthcare.prescriptions pr1\nJOIN healthcare.prescriptions pr2 ON pr1.patient_id = pr2.patient_id AND pr1.medication_id <> pr2.medication_id\nJOIN healthcare.doctors d ON pr1.doctor_id = d.doctor_id AND pr2.doctor_id = d.doctor_id\nJOIN healthcare.patients p ON pr1.patient_id = p.patient_id\nJOIN healthcare.medications m1 ON pr1.medication_id = m1.medication_id\nJOIN healthcare.medications m2 ON pr2.medication_id = m2.medication_id\nWHERE d.hospital_affiliation_id IS NOT NULL;"},{"role":"user","content":"Can you only include records where both medications share the same generic name?"},{"role":"assistant","content":"SELECT DISTINCT p.patient_id, p.first_name, p.last_name, m1.medication_name AS medication1, m2.medication_name AS medication2, m1.generic_name, d.hospital_affiliation_id\nFROM healthcare.prescriptions pr1\nJOIN healthcare.prescriptions pr2 ON pr1.patient_id = pr2.patient_id AND pr1.medication_id <> pr2.medication_id\nJOIN healthcare.doctors d ON pr1.doctor_id = d.doctor_id AND pr2.doctor_id = d.doctor_id\nJOIN healthcare.patients p ON pr1.patient_id = p.patient_id\nJOIN healthcare.medications m1 ON pr1.medication_id = m1.medication_id\nJOIN healthcare.medications m2 ON pr2.medication_id = m2.medication_id\nWHERE d.hospital_affiliation_id IS NOT NULL AND m1.generic_name = m2.generic_name;"},{"role":"user","content":"Actually, only show those cases where the doctor specialty is 'Internal Medicine'."},{"role":"assistant","content":"SELECT DISTINCT p.patient_id, p.first_name, p.last_name, m1.medication_name AS medication1, m2.medication_name AS medication2, m1.generic_name, d.hospital_affiliation_id\nFROM healthcare.prescriptions pr1\nJOIN healthcare.prescriptions pr2 ON pr1.patient_id = pr2.patient_id AND pr1.medication_id <> pr2.medication_id\nJOIN healthcare.doctors d ON pr1.doctor_id = d.doctor_id AND pr2.doctor_id = d.doctor_id\nJOIN healthcare.patients p ON pr1.patient_id = p.patient_id\nJOIN healthcare.medications m1 ON pr1.medication_id = m1.medication_id\nJOIN healthcare.medications m2 ON pr2.medication_id = m2.medication_id\nWHERE d.hospital_affiliation_id IS NOT NULL AND m1.generic_name = m2.generic_name AND d.specialty = 'Internal Medicine';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_basic_info ( coin_id text, token_name text, token_symbol text, token_address text, chain text, price numeric, price_change_percentage_1h numeric, price_change_percentage_24h numeric, price_change_percentage_7d numeric, highest_price_24h numeric, lowest_price_24h numeric, market_cap numeric, market_cap_rank numeric, market_cap_change_percentage_24h text, total_volume text, narrative text, trend_rank numeric )\nCREATE TABLE narrative_info ( narrative.text, top_3_coins.text, price_change_percentage_1h.numeric, price_change_percentage_24h.numeric, price_change_percentage_7d.numeric, market_cap.numeric, volume_24h.numeric, trend_rank.numeric, token_num.numeric )\nCREATE TABLE smart_money_token_performance ( token_address text, token_symbol text, pnl numeric, net_flow numeric, avg_cost numeric, price numeric, realized_ratio numeric, roi numeric, chain text )\n","conversations":[{"role":"user","content":"Calculate the average market cap and average 24-hour trading volume for tokens belonging to each narrative category."},{"role":"assistant","content":"SELECT narrative, AVG(market_cap) AS average_market_cap, AVG(CAST(REPLACE(total_volume, ',', '') AS NUMERIC)) AS average_24h_volume FROM token_basic_info WHERE narrative IS NOT NULL AND total_volume IS NOT NULL GROUP BY narrative;"},{"role":"user","content":"Filter the results to only include narratives where the average market cap is greater than $1,000,000,000."},{"role":"assistant","content":"SELECT narrative, AVG(market_cap) AS average_market_cap, AVG(CAST(REPLACE(total_volume, ',', '') AS NUMERIC)) AS average_24h_volume FROM token_basic_info WHERE narrative IS NOT NULL AND total_volume IS NOT NULL GROUP BY narrative HAVING AVG(market_cap) > 1000000000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\n","conversations":[{"role":"user","content":"Can you show me the number of lawyers grouped by specialization?"},{"role":"assistant","content":"SELECT specialization, COUNT(*) AS lawyer_count FROM lawyers GROUP BY specialization;"},{"role":"user","content":"Include only specializations that have more than two lawyers."},{"role":"assistant","content":"SELECT specialization, COUNT(*) AS lawyer_count FROM lawyers GROUP BY specialization HAVING COUNT(*) > 2;"},{"role":"user","content":"Also show the average tenure in years for each of those specializations."},{"role":"assistant","content":"SELECT specialization, COUNT(*) AS lawyer_count, AVG(EXTRACT(EPOCH FROM (NOW() - hire_date)) \/ 31536000) AS avg_tenure_years FROM lawyers GROUP BY specialization HAVING COUNT(*) > 2;"},{"role":"user","content":"Order the result by average tenure in descending order."},{"role":"assistant","content":"SELECT specialization, COUNT(*) AS lawyer_count, AVG(EXTRACT(EPOCH FROM (NOW() - hire_date)) \/ 31536000) AS avg_tenure_years FROM lawyers GROUP BY specialization HAVING COUNT(*) > 2 ORDER BY avg_tenure_years DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\n","conversations":[{"role":"user","content":"Find all wallets that were created on the same day and list their wallet IDs, addresses, and the creation date."},{"role":"assistant","content":"SELECT w1.wallet_id, w1.address, w1.created_at::date AS creation_date FROM web3.wallets w1 JOIN (SELECT created_at::date AS creation_date FROM web3.wallets GROUP BY created_at::date HAVING COUNT(*) > 1) w2 ON w1.created_at::date = w2.creation_date ORDER BY creation_date, w1.wallet_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\nCREATE TABLE insurance.claim_documents ( document_id text PRIMARY KEY, claim_id text, document_type text, file_name text, file_path text, file_size_bytes int, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n","conversations":[{"role":"user","content":"Show me all policy beneficiaries who were added in the last 6 months, along with their policy details and percentage shares."},{"role":"assistant","content":"SELECT pb.*, pp.policy_id, pp.customer_id, pp.payment_date FROM insurance.policy_beneficiaries pb JOIN insurance.premium_payments pp ON pb.policy_id = pp.policy_id WHERE pb.added_at >= CURRENT_DATE - INTERVAL '6 months';"},{"role":"user","content":"Actually, I only want to see beneficiaries with a percentage share greater than 30% and include the payment method used for their policies."},{"role":"assistant","content":"SELECT pb.*, pp.policy_id, pp.customer_id, pp.payment_method FROM insurance.policy_beneficiaries pb JOIN insurance.premium_payments pp ON pb.policy_id = pp.policy_id WHERE pb.added_at >= CURRENT_DATE - INTERVAL '6 months' AND pb.percentage_share > 30;"},{"role":"user","content":"Now filter these results to only show beneficiaries who are children of the policyholder."},{"role":"assistant","content":"SELECT pb.*, pp.policy_id, pp.customer_id, pp.payment_method FROM insurance.policy_beneficiaries pb JOIN insurance.premium_payments pp ON pb.policy_id = pp.policy_id WHERE pb.added_at >= CURRENT_DATE - INTERVAL '6 months' AND pb.percentage_share > 30 AND pb.relationship = 'child';"},{"role":"user","content":"Finally, order the results by percentage share in descending order."},{"role":"assistant","content":"SELECT pb.*, pp.policy_id, pp.customer_id, pp.payment_method FROM insurance.policy_beneficiaries pb JOIN insurance.premium_payments pp ON pb.policy_id = pp.policy_id WHERE pb.added_at >= CURRENT_DATE - INTERVAL '6 months' AND pb.percentage_share > 30 AND pb.relationship = 'child' ORDER BY pb.percentage_share DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"List all NFT collections where the floor price is greater than 0.5 ETH, including their names and contract addresses."},{"role":"assistant","content":"SELECT name, contract_address FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH';"},{"role":"user","content":"Can you also include the banner image URL and filter to only show ERC721 collections?"},{"role":"assistant","content":"SELECT name, contract_address, banner_image_url FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721';"},{"role":"user","content":"Now sort these results by floor price in descending order and limit to the top 10."},{"role":"assistant","content":"SELECT name, contract_address, banner_image_url FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721' ORDER BY CAST(floor_price AS decimal) DESC LIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash text, transaction_index bigint, from_address text, contract_address text, symbol text, total_supply text, name text, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info text, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_coins_metadata ( object_id text, coin_type text, status text, decimals bigint, description text, icon_url text, symbol text, name text )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_collections ( blockchain text, contract_address text, name text, symbol text, deploy_block_number bigint, deploy_block_time bigint, erc_type text, owner text, traits text, description text, slug text, media_info text, image_url text, banner_image_url text, updated_at bigint, banner text, token_count bigint, floor_price text, floor_price_symbol text, floor_price_contract text, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text, pk integer )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply text, amount text )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"Show me all wallet addresses that hold more than 1000 of any ERC1155 token, along with the token ID and contract address."},{"role":"assistant","content":"SELECT nh.wallet_address, nh.token_id, nh.contract_address FROM nft_holders nh WHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS decimal) > 1000;"},{"role":"user","content":"Can you join this with the token_prices table to include the current price of each token?"},{"role":"assistant","content":"SELECT nh.wallet_address, nh.token_id, nh.contract_address, tp.price FROM nft_holders nh JOIN token_prices tp ON nh.contract_address = tp.address WHERE nh.contract_type = 'ERC1155' AND CAST(nh.amount AS decimal) > 1000;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claims ( claim_id text PRIMARY KEY, policy_id text, customer_id text, incident_date timestamp, reported_date timestamp, description text, estimated_loss numeric, status text, settlement_amount numeric, settlement_date date, claim_handler_id text, police_report_number text )\nCREATE TABLE insurance.insurance_products ( product_id text PRIMARY KEY, product_name text, product_type text, description text, base_premium numeric, coverage_details text, underwriting_rules text, is_active boolean, created_at timestamp, updated_at timestamp )\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id text PRIMARY KEY, policy_id text, customer_id text, first_name text, last_name text, relationship text, percentage_share numeric, contact_info text, added_at timestamp )\n","conversations":[{"role":"user","content":"Show me all insurance products along with the number of distinct agents whose handled claims are for policies using that product. Include product_id, product_name, and agent_count."},{"role":"assistant","content":"SELECT ip.product_id, ip.product_name, COUNT(DISTINCT c.claim_handler_id) AS agent_count\nFROM insurance.insurance_products ip\nJOIN insurance.claims c ON c.policy_id IN (\n SELECT policy_id FROM insurance.policy_beneficiaries WHERE policy_id IS NOT NULL\n)\nWHERE ip.product_id IS NOT NULL\nGROUP BY ip.product_id, ip.product_name;"},{"role":"user","content":"Can you also add only products that are currently active and sort by agent_count descending?"},{"role":"assistant","content":"SELECT ip.product_id, ip.product_name, COUNT(DISTINCT c.claim_handler_id) AS agent_count\nFROM insurance.insurance_products ip\nJOIN insurance.claims c ON c.policy_id IN (\n SELECT policy_id FROM insurance.policy_beneficiaries WHERE policy_id IS NOT NULL\n)\nWHERE ip.is_active = true\nGROUP BY ip.product_id, ip.product_name\nORDER BY agent_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid PRIMARY KEY, player_id uuid, game_id uuid, server_id uuid, start_time timestamptz, end_time timestamptz, duration_seconds int, score int, session_data jsonb )\nCREATE TABLE gaming_technology.servers ( server_id.uuid, game_id.uuid, server_name.text, region.text, ip_address.text, port.integer, current_players.integer, max_players.integer, status.text, last_heartbeat.timestamptz )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n","conversations":[{"role":"user","content":"For each game, I need a breakdown of how many sessions each server has hosted and what percentage of that game's total sessions each server represents. Display game_id, server_id, server_name, session_count, and session_percentage."},{"role":"assistant","content":"```sql\nSELECT\n gs.game_id,\n s.server_id,\n s.server_name,\n COUNT(*) AS session_count,\n ROUND(\n COUNT(*) * 100.0\n \/ SUM(COUNT(*)) OVER (PARTITION BY gs.game_id),\n 2\n ) AS session_percentage\nFROM gaming_technology.game_sessions gs\nJOIN gaming_technology.servers s\n ON gs.server_id = s.server_id\nGROUP BY\n gs.game_id,\n s.server_id,\n s.server_name;\n```"},{"role":"user","content":"Exclude any servers that have hosted fewer than 10 sessions."},{"role":"assistant","content":"```sql\nSELECT\n gs.game_id,\n s.server_id,\n s.server_name,\n COUNT(*) AS session_count,\n ROUND(\n COUNT(*) * 100.0\n \/ SUM(COUNT(*)) OVER (PARTITION BY gs.game_id),\n 2\n ) AS session_percentage\nFROM gaming_technology.game_sessions gs\nJOIN gaming_technology.servers s\n ON gs.server_id = s.server_id\nGROUP BY\n gs.game_id,\n s.server_id,\n s.server_name\nHAVING\n COUNT(*) >= 10;\n```"},{"role":"user","content":"Also order the results by game_id and then by session_percentage descending."},{"role":"assistant","content":"```sql\nSELECT\n gs.game_id,\n s.server_id,\n s.server_name,\n COUNT(*) AS session_count,\n ROUND(\n COUNT(*) * 100.0\n \/ SUM(COUNT(*)) OVER (PARTITION BY gs.game_id),\n 2\n ) AS session_percentage\nFROM gaming_technology.game_sessions gs\nJOIN gaming_technology.servers s\n ON gs.server_id = s.server_id\nGROUP BY\n gs.game_id,\n s.server_id,\n s.server_name\nHAVING\n COUNT(*) >= 10\nORDER BY\n gs.game_id,\n session_percentage DESC;\n```"},{"role":"user","content":"Actually, I only care about servers in the 'Europe' and 'Asia' regions. Can you filter the query accordingly?"},{"role":"assistant","content":"```sql\nSELECT\n gs.game_id,\n s.server_id,\n s.server_name,\n COUNT(*) AS session_count,\n ROUND(\n COUNT(*) * 100.0\n \/ SUM(COUNT(*)) OVER (PARTITION BY gs.game_id),\n 2\n ) AS session_percentage\nFROM gaming_technology.game_sessions gs\nJOIN gaming_technology.servers s\n ON gs.server_id = s.server_id\nWHERE\n s.region IN ('Europe', 'Asia')\nGROUP BY\n gs.game_id,\n s.server_id,\n s.server_name\nHAVING\n COUNT(*) >= 10\nORDER BY\n gs.game_id,\n session_percentage DESC;\n```"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.accounts ( account_id text, customer_id text, account_number text, account_type text, balance numeric, currency text, opened_date date, status text, interest_rate numeric, last_updated_at timestamp )\nCREATE TABLE financial_services.securities ( security_id.text, ticker_symbol.text, isin_code.text, cusip_code.text, security_name.text, security_type.text, exchange.text, currency.text, issuer_name.text, sector.text, last_updated.timestamp )\nCREATE TABLE financial_services.trades ( trade_id text, account_id text, security_id text, order_id text, trade_type text, quantity numeric, price_per_unit numeric, total_amount numeric, commission numeric, trade_timestamp timestamp, settlement_date date, status text, execution_venue text )\nCREATE TABLE financial_services.market_data ( data_point_id.bigint, security_id.text, data_timestamp.timestamp, open_price.numeric, high_price.numeric, low_price.numeric, close_price.numeric, adjusted_close_price.numeric, volume.bigint, source.text )\nCREATE TABLE financial_services.employees ( employee_id text, first_name text, last_name text, job_title text, department text, branch_id text, email text, phone_extension text, hire_date date, termination_date date, manager_id text, status text )\n","conversations":[{"role":"user","content":"List all securities (security_id, ticker_symbol, security_name) that are traded on the NASDAQ exchange and have a daily trading volume exceeding 1 million shares, along with the employee details (employee_id, first_name, last_name) who last updated these securities."},{"role":"assistant","content":"SELECT s.security_id, s.ticker_symbol, s.security_name, e.employee_id, e.first_name, e.last_name FROM financial_services.securities s JOIN financial_services.employees e ON s.last_updated = e.hire_date WHERE s.exchange = 'NASDAQ' AND s.security_id IN (SELECT security_id FROM financial_services.market_data WHERE volume > 1000000);"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n","conversations":[{"role":"user","content":"Which token symbols have the highest number of addresses buying them on the Ethereum chain? Show the top 3 symbols, their total address_amount, and narrative."},{"role":"assistant","content":"SELECT token_symbol, narrative, SUM(address_amount) AS total_buying_addresses\nFROM smart_money_token_inflow\nWHERE type = 1 AND chain = 'Ethereum'\nGROUP BY token_symbol, narrative\nORDER BY total_buying_addresses DESC\nLIMIT 3;"},{"role":"user","content":"I got incorrect results. I only want results where the summed address_amount is at least 10."},{"role":"assistant","content":"SELECT token_symbol, narrative, SUM(address_amount) AS total_buying_addresses\nFROM smart_money_token_inflow\nWHERE type = 1 AND chain = 'Ethereum'\nGROUP BY token_symbol, narrative\nHAVING SUM(address_amount) >= 10\nORDER BY total_buying_addresses DESC\nLIMIT 3;"},{"role":"user","content":"Please add the total usd_value spent on buying each of these tokens."},{"role":"assistant","content":"SELECT token_symbol, narrative, SUM(address_amount) AS total_buying_addresses, SUM(usd_value) AS total_buy_usd_value\nFROM smart_money_token_inflow\nWHERE type = 1 AND chain = 'Ethereum'\nGROUP BY token_symbol, narrative\nHAVING SUM(address_amount) >= 10\nORDER BY total_buying_addresses DESC\nLIMIT 3;"},{"role":"user","content":"Also include the average price (avg_price) for each token."},{"role":"assistant","content":"SELECT token_symbol, narrative, SUM(address_amount) AS total_buying_addresses, SUM(usd_value) AS total_buy_usd_value, AVG(avg_price) AS average_price\nFROM smart_money_token_inflow\nWHERE type = 1 AND chain = 'Ethereum'\nGROUP BY token_symbol, narrative\nHAVING SUM(address_amount) >= 10\nORDER BY total_buying_addresses DESC\nLIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, -- the id of dexpool token_name character varying(100) NOT NULL, -- the name of the token in the dexpool token_symbol character varying(100) NOT NULL, -- the token's symbol chain text, -- the chain that the dexpool resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours makers_24h double precision, -- the makers of the dex pool in 24 hours volume_24h double precision, -- the trade volume of the dex pool in 24 hours liquidity double precision, -- the liquidity of the dex pool market_cap double precision, -- the market cap of the token trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token. ,PRIMARY KEY (pair_address, chain) )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol pnl numeric(38,2), -- the profit users made on this token net_flow numeric(38,2), -- the netflow of the token, means the money user spent minus the the money user sold of this token avg_cost numeric(38,16), -- the average cost price of user spent on this token price double precision, -- the current price of the token realized_ratio numeric(10,2), -- the ratio user sold of the token roi numeric(10,2), -- the roi users made of this token chain character varying(100), -- the chain that the token resides PRIMARY KEY (token_address, chain) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n","conversations":[{"role":"user","content":"Show me the top 5 tokens by 24-hour trading volume on the Ethereum chain, along with their narrative and 7-day price change percentage."},{"role":"assistant","content":"SELECT t.token_symbol, t.narrative, t.price_change_percentage_7d FROM token_basic_info t WHERE t.chain = 'Ethereum' ORDER BY CAST(t.total_volume AS numeric) DESC LIMIT 5;"},{"role":"user","content":"Can you also include their liquidity from the token_dexpool_info table?"},{"role":"assistant","content":"SELECT t.token_symbol, t.narrative, t.price_change_percentage_7d, d.liquidity FROM token_basic_info t JOIN token_dexpool_info d ON t.token_symbol = d.token_symbol AND t.chain = d.chain WHERE t.chain = 'Ethereum' ORDER BY CAST(t.total_volume AS numeric) DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients (\n patient_id character varying(64) NOT NULL, -- unique identifier for the patient\n first_name character varying(100) NOT NULL, -- patient's first name\n last_name character varying(100) NOT NULL, -- patient's last name\n date_of_birth date NOT NULL, -- patient's date of birth\n gender character varying(10), -- patient's gender (e.g., Male, Female, Other)\n address text, -- patient's home address\n phone_number character varying(20), -- patient's phone number\n email character varying(128) UNIQUE, -- patient's email address\n emergency_contact_name character varying(200), -- name of emergency contact\n emergency_contact_phone character varying(20), -- phone number of emergency contact\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (patient_id)\n)\nCREATE TABLE healthcare.doctors (\n doctor_id character varying(64) NOT NULL, -- unique identifier for the doctor\n first_name character varying(100) NOT NULL, -- doctor's first name\n last_name character varying(100) NOT NULL, -- doctor's last name\n specialty character varying(100) NOT NULL, -- doctor's medical specialty\n license_number character varying(50) UNIQUE NOT NULL, -- doctor's medical license number\n phone_number character varying(20), -- doctor's contact phone\n email character varying(128) UNIQUE, -- doctor's contact email\n hospital_affiliation_id character varying(64), -- FK to hospitals table (optional)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (doctor_id)\n)\nCREATE TABLE healthcare.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table\n appointment_time timestamp with time zone NOT NULL, -- date and time of the appointment\n duration_minutes integer NOT NULL, -- expected duration in minutes\n reason text, -- reason for the visit\n status character varying(32) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-show\n location_id character varying(64), -- FK to a potential locations\/clinics table\n notes text, -- notes related to scheduling\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record\/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions\/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment\/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\nCREATE TABLE healthcare.patient_insurance (\n patient_insurance_id character varying(64) NOT NULL, -- unique identifier for this patient-plan link\n patient_id character varying(64) NOT NULL, -- FK to patients table\n plan_id character varying(64) NOT NULL, -- FK to insurance_plans table\n policy_number character varying(100) NOT NULL, -- patient's policy number\n group_number character varying(100), -- group number, if applicable\n subscriber_name character varying(200), -- name of the primary policy holder\n effective_date date NOT NULL, -- date the coverage begins\n expiration_date date, -- date the coverage ends (if known)\n is_primary boolean NOT NULL DEFAULT true, -- indicates if this is the primary insurance\n PRIMARY KEY (patient_insurance_id),\n UNIQUE (patient_id, plan_id, policy_number) -- ensure a patient doesn't have the same policy twice\n)\n","conversations":[{"role":"user","content":"Provide each patient's most recent medical-record doctor's full name along with their primary insurance plan name. Return patient_id, first_name, last_name, primary_plan_name, doctor_first_name, doctor_last_name."},{"role":"assistant","content":"SELECT p.patient_id,\n p.first_name,\n p.last_name,\n ip.plan_name AS primary_plan_name,\n d.first_name AS doctor_first_name,\n d.last_name AS doctor_last_name\nFROM healthcare.patients AS p\nJOIN healthcare.patient_insurance AS pi\n ON p.patient_id = pi.patient_id\n AND pi.is_primary = TRUE\nJOIN healthcare.insurance_plans AS ip\n ON pi.plan_id = ip.plan_id\nJOIN (\n SELECT DISTINCT ON (patient_id)\n patient_id,\n doctor_id,\n record_date\n FROM healthcare.medical_records\n ORDER BY patient_id, record_date DESC\n) AS mr\n ON p.patient_id = mr.patient_id\nJOIN healthcare.doctors AS d\n ON mr.doctor_id = d.doctor_id;"},{"role":"user","content":"Actually, restrict to only those whose primary plan_type is 'PPO'."},{"role":"assistant","content":"SELECT p.patient_id,\n p.first_name,\n p.last_name,\n ip.plan_name AS primary_plan_name,\n d.first_name AS doctor_first_name,\n d.last_name AS doctor_last_name\nFROM healthcare.patients AS p\nJOIN healthcare.patient_insurance AS pi\n ON p.patient_id = pi.patient_id\n AND pi.is_primary = TRUE\nJOIN healthcare.insurance_plans AS ip\n ON pi.plan_id = ip.plan_id\nJOIN (\n SELECT DISTINCT ON (patient_id)\n patient_id,\n doctor_id,\n record_date\n FROM healthcare.medical_records\n ORDER BY patient_id, record_date DESC\n) AS mr\n ON p.patient_id = mr.patient_id\nJOIN healthcare.doctors AS d\n ON mr.doctor_id = d.doctor_id\nWHERE ip.plan_type = 'PPO';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\n","conversations":[{"role":"user","content":"I'd like to see, for each month, the total number of players who registered and how many of them are active versus inactive."},{"role":"assistant","content":"SELECT DATE_TRUNC('month', registration_date) AS month,\n COUNT(*) AS total_registrations,\n COUNT(*) FILTER (WHERE status = 'active') AS active_count,\n COUNT(*) FILTER (WHERE status = 'inactive') AS inactive_count\nFROM gaming_technology.players\nGROUP BY month;"},{"role":"user","content":"Actually, limit this to registrations from January 1, 2022 onwards."},{"role":"assistant","content":"SELECT DATE_TRUNC('month', registration_date) AS month,\n COUNT(*) AS total_registrations,\n COUNT(*) FILTER (WHERE status = 'active') AS active_count,\n COUNT(*) FILTER (WHERE status = 'inactive') AS inactive_count\nFROM gaming_technology.players\nWHERE registration_date >= '2022-01-01'\nGROUP BY month;"},{"role":"user","content":"Also, I'd like to calculate the active percentage per month as active_count * 100.0 \/ total_registrations."},{"role":"assistant","content":"SELECT DATE_TRUNC('month', registration_date) AS month,\n COUNT(*) AS total_registrations,\n COUNT(*) FILTER (WHERE status = 'active') AS active_count,\n COUNT(*) FILTER (WHERE status = 'inactive') AS inactive_count,\n ROUND(\n COUNT(*) FILTER (WHERE status = 'active') * 100.0 \/\n NULLIF(COUNT(*),0), 2\n ) AS active_percentage\nFROM gaming_technology.players\nWHERE registration_date >= '2022-01-01'\nGROUP BY month;"},{"role":"user","content":"Finally, please sort the output by month in ascending order."},{"role":"assistant","content":"SELECT DATE_TRUNC('month', registration_date) AS month,\n COUNT(*) AS total_registrations,\n COUNT(*) FILTER (WHERE status = 'active') AS active_count,\n COUNT(*) FILTER (WHERE status = 'inactive') AS inactive_count,\n ROUND(\n COUNT(*) FILTER (WHERE status = 'active') * 100.0 \/\n NULLIF(COUNT(*),0), 2\n ) AS active_percentage\nFROM gaming_technology.players\nWHERE registration_date >= '2022-01-01'\nGROUP BY month\nORDER BY month ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number \/ 7200))\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"Show me all wallets holding SUI coins with a balance greater than 2,000,000. Include the coin_type, balance, and owner address."},{"role":"assistant","content":"SELECT coin_type, balance, owner FROM sui_coins WHERE status = 'exists' AND CAST(balance AS bigint) > 2000000;"},{"role":"user","content":"Can you also include the name and symbol of each coin by joining with the metadata table?"},{"role":"assistant","content":"SELECT sc.coin_type, scm.name, scm.symbol, sc.balance, sc.owner\nFROM sui_coins sc\nJOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'exists' AND scm.status = 'exists' AND CAST(sc.balance AS bigint) > 2000000;"},{"role":"user","content":"I want to limit the result to coins whose description contains 'staking'."},{"role":"assistant","content":"SELECT sc.coin_type, scm.name, scm.symbol, sc.balance, sc.owner, scm.description\nFROM sui_coins sc\nJOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'exists' AND scm.status = 'exists' AND CAST(sc.balance AS bigint) > 2000000 AND LOWER(scm.description) LIKE '%staking%';"},{"role":"user","content":"Now sort the results by balance in descending order and show only the top 10 records."},{"role":"assistant","content":"SELECT sc.coin_type, scm.name, scm.symbol, sc.balance, sc.owner, scm.description\nFROM sui_coins sc\nJOIN sui_coins_metadata scm ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'exists' AND scm.status = 'exists' AND CAST(sc.balance AS bigint) > 2000000 AND LOWER(scm.description) LIKE '%staking%'\nORDER BY CAST(sc.balance AS bigint) DESC\nLIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.trips ( trip_id character varying(64) NOT NULL, route_id character varying(64), vehicle_id character varying(64) NOT NULL, driver_id character varying(64) NOT NULL, scheduled_departure timestamp with time zone NOT NULL, actual_departure timestamp with time zone, scheduled_arrival timestamp with time zone NOT NULL, actual_arrival timestamp with time zone, origin_location_id character varying(64) NOT NULL, destination_location_id character varying(64) NOT NULL, status character varying(32) NOT NULL, passenger_count integer, cargo_manifest_id character varying(64), PRIMARY KEY (trip_id) )\nCREATE TABLE transportation.locations ( location_id text, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic\/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\nCREATE TABLE transportation.bookings ( booking_id.text, passenger_id.text, trip_id.text, seat_number.text, booking_time.timestamp, status.text, fare.numeric, payment_transaction_id.text, special_requests.text )\n","conversations":[{"role":"user","content":"Show me all trips that were delayed by more than 30 minutes, along with their vehicle and driver details, and include the origin and destination city names."},{"role":"assistant","content":"SELECT t.trip_id, t.vehicle_id, t.driver_id, t.scheduled_departure, t.actual_departure, EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 AS delay_minutes, lo.city AS origin_city, ld.city AS destination_city FROM transportation.trips t JOIN transportation.locations lo ON t.origin_location_id = lo.location_id JOIN transportation.locations ld ON t.destination_location_id = ld.location_id WHERE EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 > 30 AND t.status = 'completed'"},{"role":"user","content":"Now filter these results to only show trips where the origin city is 'San Francisco' and order them by delay time in descending order."},{"role":"assistant","content":"SELECT t.trip_id, t.vehicle_id, t.driver_id, t.scheduled_departure, t.actual_departure, EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 AS delay_minutes, lo.city AS origin_city, ld.city AS destination_city FROM transportation.trips t JOIN transportation.locations lo ON t.origin_location_id = lo.location_id JOIN transportation.locations ld ON t.destination_location_id = ld.location_id WHERE EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 > 30 AND t.status = 'completed' AND lo.city = 'San Francisco' ORDER BY delay_minutes DESC"},{"role":"user","content":"Can you also include the passenger count for these trips and limit the results to the top 10 longest delays?"},{"role":"assistant","content":"SELECT t.trip_id, t.vehicle_id, t.driver_id, t.scheduled_departure, t.actual_departure, EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 AS delay_minutes, t.passenger_count, lo.city AS origin_city, ld.city AS destination_city FROM transportation.trips t JOIN transportation.locations lo ON t.origin_location_id = lo.location_id JOIN transportation.locations ld ON t.destination_location_id = ld.location_id WHERE EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 > 30 AND t.status = 'completed' AND lo.city = 'San Francisco' ORDER BY delay_minutes DESC LIMIT 10"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE 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) )\nCREATE TABLE smart_money_token_performance ( token_address.text, token_symbol.text, pnl.numeric, net_flow.numeric, avg_cost.numeric, price.numeric, realized_ratio.numeric, roi.numeric, chain.text )\n","conversations":[{"role":"user","content":"Find tokens that are currently trending (trend rank 10 or lower) and have a positive net flow from smart money addresses. Show their token symbol, chain, trend rank, and smart money net flow. Order the results by trend rank ascending."},{"role":"assistant","content":"SELECT b.token_symbol, b.chain, b.trend_rank, s.net_flow FROM token_basic_info b JOIN smart_money_token_performance s ON b.token_address = s.token_address AND b.chain = s.chain WHERE b.trend_rank IS NOT NULL AND b.trend_rank <= 10 AND s.net_flow > 0 ORDER BY b.trend_rank ASC;"},{"role":"user","content":"Filter these results to only include tokens where the smart money realized ratio is greater than 0.5. Also, include the token's narrative in the output."},{"role":"assistant","content":"SELECT b.token_symbol, b.chain, b.trend_rank, s.net_flow, s.realized_ratio, b.narrative FROM token_basic_info b JOIN smart_money_token_performance s ON b.token_address = s.token_address AND b.chain = s.chain WHERE b.trend_rank IS NOT NULL AND b.trend_rank <= 10 AND s.net_flow > 0 AND s.realized_ratio > 0.5 ORDER BY b.trend_rank ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"I need to list the top 5 ERC20 tokens by total supply, including symbol, contract_address, and name."},{"role":"assistant","content":"SELECT tm.contract_address, tm.symbol, tm.name, CAST(tm.total_supply AS DECIMAL) AS total_supply\nFROM token_metas tm\nWHERE tm.is_erc20 = 1\nORDER BY CAST(tm.total_supply AS DECIMAL) DESC\nLIMIT 5;"},{"role":"user","content":"Also include the latest USD price for each token from token_prices using the most recent timestamp per token."},{"role":"assistant","content":"SELECT tm.contract_address, tm.symbol, tm.name, CAST(tm.total_supply AS DECIMAL) AS total_supply, tp.price\nFROM token_metas tm\nJOIN (\n SELECT address, price FROM token_prices tp1\n WHERE tp1.timestamp = (\n SELECT MAX(tp2.timestamp) FROM token_prices tp2 WHERE tp2.address = tp1.address\n )\n) tp ON tp.address = tm.contract_address\nWHERE tm.is_erc20 = 1\nORDER BY CAST(tm.total_supply AS DECIMAL) DESC\nLIMIT 5;"},{"role":"user","content":"Filter results to only include tokens where the price is greater than 2."},{"role":"assistant","content":"SELECT tm.contract_address, tm.symbol, tm.name, CAST(tm.total_supply AS DECIMAL) AS total_supply, tp.price\nFROM token_metas tm\nJOIN (\n SELECT address, price FROM token_prices tp1\n WHERE tp1.timestamp = (\n SELECT MAX(tp2.timestamp) FROM token_prices tp2 WHERE tp2.address = tp1.address\n )\n) tp ON tp.address = tm.contract_address\nWHERE tm.is_erc20 = 1\n AND tp.price > 2\nORDER BY CAST(tm.total_supply AS DECIMAL) DESC\nLIMIT 5;"},{"role":"user","content":"Order the results by price descending and limit to 5."},{"role":"assistant","content":"SELECT tm.contract_address, tm.symbol, tm.name, CAST(tm.total_supply AS DECIMAL) AS total_supply, tp.price\nFROM token_metas tm\nJOIN (\n SELECT address, price FROM token_prices tp1\n WHERE tp1.timestamp = (\n SELECT MAX(tp2.timestamp) FROM token_prices tp2 WHERE tp2.address = tp1.address\n )\n) tp ON tp.address = tm.contract_address\nWHERE tm.is_erc20 = 1\n AND tp.price > 2\nORDER BY tp.price DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, plan_id character varying(64) NOT NULL, policy_number character varying(100) NOT NULL, group_number character varying(100), subscriber_name character varying(200), effective_date date NOT NULL, expiration_date date, is_primary boolean NOT NULL DEFAULT true, PRIMARY KEY (patient_insurance_id), UNIQUE (patient_id, plan_id, policy_number) )\n","conversations":[{"role":"user","content":"Give me the number of patient insurance policies for each plan where the policy is currently active. Return plan_id and policy_count."},{"role":"assistant","content":"SELECT\n plan_id,\n COUNT(*) AS policy_count\nFROM healthcare.patient_insurance\nWHERE (expiration_date IS NULL OR expiration_date >= CURRENT_DATE)\nGROUP BY plan_id;"},{"role":"user","content":"Now, only include plans where the count is greater than 5 and sort by policy_count descending."},{"role":"assistant","content":"SELECT\n plan_id,\n COUNT(*) AS policy_count\nFROM healthcare.patient_insurance\nWHERE (expiration_date IS NULL OR expiration_date >= CURRENT_DATE)\nGROUP BY plan_id\nHAVING COUNT(*) > 5\nORDER BY policy_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\nCREATE TABLE trading_platform.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\nCREATE TABLE trading_platform.orders (\n order_id character varying(64) NOT NULL, -- unique identifier for the order\n user_id character varying(64) NOT NULL, -- identifier of the user placing the order\n wallet_id character varying(64) NOT NULL, -- identifier of the wallet used for the order\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n order_type character varying(32) NOT NULL, -- type of the order (e.g., buy, sell)\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the order\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n status character varying(32) NOT NULL, -- status of the order (e.g., open, filled, canceled)\n created_at timestamp NOT NULL, -- time when the order was created\n PRIMARY KEY (order_id)\n)\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets (\n asset_id character varying(64) NOT NULL, -- unique identifier for the asset\n name character varying(128) NOT NULL, -- name of the asset\n symbol character varying(32) NOT NULL, -- symbol of the asset\n type character varying(32) NOT NULL, -- type of the asset (e.g., cryptocurrency, stock)\n PRIMARY KEY (asset_id)\n)\nCREATE TABLE trading_platform.dapps (\n dapp_id character varying(64) NOT NULL, -- unique identifier for the DApp\n name character varying(128) NOT NULL, -- name of the DApp\n description text NOT NULL, -- description of the DApp\n url character varying(256) NOT NULL, -- URL of the DApp\n PRIMARY KEY (dapp_id)\n)\nCREATE TABLE trading_platform.peers (\n peer_id character varying(64) NOT NULL, -- unique identifier for the peer\n ip_address character varying(15) NOT NULL, -- IP address of the peer\n port integer NOT NULL, -- port number of the peer\n last_seen timestamp NOT NULL, -- last time the peer was active\n PRIMARY KEY (peer_id)\n)\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\nCREATE TABLE trading_platform.logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the log entry\n user_id character varying(64), -- identifier of the user associated with the log entry\n action character varying(128) NOT NULL, -- action performed\n details text NOT NULL, -- details of the action\n logged_at timestamp NOT NULL, -- time when the log entry was created\n PRIMARY KEY (log_id)\n)\n","conversations":[{"role":"user","content":"List all cryptocurrency assets that have been traded at least 50 times, along with their average trade price."},{"role":"assistant","content":"SELECT a.asset_id, a.name, a.symbol, COUNT(t.trade_id) AS trade_count, AVG(t.price) AS avg_price FROM trading_platform.assets a JOIN trading_platform.trades t ON a.asset_id = t.asset_id WHERE a.type = 'cryptocurrency' GROUP BY a.asset_id HAVING COUNT(t.trade_id) >= 50 ORDER BY trade_count DESC;"},{"role":"user","content":"Now filter these results to only show assets where the average trade price is above $100."},{"role":"assistant","content":"SELECT a.asset_id, a.name, a.symbol, COUNT(t.trade_id) AS trade_count, AVG(t.price) AS avg_price FROM trading_platform.assets a JOIN trading_platform.trades t ON a.asset_id = t.asset_id WHERE a.type = 'cryptocurrency' GROUP BY a.asset_id HAVING COUNT(t.trade_id) >= 50 AND AVG(t.price) > 100 ORDER BY avg_price DESC;"},{"role":"user","content":"Can you also include the most recent trade timestamp for each asset?"},{"role":"assistant","content":"SELECT a.asset_id, a.name, a.symbol, COUNT(t.trade_id) AS trade_count, AVG(t.price) AS avg_price, MAX(t.traded_at) AS last_trade FROM trading_platform.assets a JOIN trading_platform.trades t ON a.asset_id = t.asset_id WHERE a.type = 'cryptocurrency' GROUP BY a.asset_id HAVING COUNT(t.trade_id) >= 50 AND AVG(t.price) > 100 ORDER BY avg_price DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.service_orders ( order_id.text, reservation_id.text, guest_id.text, service_id.text, staff_id_ordered.text, staff_id_delivered.text, order_timestamp.timestamp, delivery_timestamp.timestamp, quantity.integer, unit_price.numeric, total_price.numeric, status.text, notes.text, bill_id.text )\n","conversations":[{"role":"user","content":"Show me each service order along with the next order placed by the same guest, including both order IDs and the time difference in minutes between the two orders."},{"role":"assistant","content":"SELECT a.order_id,\n b.order_id AS next_order_id,\n EXTRACT(EPOCH FROM (b.order_timestamp - a.order_timestamp)) \/ 60 AS diff_minutes\nFROM hospitality_technology.service_orders a\nJOIN hospitality_technology.service_orders b\n ON a.guest_id = b.guest_id\n AND b.order_timestamp > a.order_timestamp;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.securities ( security_id text, ticker_symbol text, isin_code text, cusip_code text, security_name text, security_type text, exchange text, currency text, issuer_name text, sector text, last_updated timestamp )\n","conversations":[{"role":"user","content":"Find all pairs of securities that are issued by the same issuer but listed on different exchanges."},{"role":"assistant","content":"SELECT a.issuer_name, a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b FROM financial_services.securities a JOIN financial_services.securities b ON a.issuer_name = b.issuer_name AND a.exchange <> b.exchange;"},{"role":"user","content":"Also include the currency for both securities in the result."},{"role":"assistant","content":"SELECT a.issuer_name, a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, a.currency AS currency_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, b.currency AS currency_b FROM financial_services.securities a JOIN financial_services.securities b ON a.issuer_name = b.issuer_name AND a.exchange <> b.exchange;"},{"role":"user","content":"Filter the pairs to only include issuers in the 'Financials' sector."},{"role":"assistant","content":"SELECT a.issuer_name, a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, a.currency AS currency_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, b.currency AS currency_b FROM financial_services.securities a JOIN financial_services.securities b ON a.issuer_name = b.issuer_name AND a.exchange <> b.exchange WHERE a.sector = 'Financials' AND b.sector = 'Financials';"},{"role":"user","content":"Finally, sort the output by issuer_name ascending and symbol_a ascending."},{"role":"assistant","content":"SELECT a.issuer_name, a.ticker_symbol AS symbol_a, a.exchange AS exchange_a, a.currency AS currency_a, b.ticker_symbol AS symbol_b, b.exchange AS exchange_b, b.currency AS currency_b FROM financial_services.securities a JOIN financial_services.securities b ON a.issuer_name = b.issuer_name AND a.exchange <> b.exchange WHERE a.sector = 'Financials' AND b.sector = 'Financials' ORDER BY a.issuer_name ASC, symbol_a ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens (\n citizen_id character varying(64) NOT NULL, -- unique identifier for the citizen\n national_id_number character varying(128) NOT NULL UNIQUE, -- official national identification number\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n date_of_birth date NOT NULL,\n gender character varying(20),\n primary_address text NOT NULL, -- full primary residential address\n contact_email character varying(128) UNIQUE,\n contact_phone character varying(32),\n registration_date timestamp NOT NULL, -- when the citizen profile was created\n is_verified boolean DEFAULT false, -- whether identity has been officially verified\n PRIMARY KEY (citizen_id)\n)\nCREATE TABLE government_services.agencies (\n agency_id character varying(64) NOT NULL, -- unique identifier for the agency\n agency_name character varying(255) NOT NULL, -- full name of the government agency\n jurisdiction_level character varying(50) NOT NULL, -- e.g., Federal, State, County, City\n primary_contact_email character varying(128),\n main_phone_number character varying(32),\n website_url character varying(255),\n established_date date,\n parent_agency_id character varying(64), -- FK to self for hierarchical structure\n PRIMARY KEY (agency_id)\n)\nCREATE TABLE government_services.services (\n service_id character varying(64) NOT NULL, -- unique identifier for the service\n agency_id character varying(64) NOT NULL, -- FK to agencies table\n service_name character varying(255) NOT NULL, -- name of the service (e.g., Driver's License Renewal)\n description text,\n category character varying(100), -- e.g., Licensing, Benefits, Taxation, Permits\n eligibility_criteria text, -- description of who is eligible\n standard_fee numeric(10, 2) DEFAULT 0.00, -- typical fee for the service\n average_processing_time_days integer, -- estimated processing time\n is_active boolean DEFAULT true, -- whether the service is currently offered\n online_application_url character varying(255),\n PRIMARY KEY (service_id)\n)\nCREATE TABLE government_services.documents (\n document_id character varying(64) NOT NULL, -- unique identifier for the document instance\n application_id character varying(64), -- FK to applications table (optional, could be linked to citizen directly)\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n document_type character varying(100) NOT NULL, -- e.g., Passport Scan, Proof of Address, Birth Certificate\n file_reference text NOT NULL, -- reference to the stored file (e.g., S3 URL, internal path)\n upload_timestamp timestamp NOT NULL,\n expiry_date date,\n verification_status character varying(30) DEFAULT 'Pending', -- e.g., Pending, Verified, Rejected\n verified_by_employee_id character varying(64), -- FK to employees table\n verification_timestamp timestamp,\n PRIMARY KEY (document_id)\n)\nCREATE TABLE government_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n employee_id character varying(64), -- FK to employees table (optional, if assigned)\n location_id character varying(64), -- FK to service_locations table (if physical)\n service_id character varying(64), -- FK to services table (optional, if related to specific service)\n scheduled_start_time timestamp NOT NULL,\n scheduled_end_time timestamp,\n purpose text NOT NULL, -- reason for the appointment\n status character varying(30) NOT NULL, -- e.g., Scheduled, Completed, Cancelled, No-Show\n booking_method character varying(50), -- e.g., Online, Phone, In-Person\n created_at timestamp NOT NULL, -- when the appointment was booked\n notes text,\n PRIMARY KEY (appointment_id)\n)\nCREATE TABLE government_services.notifications (\n notification_id character varying(64) NOT NULL, -- unique identifier for the notification\n citizen_id character varying(64) NOT NULL, -- FK to citizens table\n application_id character varying(64), -- FK to applications table (optional)\n message_subject character varying(255),\n message_body text NOT NULL,\n channel character varying(30) NOT NULL, -- e.g., Email, SMS, Portal Message, Mail\n sent_at timestamp NOT NULL,\n status character varying(30) NOT NULL, -- e.g., Queued, Sent, Delivered, Failed, Read\n related_entity_type character varying(50), -- e.g., Application, Appointment, Document Request\n related_entity_id character varying(64), -- ID of the related entity\n PRIMARY KEY (notification_id)\n)\n","conversations":[{"role":"user","content":"List all applications that have at least one document with a verification status of 'Verified'. Show the application reference number and the name of the service associated with the application."},{"role":"assistant","content":"SELECT\n T1.reference_number,\n T2.service_name\nFROM government_services.applications AS T1\nINNER JOIN government_services.services AS T2\n ON T1.service_id = T2.service_id\nWHERE EXISTS (\n SELECT\n 1\n FROM government_services.documents AS T3\n WHERE\n T3.application_id = T1.application_id AND T3.verification_status = 'Verified'\n);"},{"role":"user","content":"Now, only include applications that were submitted in the year 2024."},{"role":"assistant","content":"SELECT\n T1.reference_number,\n T2.service_name\nFROM government_services.applications AS T1\nINNER JOIN government_services.services AS T2\n ON T1.service_id = T2.service_id\nWHERE EXISTS (\n SELECT\n 1\n FROM government_services.documents AS T3\n WHERE\n T3.application_id = T1.application_id AND T3.verification_status = 'Verified'\n)\nAND EXTRACT(YEAR FROM T1.submitted_at) = 2024;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.notifications ( notification_id text PRIMARY KEY, user_id text, message text, sent_at timestamp, read_at timestamp )\n","conversations":[{"role":"user","content":"Find the average time it takes for users to read notifications after they are sent."},{"role":"assistant","content":"SELECT AVG(EXTRACT(EPOCH FROM (read_at - sent_at))\/3600) as avg_hours_to_read FROM trading_platform.notifications WHERE read_at IS NOT NULL;"},{"role":"user","content":"Now show me this average broken down by day of the week when the notification was sent."},{"role":"assistant","content":"SELECT EXTRACT(DOW FROM sent_at) as day_of_week, AVG(EXTRACT(EPOCH FROM (read_at - sent_at))\/3600) as avg_hours_to_read FROM trading_platform.notifications WHERE read_at IS NOT NULL GROUP BY day_of_week ORDER BY day_of_week;"},{"role":"user","content":"Can you modify the query to show the day names (Monday-Sunday) instead of numbers?"},{"role":"assistant","content":"SELECT CASE EXTRACT(DOW FROM sent_at) WHEN 0 THEN 'Sunday' WHEN 1 THEN 'Monday' WHEN 2 THEN 'Tuesday' WHEN 3 THEN 'Wednesday' WHEN 4 THEN 'Thursday' WHEN 5 THEN 'Friday' WHEN 6 THEN 'Saturday' END as day_of_week, AVG(EXTRACT(EPOCH FROM (read_at - sent_at))\/3600) as avg_hours_to_read FROM trading_platform.notifications WHERE read_at IS NOT NULL GROUP BY day_of_week ORDER BY EXTRACT(DOW FROM sent_at);"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata ( object_id.text, coin_type.text, status.text, decimals.bigint, description.text, icon_url.text, symbol.text, name.text )\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE token_prices_latest (\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE erc20_approval ( block_number bigint NOT NULL, block_timestamp timestamp(6) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar NOT NULL, log_index integer NOT NULL, contract_address varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_bitcoin ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(255) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply varchar NOT NULL, amount varchar NOT NULL )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\n","conversations":[{"role":"user","content":"Show the total transfer volume and number of transfers for each Avalanche token in the past 7 days, including token tick and its creator."},{"role":"assistant","content":"SELECT ta.tick, ti.creator, SUM(ta.amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities ta\nJOIN token_info ti ON ta.tick = ti.tick\nWHERE ta.block_timestamp >= now() - interval '7 days'\nGROUP BY ta.tick, ti.creator;"},{"role":"user","content":"Only include tokens where total_volume > 1000 and sort by total_volume descending."},{"role":"assistant","content":"SELECT ta.tick, ti.creator, SUM(ta.amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities ta\nJOIN token_info ti ON ta.tick = ti.tick\nWHERE ta.block_timestamp >= now() - interval '7 days'\nGROUP BY ta.tick, ti.creator\nHAVING SUM(ta.amt) > 1000\nORDER BY total_volume DESC;"},{"role":"user","content":"Limit the output to the top 5 tokens."},{"role":"assistant","content":"SELECT ta.tick, ti.creator, SUM(ta.amt) AS total_volume, COUNT(*) AS transfer_count\nFROM token_activities ta\nJOIN token_info ti ON ta.tick = ti.tick\nWHERE ta.block_timestamp >= now() - interval '7 days'\nGROUP BY ta.tick, ti.creator\nHAVING SUM(ta.amt) > 1000\nORDER BY total_volume DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"List all active SUI coins with their symbol, name, and total balance across all owners."},{"role":"assistant","content":"SELECT scm.coin_type, scm.symbol, scm.name, SUM(CAST(sc.balance AS DECIMAL)) AS total_balance\nFROM sui_coins_metadata scm\nJOIN sui_coins sc ON sc.coin_type = scm.coin_type\nWHERE sc.status = 'active' AND scm.status = 'exists'\nGROUP BY scm.coin_type, scm.symbol, scm.name;"},{"role":"user","content":"Filter coins with description containing 'staking' and sort by total_balance descending."},{"role":"assistant","content":"SELECT sub.coin_type, sub.symbol, sub.name, sub.total_balance\nFROM (\n SELECT scm.coin_type, scm.symbol, scm.name, SUM(CAST(sc.balance AS DECIMAL)) AS total_balance\n FROM sui_coins_metadata scm\n JOIN sui_coins sc ON sc.coin_type = scm.coin_type\n WHERE sc.status = 'active' AND scm.status = 'exists' AND LOWER(scm.description) LIKE '%staking%'\n GROUP BY scm.coin_type, scm.symbol, scm.name\n) sub\nORDER BY sub.total_balance DESC;"},{"role":"user","content":"Limit the result to the top 3 coins."},{"role":"assistant","content":"SELECT sub.coin_type, sub.symbol, sub.name, sub.total_balance\nFROM (\n SELECT scm.coin_type, scm.symbol, scm.name, SUM(CAST(sc.balance AS DECIMAL)) AS total_balance\n FROM sui_coins_metadata scm\n JOIN sui_coins sc ON sc.coin_type = scm.coin_type\n WHERE sc.status = 'active' AND scm.status = 'exists' AND LOWER(scm.description) LIKE '%staking%'\n GROUP BY scm.coin_type, scm.symbol, scm.name\n) sub\nORDER BY sub.total_balance DESC\nLIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n","conversations":[{"role":"user","content":"Show me all claims with police reports that were filed in the last 3 months, along with the policy details and customer information."},{"role":"assistant","content":"SELECT c.claim_id, c.policy_id, c.customer_id, c.incident_date, c.reported_date, c.description, c.estimated_loss, c.status, c.settlement_amount, c.settlement_date, c.police_report_number, p.product_id, p.product_name, p.product_type, b.first_name, b.last_name, b.relationship FROM insurance.claims c JOIN insurance.insurance_products p ON c.policy_id = p.product_id JOIN insurance.policy_beneficiaries b ON c.customer_id = b.customer_id WHERE c.police_report_number IS NOT NULL AND c.reported_date >= CURRENT_DATE - INTERVAL '3 months';"},{"role":"user","content":"Now filter to only show claims where the estimated loss is above $10,000."},{"role":"assistant","content":"SELECT c.claim_id, c.policy_id, c.customer_id, c.incident_date, c.reported_date, c.description, c.estimated_loss, c.status, c.settlement_amount, c.settlement_date, c.police_report_number, p.product_id, p.product_name, p.product_type, b.first_name, b.last_name, b.relationship FROM insurance.claims c JOIN insurance.insurance_products p ON c.policy_id = p.product_id JOIN insurance.policy_beneficiaries b ON c.customer_id = b.customer_id WHERE c.police_report_number IS NOT NULL AND c.reported_date >= CURRENT_DATE - INTERVAL '3 months' AND c.estimated_loss > 10000;"},{"role":"user","content":"I also want to see the count of such claims per product type."},{"role":"assistant","content":"SELECT p.product_type, COUNT(c.claim_id) AS claim_count FROM insurance.claims c JOIN insurance.insurance_products p ON c.policy_id = p.product_id WHERE c.police_report_number IS NOT NULL AND c.reported_date >= CURRENT_DATE - INTERVAL '3 months' AND c.estimated_loss > 10000 GROUP BY p.product_type;"},{"role":"user","content":"Finally, show me the average estimated loss for these claims by product type."},{"role":"assistant","content":"SELECT p.product_type, AVG(c.estimated_loss) AS avg_estimated_loss FROM insurance.claims c JOIN insurance.insurance_products p ON c.policy_id = p.product_id WHERE c.police_report_number IS NOT NULL AND c.reported_date >= CURRENT_DATE - INTERVAL '3 months' AND c.estimated_loss > 10000 GROUP BY p.product_type;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts ( contract_id character varying(64) NOT NULL, address character varying(128) NOT NULL, abi text NOT NULL, bytecode text NOT NULL, deployer_address character varying(128) NOT NULL, deployed_at timestamp NOT NULL, network_id character varying(64) NOT NULL, status character varying(32) NOT NULL, PRIMARY KEY (contract_id) )\n","conversations":[{"role":"user","content":"Find all contracts where the deployer address is the same as the contract address, indicating self-deployed contracts, and show their network IDs and deployment timestamps."},{"role":"assistant","content":"SELECT address, network_id, deployed_at FROM web3.contracts WHERE address = deployer_address;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id character varying(64) NOT NULL, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_message_at timestamp, is_group_chat boolean NOT NULL DEFAULT false, group_name character varying(100), PRIMARY KEY (conversation_id) )\n","conversations":[{"role":"user","content":"Provide a breakdown of the total number of conversations, showing how many are group chats and how many are not. Also, show the count of conversations that have a recorded last message time."},{"role":"assistant","content":"SELECT COUNT(*) AS total_conversations, COUNT(CASE WHEN is_group_chat = true THEN 1 END) AS group_chat_count, COUNT(CASE WHEN is_group_chat = false THEN 1 END) AS private_chat_count, COUNT(last_message_at) AS conversations_with_messages_count FROM social_media.conversations;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.hashtags ( hashtag_id.text, tag_name.text, created_at.timestamp )\nCREATE TABLE social_media.conversations ( conversation_id.text, created_at.timestamp, last_message_at.timestamp, is_group_chat.boolean, group_name.text )\n","conversations":[{"role":"user","content":"List all group conversations that were created after January 1st, 2023, and for each, show the names of hashtags that were created within the same month as the conversation."},{"role":"assistant","content":"SELECT c.conversation_id, c.group_name, c.created_at AS conversation_created_at, h.tag_name, h.created_at AS hashtag_created_at\nFROM social_media.conversations c\nJOIN social_media.hashtags h\n ON DATE_TRUNC('month', c.created_at) = DATE_TRUNC('month', h.created_at)\nWHERE c.is_group_chat = TRUE\n AND c.created_at > '2023-01-01';"},{"role":"user","content":"Instead of hashtag names, can you show their hashtag IDs?"},{"role":"assistant","content":"SELECT c.conversation_id, c.group_name, c.created_at AS conversation_created_at, h.hashtag_id, h.created_at AS hashtag_created_at\nFROM social_media.conversations c\nJOIN social_media.hashtags h\n ON DATE_TRUNC('month', c.created_at) = DATE_TRUNC('month', h.created_at)\nWHERE c.is_group_chat = TRUE\n AND c.created_at > '2023-01-01';"},{"role":"user","content":"Also, filter only group chats where the group name contains the word 'Project'."},{"role":"assistant","content":"SELECT c.conversation_id, c.group_name, c.created_at AS conversation_created_at, h.hashtag_id, h.created_at AS hashtag_created_at\nFROM social_media.conversations c\nJOIN social_media.hashtags h\n ON DATE_TRUNC('month', c.created_at) = DATE_TRUNC('month', h.created_at)\nWHERE c.is_group_chat = TRUE\n AND c.created_at > '2023-01-01'\n AND c.group_name ILIKE '%Project%';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE token_dexpool_info (\",\n \"pair_address character varying(512) NOT NULL, -- the id of dexpool\",\n \"token_name character varying(100) NOT NULL, -- the name of the token in the dexpool\",\n \"token_symbol character varying(100) NOT NULL, -- the token's symbol\",\n \"chain text, -- the chain that the dexpool resides\",\n \"price double precision, -- the current price of the token\",\n \"price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour\",\n \"price_change_percentage_6h double precision, -- change in value divided by the absolute price value of the original token price in 6 hours\",\n \"price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours\",\n \"makers_24h double precision, -- the makers of the dex pool in 24 hours\",\n \"volume_24h double precision, -- the trade volume of the dex pool in 24 hours\",\n \"liquidity double precision, -- the liquidity of the dex pool\",\n \"market_cap double precision, -- the market cap of the token\",\n \"trend_rank bigint, -- the rank of token in the dex pool of recent trending, value 1 expresses the most popular token.\",\n \",PRIMARY KEY (pair_address, chain);\"\n\n","conversations":[{"role":"user","content":"Which pairs of tokens on the same chain have the greatest difference in 24h trading volume? List the two token symbols, their volumes, the absolute difference, and the chain. Limit to the top 3 pairs."},{"role":"assistant","content":"SELECT a.chain,\n a.token_symbol AS token_a,\n b.token_symbol AS token_b,\n ABS(a.volume_24h - b.volume_24h) AS volume_diff,\n a.volume_24h AS volume_a,\n b.volume_24h AS volume_b\nFROM token_dexpool_info a\nJOIN token_dexpool_info b\n ON a.chain = b.chain\n AND a.token_symbol <> b.token_symbol\nORDER BY volume_diff DESC\nLIMIT 3;"},{"role":"user","content":"I only want results for chains 'Ethereum' and 'Polygon' and show the top 5 pairs instead of 3."},{"role":"assistant","content":"SELECT a.chain,\n a.token_symbol AS token_a,\n b.token_symbol AS token_b,\n ABS(a.volume_24h - b.volume_24h) AS volume_diff,\n a.volume_24h AS volume_a,\n b.volume_24h AS volume_b\nFROM token_dexpool_info a\nJOIN token_dexpool_info b\n ON a.chain = b.chain\n AND a.token_symbol <> b.token_symbol\nWHERE a.chain IN ('Ethereum','Polygon')\nORDER BY volume_diff DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, transaction_index integer NOT NULL, transaction_hash varchar(66) NOT NULL, log_index integer NOT NULL, contract_address varchar(42) NOT NULL )\nCREATE TABLE erc20_balances ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk varchar NOT NULL )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE nft_holder_historical ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.integer )\nCREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE token_prices (\n uuid varchar(36) NOT NULL, -- uuid fields for the functionType in contract\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"Show me the wallet addresses that hold more than 1000 of any ERC20 token, along with the token symbol and amount, from the erc20_balances table."},{"role":"assistant","content":"SELECT e.wallet_address, t.symbol, e.amount FROM erc20_balances e JOIN token_prices_latest t ON e.contract_address = t.address WHERE CAST(e.amount AS decimal) > 1000;"},{"role":"user","content":"Can you also include the current price of each token from the token_prices_latest table and sort the results by amount in descending order?"},{"role":"assistant","content":"SELECT e.wallet_address, t.symbol, e.amount, t.price FROM erc20_balances e JOIN token_prices_latest t ON e.contract_address = t.address WHERE CAST(e.amount AS decimal) > 1000 ORDER BY CAST(e.amount AS decimal) DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\n","conversations":[{"role":"user","content":"Identify all instances where a vehicle's odometer_reading increased by more than 500 miles between two consecutive fuel log entries."},{"role":"assistant","content":"SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n a.log_timestamp AS previous_time,\n b.log_timestamp AS next_time,\n b.odometer_reading - a.odometer_reading AS mile_increase\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500;"},{"role":"user","content":"Now restrict these increases to those where the time difference between entries is less than 7 days."},{"role":"assistant","content":"SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n a.log_timestamp AS previous_time,\n b.log_timestamp AS next_time,\n b.odometer_reading - a.odometer_reading AS mile_increase,\n EXTRACT(epoch FROM (b.log_timestamp - a.log_timestamp))\/3600 AS hours_diff\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500\n AND b.log_timestamp - a.log_timestamp < INTERVAL '7 days';"},{"role":"user","content":"Also include both the mile increase and the time difference in hours in the final output columns."},{"role":"assistant","content":"SELECT a.vehicle_id,\n a.fuel_log_id AS previous_log_id,\n b.fuel_log_id AS next_log_id,\n b.odometer_reading - a.odometer_reading AS mile_increase,\n EXTRACT(epoch FROM (b.log_timestamp - a.log_timestamp))\/3600 AS hours_difference\nFROM transportation.fuel_logs a\nJOIN transportation.fuel_logs b\n ON a.vehicle_id = b.vehicle_id\n AND b.log_timestamp = (\n SELECT MIN(log_timestamp)\n FROM transportation.fuel_logs\n WHERE vehicle_id = a.vehicle_id\n AND log_timestamp > a.log_timestamp\n )\nWHERE b.odometer_reading - a.odometer_reading > 500\n AND b.log_timestamp - a.log_timestamp < INTERVAL '7 days';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(10), address text, phone_number character varying(20), email character varying(128) UNIQUE, emergency_contact_name character varying(200), emergency_contact_phone character varying(20), created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (patient_id) )\nCREATE TABLE healthcare.doctors ( doctor_id.text, first_name.text, last_name.text, specialty.text, license_number.text, phone_number.text, email.text, hospital_affiliation_id.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE healthcare.medical_records (\n record_id character varying(64) NOT NULL, -- unique identifier for the medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n appointment_id character varying(64) UNIQUE, -- FK to appointments table (can be null if record not tied to specific appt)\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (doctor creating the record)\n record_date timestamp with time zone NOT NULL, -- date the record\/observation was made\n chief_complaint text, -- patient's primary reason for visit\n present_illness_history text, -- detailed history of the current issue\n past_medical_history text, -- relevant past conditions\/surgeries\n physical_examination_notes text, -- findings from the physical exam\n assessment text, -- doctor's assessment\/diagnosis summary\n treatment_plan text, -- planned course of action\n vitals jsonb, -- store vitals like BP, HR, Temp as structured JSON\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (record_id)\n)\nCREATE TABLE healthcare.diagnoses ( diagnosis_id text PRIMARY KEY, record_id text, patient_id text, doctor_id text, diagnosis_code text, code_type text, description text, diagnosis_date date, status text, is_chronic boolean )\nCREATE TABLE healthcare.medications (\n medication_id character varying(64) NOT NULL, -- unique identifier for the medication type\n medication_name character varying(255) NOT NULL, -- common or brand name\n generic_name character varying(255), -- generic chemical name\n manufacturer character varying(100), -- drug manufacturer\n ndc_code character varying(20) UNIQUE, -- National Drug Code (optional but useful)\n description text, -- description of the medication\n PRIMARY KEY (medication_id)\n)\nCREATE TABLE healthcare.prescriptions ( prescription_id character varying(64) NOT NULL, record_id character varying(64) NOT NULL, patient_id character varying(64) NOT NULL, doctor_id character varying(64) NOT NULL, medication_id character varying(64) NOT NULL, dosage character varying(100) NOT NULL, frequency character varying(100) NOT NULL, route character varying(50), start_date date NOT NULL, end_date date, quantity_dispensed numeric(10,2), refills_allowed integer NOT NULL DEFAULT 0, prescription_date timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (prescription_id) )\n","conversations":[{"role":"user","content":"Find all medical records where the treatment plan includes 'physical therapy' and the patient has an active primary insurance plan, showing the patient ID, record date, and insurance provider details."},{"role":"assistant","content":"SELECT mr.patient_id, mr.record_date, i.provider_name, i.policy_number FROM healthcare.medical_records mr JOIN healthcare.patients p ON mr.patient_id = p.patient_id JOIN healthcare.insurance_plans i ON p.patient_id = i.patient_id WHERE mr.treatment_plan LIKE '%physical therapy%' AND i.is_primary = true AND i.status = 'Active';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"List all ERC20 tokens along with their contract addresses and the wallet address holding the largest balance for each token."},{"role":"assistant","content":"SELECT eb.contract_address, eb.wallet_address, eb.amount FROM erc20_balances eb WHERE (eb.contract_address, CAST(eb.amount AS DECIMAL)) IN (SELECT contract_address, MAX(CAST(amount AS DECIMAL)) FROM erc20_balances GROUP BY contract_address);"},{"role":"user","content":"I want to see the symbol and name of each token as well. Join with their metadata table if available."},{"role":"assistant","content":"SELECT eb.contract_address, eb.wallet_address, eb.amount, tm.symbol, tm.name FROM erc20_balances eb JOIN token_prices_latest tm ON eb.contract_address = tm.address WHERE (eb.contract_address, CAST(eb.amount AS DECIMAL)) IN (SELECT contract_address, MAX(CAST(amount AS DECIMAL)) FROM erc20_balances GROUP BY contract_address);"},{"role":"user","content":"Only show tokens where the wallet holds more than 10,000 tokens."},{"role":"assistant","content":"SELECT eb.contract_address, eb.wallet_address, eb.amount, tm.symbol, tm.name FROM erc20_balances eb JOIN token_prices_latest tm ON eb.contract_address = tm.address WHERE (eb.contract_address, CAST(eb.amount AS DECIMAL)) IN (SELECT contract_address, MAX(CAST(amount AS DECIMAL)) FROM erc20_balances GROUP BY contract_address) AND CAST(eb.amount AS DECIMAL) > 10000;"},{"role":"user","content":"Limit the results to tokens with a symbol that starts with 'A' and show only the top 5 based on balance."},{"role":"assistant","content":"SELECT eb.contract_address, eb.wallet_address, eb.amount, tm.symbol, tm.name FROM erc20_balances eb JOIN token_prices_latest tm ON eb.contract_address = tm.address WHERE (eb.contract_address, CAST(eb.amount AS DECIMAL)) IN (SELECT contract_address, MAX(CAST(amount AS DECIMAL)) FROM erc20_balances GROUP BY contract_address) AND CAST(eb.amount AS DECIMAL) > 10000 AND tm.symbol LIKE 'A%' ORDER BY CAST(eb.amount AS DECIMAL) DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract\n amount varchar NOT NULL, -- Wallet's on-chain balance at the corresponding block height\n pk varchar NOT NULL -- The last string partition of the contract.\n)\nCREATE TABLE erc20_balances_historical ( block_number bigint NOT NULL, contract_address varchar NOT NULL, wallet_address varchar NOT NULL, amount varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE sui_coins ( object_id.text, status.text, coin_type.text, balance.text, owner.text )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_collections (\n blockchain varchar NOT NULL, -- blockchain fields for the functionType in contract\n contract_address varchar NOT NULL, -- Contract address(with bloom filter)\n name varchar NOT NULL, -- name fields for the functionType in contract\n symbol varchar NOT NULL, -- symbol fields for the functionType in contract\n deploy_block_number bigint NOT NULL, -- deploy_block_number fields for the functionType in contract\n deploy_block_time bigint NOT NULL, -- deploy_block_time fields for the functionType in contract\n erc_type varchar NOT NULL, -- The type of token\n owner varchar NOT NULL, -- owner fields for the functionType in contract\n traits varchar NOT NULL, -- traits fields for the functionType in contract\n description varchar NOT NULL, -- description fields for the functionType in contract\n slug varchar NOT NULL, -- slug fields for the functionType in contract\n media_info varchar NOT NULL, -- media_info fields for the functionType in contract\n image_url varchar NOT NULL, -- image_url fields for the functionType in contract\n banner_image_url varchar NOT NULL, -- banner_image_url fields for the functionType in contract\n updated_at bigint NOT NULL, -- updated_at fields for the functionType in contract\n banner varchar NOT NULL, -- banner fields for the functionType in contract\n token_count bigint NOT NULL, -- token_count fields for the functionType in contract\n floor_price varchar NOT NULL, -- floor_price fields for the functionType in contract\n floor_price_symbol varchar NOT NULL, -- floor_price_symbol fields for the functionType in contract\n floor_price_contract varchar NOT NULL, -- floor_price_contract fields for the functionType in contract\n pk integer NOT NULL -- Partition key for the table(floor(deploy_block_time \/ 1000 \/ 86400 \/ 30))\n)\nCREATE TABLE token_prices (\n uuid varchar(36) NOT NULL, -- uuid fields for the functionType in contract\n blockchain varchar(36) NOT NULL, -- blockchain fields for the functionType in contract\n address varchar(42) NOT NULL, -- address fields for the functionType in contract\n decimals bigint NOT NULL, -- decimals fields for the functionType in contract\n symbol varchar(36) NOT NULL, -- symbol fields for the functionType in contract\n price real NOT NULL, -- price fields for the functionType in contract\n timestamp timestamp(6) NOT NULL -- timestamp fields for the functionType in contract\n)\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar(255) NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities_bitcoin (\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the inscription (matches block_timestamp in transactions table)\n block_number bigint NOT NULL, -- Block number containing the inscription (matches block_number in transactions table)\n tx_index integer NOT NULL, -- Index of the transaction containing the inscription (matches transaction_index in transactions table)\n tx_hash varchar(66) NOT NULL, -- Unique identifier of the transaction containing the inscription (matches hash in transactions table)\n log_index integer NOT NULL, -- Index of the log within the transaction\n type varchar(20) NOT NULL, -- Operation: Type of event (deploy, mint, transfer, list)\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n id varchar(255) NOT NULL, -- Unique identifier of the inscription\n amt decimal(38,0) NOT NULL, -- Amount to mint: States the amount of the inscription to operation. When operation is mint, has to be less or equal to \"lim\"\n from_address varchar(62) NOT NULL, -- Address sending the inscription\n to_address varchar(62) NOT NULL -- Address receiving the inscription\n)\nCREATE TABLE token_activities_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE token_balances_avalanche ( block_number bigint NOT NULL, block_timestamp timestamp(3) NOT NULL, tick varchar(20) NOT NULL, wallet_address varchar(42) NOT NULL, total_supply decimal(38,0) NOT NULL, amount decimal(38,0) NOT NULL )\nCREATE TABLE token_info_avalanche ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, tick.text, max_supply.decimal, lim.decimal, wlim.decimal, dec.integer, creator.text, minted.decimal, holders.decimal, txs.decimal, updated_timestamp.timestamp, completed_timestamp.timestamp, id.text )\n","conversations":[{"role":"user","content":"List all NFT collections where the floor price is greater than 0.5 ETH, including their names and contract addresses."},{"role":"assistant","content":"SELECT name, contract_address FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH';"},{"role":"user","content":"Can you also include the banner image URL and filter to only show ERC721 collections?"},{"role":"assistant","content":"SELECT name, contract_address, banner_image_url FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721';"},{"role":"user","content":"Now sort these results by floor price in descending order."},{"role":"assistant","content":"SELECT name, contract_address, banner_image_url, floor_price FROM nft_collections WHERE CAST(floor_price AS decimal) > 0.5 AND floor_price_symbol = 'ETH' AND erc_type = 'ERC721' ORDER BY CAST(floor_price AS decimal) DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id.text, first_name.text, last_name.text, date_of_birth.date, gender.text, address.text, phone_number.text, email.text, emergency_contact_name.text, emergency_contact_phone.text, created_at.timestamp, updated_at.timestamp )\nCREATE TABLE healthcare.appointments ( appointment_id.text, patient_id.text, doctor_id.text, appointment_time.timestamp, duration_minutes.integer, reason.text, status.text, location_id.text, notes.text, created_at.timestamp )\nCREATE TABLE healthcare.diagnoses ( diagnosis_id.text, record_id.text, patient_id.text, doctor_id.text, diagnosis_code.text, code_type.text, description.text, diagnosis_date.date, status.text, is_chronic.boolean )\nCREATE TABLE healthcare.prescriptions ( prescription_id.text, record_id.text, patient_id.text, doctor_id.text, medication_id.text, dosage.text, frequency.text, route.text, start_date.date, end_date.date, quantity_dispensed.numeric, refills_allowed.integer, prescription_date.timestamp )\nCREATE TABLE healthcare.insurance_plans ( plan_id.text, plan_name.text, insurance_provider.text, plan_type.text, contact_phone.text, website.text )\n","conversations":[{"role":"user","content":"Find all patients who have been prescribed medications with dosage greater than 50mg, along with their medication details and prescribing doctor's name."},{"role":"assistant","content":"SELECT p.patient_id, p.first_name, p.last_name, pr.dosage, pr.medication_id, pr.start_date, doc.first_name AS doctor_first_name, doc.last_name AS doctor_last_name FROM healthcare.patients p JOIN healthcare.prescriptions pr ON p.patient_id = pr.patient_id JOIN healthcare.doctors doc ON pr.doctor_id = doc.doctor_id WHERE CAST(SUBSTRING_INDEX(pr.dosage, 'mg', 1) AS UNSIGNED) > 50;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.agencies ( agency_id text PRIMARY KEY, agency_name text, jurisdiction_level text, primary_contact_email text, main_phone_number text, website_url text, established_date date, parent_agency_id text )\nCREATE TABLE government_services.applications ( application_id text PRIMARY KEY, citizen_id text, service_id text, submitted_at timestamp, status text, last_updated_at timestamp, assigned_employee_id text, decision_date date, notes text, reference_number text )\nCREATE TABLE government_services.documents ( document_id text PRIMARY KEY, application_id text, citizen_id text, document_type text, file_reference text, upload_timestamp timestamp, expiry_date date, verification_status text, verified_by_employee_id text, verification_timestamp timestamp )\nCREATE TABLE government_services.payments ( payment_id text PRIMARY KEY, application_id text, citizen_id text, service_id text, amount numeric, currency text, payment_method text, payment_provider_reference text, payment_timestamp timestamp, status text, notes text )\nCREATE TABLE government_services.employees ( employee_id text PRIMARY KEY, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\nCREATE TABLE government_services.service_locations ( location_id text PRIMARY KEY, agency_id text, location_name text, address text, city text, state text, postal_code text, latitude numeric, longitude numeric, operating_hours text, contact_phone text, is_accessible boolean )\nCREATE TABLE government_services.appointments ( appointment_id text PRIMARY KEY, citizen_id text, employee_id text, location_id text, service_id text, scheduled_start_time timestamp, scheduled_end_time timestamp, purpose text, status text, booking_method text, created_at timestamp, notes text )\n","conversations":[{"role":"user","content":"For each employee, retrieve their full name and the number of appointments scheduled for them in the next 7 days, including employees with no appointments."},{"role":"assistant","content":"SELECT e.first_name || ' ' || e.last_name AS full_name,\n COUNT(a.appointment_id) AS appointment_count\nFROM government_services.employees e\nLEFT JOIN government_services.appointments a\n ON e.employee_id = a.employee_id\n AND a.scheduled_start_time BETWEEN now() AND now() + INTERVAL '7 days'\nGROUP BY e.first_name, e.last_name;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash text, log_index integer, contract_address text )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address text, wallet_address text, amount text, pk text )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address text, wallet_address text, token_id text, contract_type text, amount text, pk text )\nCREATE TABLE sui_coins ( object_id text, status text, coin_type text, balance text, owner text )\nCREATE TABLE sui_nfts ( object_id text, status text, collection_type text, package_id text, previous_transaction text, display text, owner text, name text )\nCREATE TABLE nft_metadata ( blockchain text, contract_address text, token_id text, contract_name text, erc_type text, amount bigint, minter text, owner text, mint_block_number bigint, mint_time bigint, mint_transaction_hash text, mint_price text, token_uri text, metadata text, name text, image_uri text, traits text, updated_at bigint, status text, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE token_prices ( uuid text, blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain text, address text, decimals bigint, symbol text, price real, timestamp timestamp )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick text, wallet_address text, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id text )\n","conversations":[{"role":"user","content":"Show me all wallet addresses that hold more than 3 different NFTs from any ERC1155 contract. For each wallet, list the contract address and the count of distinct token_ids."},{"role":"assistant","content":"SELECT contract_address, wallet_address, COUNT(DISTINCT token_id) AS token_id_count \nFROM nft_holders \nWHERE contract_type = 'ERC1155'\nGROUP BY contract_address, wallet_address \nHAVING COUNT(DISTINCT token_id) > 3;"},{"role":"user","content":"Can you also tell me the total amount of NFTs held by each of these wallets for the contracts they qualify for?"},{"role":"assistant","content":"SELECT contract_address, wallet_address, COUNT(DISTINCT token_id) AS token_id_count, SUM(CAST(amount AS numeric)) AS total_amount \nFROM nft_holders \nWHERE contract_type = 'ERC1155'\nGROUP BY contract_address, wallet_address \nHAVING COUNT(DISTINCT token_id) > 3;"},{"role":"user","content":"Actually, only include results for contracts where the total number of NFTs held by all wallets is over 1000. Show the contract address in the output."},{"role":"assistant","content":"WITH contract_totals AS (\n SELECT contract_address, SUM(CAST(amount AS numeric)) AS contract_total_amount\n FROM nft_holders\n WHERE contract_type = 'ERC1155'\n GROUP BY contract_address\n HAVING SUM(CAST(amount AS numeric)) > 1000\n)\nSELECT n.contract_address, n.wallet_address, COUNT(DISTINCT n.token_id) AS token_id_count, SUM(CAST(n.amount AS numeric)) AS total_amount \nFROM nft_holders n\nJOIN contract_totals c ON n.contract_address = c.contract_address\nWHERE n.contract_type = 'ERC1155'\nGROUP BY n.contract_address, n.wallet_address \nHAVING COUNT(DISTINCT n.token_id) > 3;"},{"role":"user","content":"Also include the name of the NFT for each token_id if available from nft_metadata. Only show NFTs on the Ethereum blockchain."},{"role":"assistant","content":"WITH contract_totals AS (\n SELECT contract_address, SUM(CAST(amount AS numeric)) AS contract_total_amount\n FROM nft_holders\n WHERE contract_type = 'ERC1155'\n GROUP BY contract_address\n HAVING SUM(CAST(amount AS numeric)) > 1000\n),\nwallet_tokens AS (\n SELECT n.contract_address, n.wallet_address, n.token_id, SUM(CAST(n.amount AS numeric)) AS amount\n FROM nft_holders n\n JOIN contract_totals c ON n.contract_address = c.contract_address\n WHERE n.contract_type = 'ERC1155'\n GROUP BY n.contract_address, n.wallet_address, n.token_id\n)\nSELECT w.contract_address, w.wallet_address, w.token_id, w.amount, m.name AS nft_name\nFROM wallet_tokens w\nLEFT JOIN nft_metadata m\n ON m.blockchain = 'Ethereum' AND m.contract_address = w.contract_address AND m.token_id = w.token_id\nWHERE w.amount > 0;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )\n","conversations":[{"role":"user","content":"Find acquisition event pairs for each player where they acquired two distinct items. Show player_id, the first inventory_id as inv1, the second inventory_id as inv2, and their corresponding item_ids."},{"role":"assistant","content":"SELECT p1.player_id,\n p1.inventory_id AS inv1,\n p1.item_id AS item1,\n p2.inventory_id AS inv2,\n p2.item_id AS item2\nFROM gaming_technology.player_inventory p1\nJOIN gaming_technology.player_inventory p2\n ON p1.player_id = p2.player_id\n AND p1.item_id <> p2.item_id\n AND p1.acquired_at < p2.acquired_at;"},{"role":"user","content":"Also calculate the time difference in minutes between the two acquisitions labeled diff_minutes."},{"role":"assistant","content":"SELECT p1.player_id,\n p1.inventory_id AS inv1,\n p1.item_id AS item1,\n p2.inventory_id AS inv2,\n p2.item_id AS item2,\n EXTRACT(EPOCH FROM (p2.acquired_at - p1.acquired_at)) \/ 60 AS diff_minutes\nFROM gaming_technology.player_inventory p1\nJOIN gaming_technology.player_inventory p2\n ON p1.player_id = p2.player_id\n AND p1.item_id <> p2.item_id\n AND p1.acquired_at < p2.acquired_at;"},{"role":"user","content":"Only include pairs where diff_minutes is less than or equal to 60."},{"role":"assistant","content":"SELECT p1.player_id,\n p1.inventory_id AS inv1,\n p1.item_id AS item1,\n p2.inventory_id AS inv2,\n p2.item_id AS item2,\n EXTRACT(EPOCH FROM (p2.acquired_at - p1.acquired_at)) \/ 60 AS diff_minutes\nFROM gaming_technology.player_inventory p1\nJOIN gaming_technology.player_inventory p2\n ON p1.player_id = p2.player_id\n AND p1.item_id <> p2.item_id\n AND p1.acquired_at < p2.acquired_at\nWHERE EXTRACT(EPOCH FROM (p2.acquired_at - p1.acquired_at)) \/ 60 <= 60;"},{"role":"user","content":"Order the output by player_id and diff_minutes ascending."},{"role":"assistant","content":"SELECT p1.player_id,\n p1.inventory_id AS inv1,\n p1.item_id AS item1,\n p2.inventory_id AS inv2,\n p2.item_id AS item2,\n EXTRACT(EPOCH FROM (p2.acquired_at - p1.acquired_at)) \/ 60 AS diff_minutes\nFROM gaming_technology.player_inventory p1\nJOIN gaming_technology.player_inventory p2\n ON p1.player_id = p2.player_id\n AND p1.item_id <> p2.item_id\n AND p1.acquired_at < p2.acquired_at\nWHERE EXTRACT(EPOCH FROM (p2.acquired_at - p1.acquired_at)) \/ 60 <= 60\nORDER BY p1.player_id, diff_minutes ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\nCREATE TABLE transportation.drivers ( driver_id text PRIMARY KEY, employee_id text, first_name text, last_name text, license_number text, license_expiry_date date, contact_number text, email text, hire_date date, status text )\nCREATE TABLE transportation.routes ( route_id text PRIMARY KEY, route_number text, description text, origin_location_id text, destination_location_id text, distance_km numeric, estimated_duration_minutes int, type text )\nCREATE TABLE transportation.trips ( trip_id text PRIMARY KEY, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count int, cargo_manifest_id text )\nCREATE TABLE transportation.locations ( location_id text PRIMARY KEY, name text, type text, address_line1 text, city text, state_province text, postal_code text, country text, latitude numeric, longitude numeric, timezone text )\nCREATE TABLE transportation.maintenance_logs ( log_id text PRIMARY KEY, vehicle_id text, service_date date, odometer_reading int, service_type text, description text, cost numeric, mechanic_name text, next_service_due_date date )\nCREATE TABLE transportation.fuel_logs ( fuel_log_id text PRIMARY KEY, vehicle_id text, trip_id text, log_timestamp timestamp, fuel_type text, quantity numeric, unit text, cost_per_unit numeric, total_cost numeric, odometer_reading int, location_id text )\nCREATE TABLE transportation.bookings ( booking_id text PRIMARY KEY, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n","conversations":[{"role":"user","content":"Retrieve the vehicle_id, make, model, and the next_service_due_date for each vehicle based on the most recent maintenance log."},{"role":"assistant","content":"SELECT DISTINCT ON (ml.vehicle_id) v.vehicle_id, v.make, v.model, ml.next_service_due_date FROM transportation.maintenance_logs ml JOIN transportation.vehicles v ON v.vehicle_id = ml.vehicle_id ORDER BY ml.vehicle_id, ml.service_date DESC;"},{"role":"user","content":"Now, only include vehicles with status 'Active' and whose next_service_due_date is within the next 30 days, ordering by next_service_due_date ascending."},{"role":"assistant","content":"SELECT v.vehicle_id, v.make, v.model, ml.next_service_due_date FROM transportation.vehicles v JOIN (SELECT DISTINCT ON (vehicle_id) vehicle_id, next_service_due_date FROM transportation.maintenance_logs ORDER BY vehicle_id, service_date DESC) ml ON v.vehicle_id = ml.vehicle_id WHERE v.status = 'Active' AND ml.next_service_due_date BETWEEN current_date AND current_date + INTERVAL '30 days' ORDER BY ml.next_service_due_date ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens ( token_id character varying(64) NOT NULL, contract_address character varying(128) NOT NULL, token_name character varying(128) NOT NULL, token_symbol character varying(32) NOT NULL, decimals integer NOT NULL, total_supply numeric(38,14) NOT NULL, PRIMARY KEY (token_id) )\nCREATE TABLE web3.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) )\n","conversations":[{"role":"user","content":"Show me all token names and their contract addresses along with the wallet addresses of users who created wallets in the last 30 days, sorted by wallet creation date."},{"role":"assistant","content":"SELECT t.token_name, t.contract_address, w.address AS wallet_address FROM web3.tokens t JOIN web3.wallets w ON 1=1 WHERE w.created_at >= CURRENT_DATE - INTERVAL '30 days' ORDER BY w.created_at;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers ( customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, ssn_hash character varying(128), address_line1 character varying(255) NOT NULL, address_line2 character varying(255), city character varying(100) NOT NULL, state character varying(50) NOT NULL, zip_code character varying(20) NOT NULL, country character varying(50) NOT NULL DEFAULT 'USA', phone_number character varying(30), email character varying(128) UNIQUE, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, status character varying(20) NOT NULL DEFAULT 'Active', PRIMARY KEY (customer_id) )\nCREATE TABLE insurance.claims ( claim_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, incident_date timestamp NOT NULL, reported_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text NOT NULL, estimated_loss numeric(15, 2), status character varying(30) NOT NULL, settlement_amount numeric(15, 2), settlement_date date, claim_handler_id character varying(64), police_report_number character varying(100), PRIMARY KEY (claim_id) )\nCREATE TABLE insurance.insurance_products ( product_id character varying(64) NOT NULL, product_name character varying(150) NOT NULL, product_type character varying(50) NOT NULL, description text, base_premium numeric(10, 2) NOT NULL, coverage_details text, underwriting_rules text, is_active boolean NOT NULL DEFAULT true, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at timestamp, PRIMARY KEY (product_id) )\nCREATE TABLE insurance.agents ( agent_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, agency_name character varying(150), license_number character varying(100) NOT NULL UNIQUE, license_state character varying(50) NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(30), hire_date date, termination_date date, status character varying(20) NOT NULL DEFAULT 'Active', commission_rate numeric(5, 4) NOT NULL DEFAULT 0.05, manager_id character varying(64), PRIMARY KEY (agent_id) )\nCREATE TABLE insurance.claim_documents ( document_id character varying(64) NOT NULL, claim_id character varying(64) NOT NULL, document_type character varying(50) NOT NULL, file_name character varying(255) NOT NULL, file_path character varying(512) NOT NULL, file_size_bytes integer, mime_type character varying(100), uploaded_by character varying(64), uploaded_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, description text, PRIMARY KEY (document_id) )\nCREATE TABLE insurance.policy_beneficiaries ( beneficiary_id character varying(64) NOT NULL, policy_id character varying(64) NOT NULL, customer_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, relationship character varying(50) NOT NULL, percentage_share numeric(5, 2) NOT NULL CHECK (percentage_share > 0 AND percentage_share <= 100), contact_info text, added_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (beneficiary_id), UNIQUE (policy_id, customer_id) )\n","conversations":[{"role":"user","content":"Show me all active agents who have a commission rate above 0.08, along with their agency names and the count of claims they've handled."},{"role":"assistant","content":"SELECT a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate, COUNT(cl.claim_id) AS claims_handled FROM insurance.agents a LEFT JOIN insurance.claims cl ON a.agent_id = cl.claim_handler_id WHERE a.status = 'Active' AND a.commission_rate > 0.08 GROUP BY a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate;"},{"role":"user","content":"Actually, I only want to see agents who have handled at least 5 claims and include their hire date."},{"role":"assistant","content":"SELECT a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate, a.hire_date, COUNT(cl.claim_id) AS claims_handled FROM insurance.agents a LEFT JOIN insurance.claims cl ON a.agent_id = cl.claim_handler_id WHERE a.status = 'Active' AND a.commission_rate > 0.08 GROUP BY a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate, a.hire_date HAVING COUNT(cl.claim_id) >= 5;"},{"role":"user","content":"Now include only agents who were hired in the last 3 years and sort them by the number of claims handled in descending order."},{"role":"assistant","content":"SELECT a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate, a.hire_date, COUNT(cl.claim_id) AS claims_handled FROM insurance.agents a LEFT JOIN insurance.claims cl ON a.agent_id = cl.claim_handler_id WHERE a.status = 'Active' AND a.commission_rate > 0.08 AND a.hire_date >= CURRENT_DATE - INTERVAL '3 years' GROUP BY a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate, a.hire_date HAVING COUNT(cl.claim_id) >= 5 ORDER BY claims_handled DESC;"},{"role":"user","content":"Finally, include the average settlement amount for the claims each agent has handled."},{"role":"assistant","content":"SELECT a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate, a.hire_date, COUNT(cl.claim_id) AS claims_handled, AVG(cl.settlement_amount) AS avg_settlement FROM insurance.agents a LEFT JOIN insurance.claims cl ON a.agent_id = cl.claim_handler_id WHERE a.status = 'Active' AND a.commission_rate > 0.08 AND a.hire_date >= CURRENT_DATE - INTERVAL '3 years' AND cl.settlement_amount IS NOT NULL GROUP BY a.agent_id, a.first_name, a.last_name, a.agency_name, a.commission_rate, a.hire_date HAVING COUNT(cl.claim_id) >= 5 ORDER BY claims_handled DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\n","conversations":[{"role":"user","content":"For each game, count how many achievements it has and calculate the average points."},{"role":"assistant","content":"SELECT game_id,\n COUNT(*) AS total_achievements,\n AVG(points) AS avg_points\nFROM achievements\nGROUP BY game_id;"},{"role":"user","content":"Actually, only count visible achievements (hidden = false)."},{"role":"assistant","content":"SELECT game_id,\n COUNT(*) AS visible_achievements,\n AVG(points) AS avg_points\nFROM achievements\nWHERE hidden = false\nGROUP BY game_id;"},{"role":"user","content":"Also include the total count of hidden achievements per game."},{"role":"assistant","content":"SELECT v.game_id,\n v.visible_achievements,\n v.avg_points,\n h.hidden_count\nFROM (\n SELECT game_id,\n COUNT(*) AS visible_achievements,\n AVG(points) AS avg_points\n FROM achievements\n WHERE hidden = false\n GROUP BY game_id\n) v\nLEFT JOIN (\n SELECT game_id,\n COUNT(*) AS hidden_count\n FROM achievements\n WHERE hidden = true\n GROUP BY game_id\n) h ON v.game_id = h.game_id;"},{"role":"user","content":"Now filter the results to only games with at least 3 visible achievements."},{"role":"assistant","content":"SELECT v.game_id,\n v.visible_achievements,\n v.avg_points,\n h.hidden_count\nFROM (\n SELECT game_id,\n COUNT(*) AS visible_achievements,\n AVG(points) AS avg_points\n FROM achievements\n WHERE hidden = false\n GROUP BY game_id\n HAVING COUNT(*) >= 3\n) v\nLEFT JOIN (\n SELECT game_id,\n COUNT(*) AS hidden_count\n FROM achievements\n WHERE hidden = true\n GROUP BY game_id\n) h ON v.game_id = h.game_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.transactions ( transaction_id text, block_id text, sender_address text, receiver_address text, amount numeric, timestamp timestamp, signature text )\nCREATE TABLE blockchain.smart_contracts ( contract_id text, creator_address text, code text, timestamp timestamp )\n","conversations":[{"role":"user","content":"I want to know how many times each smart contract has been invoked by transactions; also include the contract creator."},{"role":"assistant","content":"SELECT sc.contract_id, sc.creator_address, COUNT(t.transaction_id) AS invocation_count\nFROM blockchain.smart_contracts sc\nLEFT JOIN blockchain.transactions t\n ON t.receiver_address = sc.contract_id\nGROUP BY sc.contract_id, sc.creator_address;"},{"role":"user","content":"I'd like to see only contracts with more than 100 invocations."},{"role":"assistant","content":"SELECT sc.contract_id, sc.creator_address, COUNT(t.transaction_id) AS invocation_count\nFROM blockchain.smart_contracts sc\nLEFT JOIN blockchain.transactions t\n ON t.receiver_address = sc.contract_id\nGROUP BY sc.contract_id, sc.creator_address\nHAVING COUNT(t.transaction_id) > 100;"},{"role":"user","content":"Actually, I want to order them by invocation_count descending and limit to the top 5."},{"role":"assistant","content":"SELECT sc.contract_id, sc.creator_address, COUNT(t.transaction_id) AS invocation_count\nFROM blockchain.smart_contracts sc\nLEFT JOIN blockchain.transactions t\n ON t.receiver_address = sc.contract_id\nGROUP BY sc.contract_id, sc.creator_address\nHAVING COUNT(t.transaction_id) > 100\nORDER BY invocation_count DESC\nLIMIT 5;"},{"role":"user","content":"Also, show the timestamp when each of those top 5 contracts was created."},{"role":"assistant","content":"SELECT sc.contract_id, sc.creator_address, sc.timestamp AS creation_time, COUNT(t.transaction_id) AS invocation_count\nFROM blockchain.smart_contracts sc\nLEFT JOIN blockchain.transactions t\n ON t.receiver_address = sc.contract_id\nGROUP BY sc.contract_id, sc.creator_address, sc.timestamp\nHAVING COUNT(t.transaction_id) > 100\nORDER BY invocation_count DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers ( lawyer_id.text, first_name.text, last_name.text, bar_number.text, firm_id.text, email.text, phone.text, specialization.text, hire_date.timestamp, is_partner.boolean )\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n","conversations":[{"role":"user","content":"List all 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;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp timestamp, block_number bigint, transaction_hash varchar, transaction_index bigint, from_address varchar, contract_address varchar, symbol varchar, total_supply varchar, name varchar, decimals bigint, is_erc20 integer, is_erc721 integer, is_erc1155 integer, is_proxy integer, extra_info varchar, pk integer )\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk integer )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holder_historical ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk integer )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_coins_metadata ( object_id varchar, coin_type varchar, status varchar, decimals bigint, description varchar, icon_url varchar, symbol varchar, name varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\n","conversations":[{"role":"user","content":"For each ERC20 token, I need the total historical balance and number of unique holders from erc20_balances_historical. Include contract_address, total_balance, holder_count, symbol, and decimals."},{"role":"assistant","content":"SELECT bh.contract_address,\n SUM(CAST(bh.amount AS numeric)) AS total_balance,\n COUNT(DISTINCT bh.wallet_address) AS holder_count,\n tm.symbol,\n tm.decimals\nFROM erc20_balances_historical AS bh\nJOIN token_metas AS tm\n ON bh.contract_address = tm.contract_address\nGROUP BY bh.contract_address, tm.symbol, tm.decimals\nORDER BY total_balance DESC;"},{"role":"user","content":"Now filter only tokens where total_balance > 1000000 and sort by total_balance descending."},{"role":"assistant","content":"SELECT bh.contract_address,\n SUM(CAST(bh.amount AS numeric)) AS total_balance,\n COUNT(DISTINCT bh.wallet_address) AS holder_count,\n tm.symbol,\n tm.decimals\nFROM erc20_balances_historical AS bh\nJOIN token_metas AS tm\n ON bh.contract_address = tm.contract_address\nGROUP BY bh.contract_address, tm.symbol, tm.decimals\nHAVING SUM(CAST(bh.amount AS numeric)) > 1000000\nORDER BY total_balance DESC;"},{"role":"user","content":"Also limit to top 5 tokens and include the latest USD price by joining token_prices_latest on address = contract_address."},{"role":"assistant","content":"SELECT t.contract_address,\n t.total_balance,\n t.holder_count,\n t.symbol,\n t.decimals,\n tpl.price AS latest_price\nFROM (\n SELECT bh.contract_address,\n SUM(CAST(bh.amount AS numeric)) AS total_balance,\n COUNT(DISTINCT bh.wallet_address) AS holder_count,\n tm.symbol,\n tm.decimals\n FROM erc20_balances_historical AS bh\n JOIN token_metas AS tm\n ON bh.contract_address = tm.contract_address\n GROUP BY bh.contract_address, tm.symbol, tm.decimals\n HAVING SUM(CAST(bh.amount AS numeric)) > 1000000\n) AS t\nJOIN token_prices_latest AS tpl\n ON t.contract_address = tpl.address\nORDER BY t.total_balance DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\n","conversations":[{"role":"user","content":"I want to see, for each guest, the total number of payments they have made and the timestamp of their latest payment."},{"role":"assistant","content":"SELECT p.guest_id,\n COUNT(p.payment_id) AS payment_count,\n t.last_ts\nFROM hospitality_technology.payments p\nJOIN (\n SELECT guest_id,\n MAX(payment_timestamp) AS last_ts\n FROM hospitality_technology.payments\n GROUP BY guest_id\n) t ON p.guest_id = t.guest_id\nGROUP BY p.guest_id, t.last_ts;"},{"role":"user","content":"Only include guests whose latest payment status was 'Succeeded' and who have made at least 5 successful payments."},{"role":"assistant","content":"SELECT p.guest_id,\n COUNT(p.payment_id) AS payment_count,\n t.last_ts\nFROM hospitality_technology.payments p\nJOIN (\n SELECT guest_id,\n MAX(payment_timestamp) AS last_ts,\n COUNT(*) AS cnt\n FROM hospitality_technology.payments\n WHERE status = 'Succeeded'\n GROUP BY guest_id\n HAVING COUNT(*) >= 5\n) t ON p.guest_id = t.guest_id\nGROUP BY p.guest_id, t.last_ts;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE trading_platform.wallets ( wallet_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, address character varying(128) NOT NULL, private_key text NOT NULL, created_at timestamp NOT NULL, PRIMARY KEY (wallet_id) )\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades (\n trade_id character varying(64) NOT NULL, -- unique identifier for the trade\n order_id character varying(64) NOT NULL, -- identifier of the order that led to the trade\n buyer_id character varying(64) NOT NULL, -- identifier of the buyer\n seller_id character varying(64) NOT NULL, -- identifier of the seller\n asset_id character varying(64) NOT NULL, -- identifier of the asset being traded\n quantity numeric(38,14) NOT NULL, -- quantity of the asset in the trade\n price numeric(38,14) NOT NULL, -- price per unit of the asset\n traded_at timestamp NOT NULL, -- time when the trade was executed\n PRIMARY KEY (trade_id)\n)\nCREATE TABLE trading_platform.assets ( asset_id text PRIMARY KEY, name text, symbol text, type text )\nCREATE TABLE trading_platform.utxos ( utxo_id.text, transaction_id.text, output_index.integer, address.text, amount.numeric, spent.boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id.text, name.text, description.text, url.text )\nCREATE TABLE trading_platform.metadata (\n metadata_id character varying(64) NOT NULL, -- unique identifier for the metadata\n asset_id character varying(64) NOT NULL, -- identifier of the asset the metadata is associated with\n key character varying(128) NOT NULL, -- key of the metadata\n value text NOT NULL, -- value of the metadata\n PRIMARY KEY (metadata_id)\n)\nCREATE TABLE trading_platform.kyc_audit (\n kyc_audit_id character varying(64) NOT NULL, -- unique identifier for the KYC audit\n user_id character varying(64) NOT NULL, -- identifier of the user being audited\n status character varying(32) NOT NULL, -- status of the KYC audit (e.g., pending, approved, rejected)\n reviewed_at timestamp NOT NULL, -- time when the KYC audit was reviewed\n PRIMARY KEY (kyc_audit_id)\n)\n","conversations":[{"role":"user","content":"Show me the total value of assets purchased by each user (sum of quantity * price for trades where they were the buyer). Include user ID and username."},{"role":"assistant","content":"SELECT T1.user_id , T1.username , sum(T2.quantity * T2.price) FROM trading_platform.users AS T1 JOIN trading_platform.trades AS T2 ON T1.user_id = T2.buyer_id GROUP BY T1.user_id , T1.username"},{"role":"user","content":"Filter this list to only include users whose total buy value is greater than 500."},{"role":"assistant","content":"SELECT T1.user_id , T1.username , sum(T2.quantity * T2.price) FROM trading_platform.users AS T1 JOIN trading_platform.trades AS T2 ON T1.user_id = T2.buyer_id GROUP BY T1.user_id , T1.username HAVING sum(T2.quantity * T2.price) > 500"},{"role":"user","content":"Now, also include the total value of assets they have sold (sum of quantity * price for trades where they were the seller) in the same report."},{"role":"assistant","content":"SELECT T1.user_id , T1.username , COALESCE(buy_trades.total_buy_value, 0) AS total_buy_value , COALESCE(sell_trades.total_sell_value, 0) AS total_sell_value FROM trading_platform.users AS T1 LEFT JOIN (SELECT buyer_id, sum(quantity * price) AS total_buy_value FROM trading_platform.trades GROUP BY buyer_id) AS buy_trades ON T1.user_id = buy_trades.buyer_id LEFT JOIN (SELECT seller_id, sum(quantity * price) AS total_sell_value FROM trading_platform.trades GROUP BY seller_id) AS sell_trades ON T1.user_id = sell_trades.seller_id WHERE COALESCE(buy_trades.total_buy_value, 0) > 500"},{"role":"user","content":"Finally, only show users who have *both* bought and sold assets (total buy value > 0 and total sell value > 0)."},{"role":"assistant","content":"SELECT T1.user_id , T1.username , COALESCE(buy_trades.total_buy_value, 0) AS total_buy_value , COALESCE(sell_trades.total_sell_value, 0) AS total_sell_value FROM trading_platform.users AS T1 LEFT JOIN (SELECT buyer_id, sum(quantity * price) AS total_buy_value FROM trading_platform.trades GROUP BY buyer_id) AS buy_trades ON T1.user_id = buy_trades.buyer_id LEFT JOIN (SELECT seller_id, sum(quantity * price) AS total_sell_value FROM trading_platform.trades GROUP BY seller_id) AS sell_trades ON T1.user_id = sell_trades.seller_id WHERE COALESCE(buy_trades.total_buy_value, 0) > 500 AND COALESCE(sell_trades.total_sell_value, 0) > 0"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar )\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holders ( block_number bigint, contract_address varchar, wallet_address varchar, token_id varchar, contract_type varchar, amount varchar, pk varchar )\nCREATE TABLE sui_coins ( object_id varchar, status varchar, coin_type varchar, balance varchar, owner varchar )\nCREATE TABLE sui_nfts ( object_id varchar, status varchar, collection_type varchar, package_id varchar, previous_transaction varchar, display varchar, owner varchar, name varchar )\nCREATE TABLE nft_metadata ( blockchain varchar, contract_address varchar, token_id varchar, contract_name varchar, erc_type varchar, amount bigint, minter varchar, owner varchar, mint_block_number bigint, mint_time bigint, mint_transaction_hash varchar, mint_price varchar, token_uri varchar, metadata varchar, name varchar, image_uri varchar, traits varchar, updated_at bigint, status varchar, rarity_score real, rarity_rank integer, unique_attribute_count integer, pk integer )\nCREATE TABLE nft_collections ( blockchain varchar, contract_address varchar, name varchar, symbol varchar, deploy_block_number bigint, deploy_block_time bigint, erc_type varchar, owner varchar, traits varchar, description varchar, slug varchar, media_info varchar, image_url varchar, banner_image_url varchar, updated_at bigint, banner varchar, token_count bigint, floor_price varchar, floor_price_symbol varchar, floor_price_contract varchar, pk integer )\nCREATE TABLE token_prices ( uuid varchar, blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE token_prices_latest ( blockchain varchar, address varchar, decimals bigint, symbol varchar, price real, timestamp timestamp )\nCREATE TABLE erc20_approval ( block_number bigint, block_timestamp timestamp, transaction_index integer, transaction_hash varchar, log_index integer, contract_address varchar, pk integer )\nCREATE TABLE token_balances ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE mud_holesky_redstone ( address varchar, table_id varchar, key_bytes varchar, key0 varchar, key1 varchar, static_data varchar, encoded_lengths varchar, dynamic_data varchar, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply varchar, amount varchar )\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche ( block_number bigint, block_timestamp timestamp, tick varchar, wallet_address varchar, total_supply decimal, amount decimal )\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"List all Avalanche tokens by their tick with the total amount currently held across all wallets."},{"role":"assistant","content":"SELECT tick, SUM(CAST(amount AS DECIMAL)) AS total_supply FROM token_balances_avalanche GROUP BY tick"},{"role":"user","content":"Add the creator address for each token."},{"role":"assistant","content":"SELECT tb.tick, SUM(CAST(tb.amount AS DECIMAL)) AS total_supply, ti.creator FROM token_balances_avalanche AS tb JOIN token_info_avalanche AS ti ON tb.tick = ti.tick GROUP BY tb.tick, ti.creator"},{"role":"user","content":"Only show tokens where the total supply is greater than 10000."},{"role":"assistant","content":"SELECT tb.tick, SUM(CAST(tb.amount AS DECIMAL)) AS total_supply, ti.creator FROM token_balances_avalanche AS tb JOIN token_info_avalanche AS ti ON tb.tick = ti.tick GROUP BY tb.tick, ti.creator HAVING SUM(CAST(tb.amount AS DECIMAL)) > 10000"},{"role":"user","content":"Order the results by total supply descending and limit to top 5."},{"role":"assistant","content":"SELECT tb.tick, SUM(CAST(tb.amount AS DECIMAL)) AS total_supply, ti.creator FROM token_balances_avalanche AS tb JOIN token_info_avalanche AS ti ON tb.tick = ti.tick GROUP BY tb.tick, ti.creator HAVING SUM(CAST(tb.amount AS DECIMAL)) > 10000 ORDER BY total_supply DESC LIMIT 5"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\nCREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.cases ( case_id.text, case_number.text, case_name.text, client_id.text, lead_lawyer_id.text, case_type.text, status.text, date_opened.timestamp, date_closed.timestamp, description.text, court_jurisdiction.text )\nCREATE TABLE legal_services.invoices ( invoice_id.text, invoice_number.text, client_id.text, case_id.text, issue_date.date, due_date.date, total_amount.numeric, amount_paid.numeric, status.text, payment_date.timestamp, notes.text, created_at.timestamp )\nCREATE TABLE legal_services.appointments (\n appointment_id character varying(64) NOT NULL, -- unique identifier for the appointment\n client_id character varying(64) NOT NULL, -- FK to clients table\n lawyer_id character varying(64) NOT NULL, -- FK to lawyers table\n case_id character varying(64), -- FK to cases table (optional, if related to a specific case)\n start_time timestamp NOT NULL, -- scheduled start date and time\n end_time timestamp NOT NULL, -- scheduled end date and time\n location text, -- location of the meeting (address or virtual link)\n subject character varying(255), -- subject or purpose of the appointment\n notes text, -- additional notes for the appointment\n status character varying(50) NOT NULL, -- e.g., Scheduled, Completed, Canceled, Rescheduled\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (appointment_id)\n)\n","conversations":[{"role":"user","content":"List all cases where the client and the lead lawyer belong to companies or law firms with the same phone number. For each such case, please show the case name, client name, client company, lead lawyer name, and the shared phone number."},{"role":"assistant","content":"SELECT cases.case_name, c.first_name AS client_first_name, c.last_name AS client_last_name, c.company_name, l.first_name AS lawyer_first_name, l.last_name AS lawyer_last_name, f.phone AS shared_phone\nFROM legal_services.cases\nJOIN legal_services.clients c ON cases.client_id = c.client_id\nJOIN legal_services.lawyers l ON cases.lead_lawyer_id = l.lawyer_id\nJOIN legal_services.law_firms f ON l.firm_id = f.firm_id\nWHERE c.phone = f.phone;"},{"role":"user","content":"Can you include the case number and sort the results by the shared phone number?"},{"role":"assistant","content":"SELECT cases.case_number, cases.case_name, c.first_name AS client_first_name, c.last_name AS client_last_name, c.company_name, l.first_name AS lawyer_first_name, l.last_name AS lawyer_last_name, f.phone AS shared_phone\nFROM legal_services.cases\nJOIN legal_services.clients c ON cases.client_id = c.client_id\nJOIN legal_services.lawyers l ON cases.lead_lawyer_id = l.lawyer_id\nJOIN legal_services.law_firms f ON l.firm_id = f.firm_id\nWHERE c.phone = f.phone\nORDER BY f.phone;"},{"role":"user","content":"Actually, please only show cases where the shared phone number is not null and starts with '+44'."},{"role":"assistant","content":"SELECT cases.case_number, cases.case_name, c.first_name AS client_first_name, c.last_name AS client_last_name, c.company_name, l.first_name AS lawyer_first_name, l.last_name AS lawyer_last_name, f.phone AS shared_phone\nFROM legal_services.cases\nJOIN legal_services.clients c ON cases.client_id = c.client_id\nJOIN legal_services.lawyers l ON cases.lead_lawyer_id = l.lawyer_id\nJOIN legal_services.law_firms f ON l.firm_id = f.firm_id\nWHERE c.phone = f.phone AND f.phone IS NOT NULL AND f.phone LIKE '+44%'\nORDER BY f.phone;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n","conversations":[{"role":"user","content":"For each citizen who has made at least one payment, show the citizen's full name, number of payments, and total amount paid, grouped by currency."},{"role":"assistant","content":"SELECT\n c.first_name || ' ' || c.last_name AS full_name,\n p.currency,\n COUNT(*) AS payment_count,\n SUM(p.amount) AS total_amount\nFROM government_services.citizens c\nJOIN government_services.payments p ON c.citizen_id = p.citizen_id\nGROUP BY full_name, p.currency;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.documents ( document_id.text, case_id.text, document_name.text, document_type.text, storage_path.text, uploaded_by_lawyer_id.text, upload_timestamp.timestamp, version.integer, description.text )\nCREATE TABLE legal_services.appointments ( appointment_id.text, client_id.text, lawyer_id.text, case_id.text, start_time.timestamp, end_time.timestamp, location.text, subject.text, notes.text, status.text, created_at.timestamp )\n","conversations":[{"role":"user","content":"List the document names and subjects of appointments that are linked to the same case, but only for documents uploaded after March 1st, 2024."},{"role":"assistant","content":"SELECT d.document_name, a.subject, d.case_id\nFROM legal_services.documents d\nJOIN legal_services.appointments a ON d.case_id = a.case_id\nWHERE d.upload_timestamp > '2024-03-01';"},{"role":"user","content":"Can you make it so the appointments must have a non-null location?"},{"role":"assistant","content":"SELECT d.document_name, a.subject, d.case_id\nFROM legal_services.documents d\nJOIN legal_services.appointments a ON d.case_id = a.case_id\nWHERE d.upload_timestamp > '2024-03-01' AND a.location IS NOT NULL;"},{"role":"user","content":"Add the document type and the appointment start time to the results."},{"role":"assistant","content":"SELECT d.document_name, d.document_type, a.subject, a.start_time, d.case_id\nFROM legal_services.documents d\nJOIN legal_services.appointments a ON d.case_id = a.case_id\nWHERE d.upload_timestamp > '2024-03-01' AND a.location IS NOT NULL;"},{"role":"user","content":"Now only include appointments whose status is not 'cancelled', and order by start_time ascending."},{"role":"assistant","content":"SELECT d.document_name, d.document_type, a.subject, a.start_time, d.case_id\nFROM legal_services.documents d\nJOIN legal_services.appointments a ON d.case_id = a.case_id\nWHERE d.upload_timestamp > '2024-03-01'\n AND a.location IS NOT NULL\n AND a.status <> 'cancelled'\nORDER BY a.start_time ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.comments ( comment_id text, post_id text, user_id text, parent_comment_id text, content text, created_at timestamp, updated_at timestamp )\nCREATE TABLE social_media.likes ( like_id text, user_id text, post_id text, comment_id text, created_at timestamp )\nCREATE TABLE social_media.follows ( follow_id text, follower_user_id text, following_user_id text, created_at timestamp )\nCREATE TABLE social_media.messages ( message_id text, conversation_id text, sender_user_id text, content text, media_url text, media_type text, sent_at timestamp, read_at timestamp )\nCREATE TABLE social_media.conversations ( conversation_id text, created_at timestamp, last_message_at timestamp, is_group_chat boolean, group_name text )\nCREATE TABLE social_media.conversation_participants ( participant_id text, conversation_id text, user_id text, joined_at timestamp, last_read_at timestamp )\n","conversations":[{"role":"user","content":"I want the list of participants in group chats who have unread messages, including conversation ID, group name, user ID, and the timestamp of the last message that the user hasn\u2019t read."},{"role":"assistant","content":"SELECT cp.conversation_id,\n c.group_name,\n cp.user_id,\n c.last_message_at\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp\n ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = true\n AND (cp.last_read_at IS NULL OR cp.last_read_at < c.last_message_at);"},{"role":"user","content":"Now, only include those group chats where the last unread message was sent in the past 7 days."},{"role":"assistant","content":"SELECT cp.conversation_id,\n c.group_name,\n cp.user_id,\n c.last_message_at\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp\n ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = true\n AND (cp.last_read_at IS NULL OR cp.last_read_at < c.last_message_at)\n AND c.last_message_at >= now() - INTERVAL '7 days';"},{"role":"user","content":"Also calculate the delay in hours between the last message and the user's last read time and include it as unread_delay_hours."},{"role":"assistant","content":"SELECT cp.conversation_id,\n c.group_name,\n cp.user_id,\n c.last_message_at,\n EXTRACT(EPOCH FROM (c.last_message_at - COALESCE(cp.last_read_at, '1970-01-01'))) \/ 3600 AS unread_delay_hours\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp\n ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = true\n AND (cp.last_read_at IS NULL OR cp.last_read_at < c.last_message_at)\n AND c.last_message_at >= now() - INTERVAL '7 days';"},{"role":"user","content":"Finally, order the results by unread_delay_hours descending and limit the output to 10 records."},{"role":"assistant","content":"SELECT cp.conversation_id,\n c.group_name,\n cp.user_id,\n c.last_message_at,\n EXTRACT(EPOCH FROM (c.last_message_at - COALESCE(cp.last_read_at, '1970-01-01'))) \/ 3600 AS unread_delay_hours\nFROM social_media.conversations c\nJOIN social_media.conversation_participants cp\n ON c.conversation_id = cp.conversation_id\nWHERE c.is_group_chat = true\n AND (cp.last_read_at IS NULL OR cp.last_read_at < c.last_message_at)\n AND c.last_message_at >= now() - INTERVAL '7 days'\nORDER BY unread_delay_hours DESC\nLIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\n \"CREATE TABLE project_fundraising_record (\",\n \"id character varying(32) NOT NULL, -- fundraising record id\",\n \"project_id character varying(32) NOT NULL, -- the invested project's id\",\n \"project_name character varying(128) NOT NULL, -- name of the invested project\",\n \"rounds_name character varying(32), -- name of the fundraising round\",\n \"investment_value numeric(38,14), -- amount of the fundraising in USD\",\n \"investment_date character varying(128), -- the date of the investment happened\",\n \"introduction character varying(128), -- the introduction of the invested project\",\n \"valuation numeric(38,14), -- the valuation of the project in USD when invested\",\n\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\nCREATE TABLE token_dexpool_info ( pair_address character varying(512) NOT NULL, token_name character varying(100) NOT NULL, token_symbol character varying(100) NOT NULL, chain text, price double precision, price_change_percentage_1h double precision, price_change_percentage_6h double precision, price_change_percentage_24h double precision, makers_24h double precision, volume_24h double precision, liquidity double precision, market_cap double precision, trend_rank bigint )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, rank INT, profit numeric(38,6), roi numeric(38,2), realized_ratio numeric(38,2), most_profit_token character varying(100), last_trade_time character varying(100), chain character varying(100) )\n \"CREATE TABLE smart_money_token_performance (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"pnl numeric(38,2), -- the profit users made on this token\",\n \"net_flow numeric(38,2), -- the netflow of the token, means the money user spent minus the the money user sold of this token\",\n \"avg_cost numeric(38,16), -- the average cost price of user spent on this token\",\n \"price double precision, -- the current price of the token\",\n \"realized_ratio numeric(10,2), -- the ratio user sold of the token\",\n \"roi numeric(10,2), -- the roi users made of this token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \"PRIMARY KEY (token_address, chain));\",\n\n \"CREATE TABLE smart_money_token_inflow (\",\n \"token_address character varying(100) NOT NULL, -- the token's address\",\n \"token_symbol character varying(100), -- the tokens's symbol\",\n \"token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token\",\n \"usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token\",\n \"avg_price numeric(38,6), -- the average cost price of user spent on this token\",\n \"type int, -- the direction of the trade on this token. 1 means buying, 2 means selling\",\n \"address_amount integer, -- the amount of the user bought this token\",\n \"narrative character varying(100), -- the category or narrative of the token\",\n \"chain character varying(100), -- the chain that the token resides\",\n \",PRIMARY KEY (token_address, chain)\",\n\n","conversations":[{"role":"user","content":"Show me the top 5 projects by valuation that completed fundraising rounds in the last 12 months, along with their token symbol and price from the token_basic_info table."},{"role":"assistant","content":"SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) ORDER BY pfr.valuation DESC LIMIT 5;"},{"role":"user","content":"Can you also include the 24-hour trading volume for these projects' tokens and filter to only include projects with valuation over $100 million?"},{"role":"assistant","content":"SELECT pfr.project_name, pfr.valuation, tbi.token_symbol, tbi.price, tbi.total_volume FROM project_fundraising_record pfr LEFT JOIN token_basic_info tbi ON pfr.project_name = tbi.token_name WHERE pfr.investment_date >= DATE_SUB(CURRENT_DATE, INTERVAL 12 MONTH) AND pfr.valuation > 100000000 ORDER BY pfr.valuation DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.rooms ( room_id text, property_id text, room_number text, room_type_id text, floor integer, status text, is_smoking boolean, features text, current_condition text, last_cleaned_at timestamp )\nCREATE TABLE hospitality_technology.room_types ( room_type_id text, property_id text, type_name text, description text, base_rate numeric, max_occupancy integer, bed_type text, area_sqft numeric, amenities text )\nCREATE TABLE hospitality_technology.guests ( guest_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, email character varying(255) UNIQUE, phone_number character varying(30), date_of_birth date, address_line1 character varying(255), city character varying(100), state_province character varying(100), postal_code character varying(20), country_code character varying(3), preferences text, loyalty_member_id character varying(64) UNIQUE, communication_consent boolean DEFAULT true, created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, PRIMARY KEY (guest_id) )\nCREATE TABLE hospitality_technology.staff ( staff_id text PRIMARY KEY, property_id text, first_name text, last_name text, position text, work_email text, work_phone text, hire_date date, termination_date date, is_active boolean, access_level int, manager_id text, created_at timestamp )\nCREATE TABLE hospitality_technology.services ( service_id text PRIMARY KEY, property_id text, service_name text, description text, category text, price numeric, unit text, is_available boolean, department text )\nCREATE TABLE hospitality_technology.service_orders ( order_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, staff_id_ordered character varying(64), staff_id_delivered character varying(64), order_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, delivery_timestamp timestamp with time zone, quantity integer NOT NULL DEFAULT 1, unit_price numeric(10, 2) NOT NULL, total_price numeric(12, 2) NOT NULL, status character varying(50) NOT NULL, notes text, bill_id character varying(64), PRIMARY KEY (order_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (service_id) REFERENCES hospitality_technology.services(service_id), FOREIGN KEY (staff_id_ordered) REFERENCES hospitality_technology.staff(staff_id), FOREIGN KEY (staff_id_delivered) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.payments ( payment_id character varying(64) NOT NULL, reservation_id character varying(64), guest_id character varying(64) NOT NULL, bill_id character varying(64), amount numeric(12,2) NOT NULL, currency_code character varying(3) NOT NULL, payment_method character varying(50) NOT NULL, card_type character varying(50), card_last_four character varying(4), transaction_ref character varying(128), payment_timestamp timestamp with time zone NOT NULL DEFAULT current_timestamp, status character varying(50) NOT NULL, staff_id_processed character varying(64), notes text, PRIMARY KEY (payment_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (staff_id_processed) REFERENCES hospitality_technology.staff(staff_id) )\nCREATE TABLE hospitality_technology.reviews ( review_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, reservation_id character varying(64) UNIQUE, guest_id character varying(64) NOT NULL, rating_overall integer, rating_cleanliness integer, rating_service integer, rating_location integer, rating_value integer, comment text, review_source character varying(100), review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, is_public boolean DEFAULT true, staff_response text, response_staff_id character varying(64), response_date timestamp with time zone, PRIMARY KEY (review_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id), FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id), FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id), FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id) )\n","conversations":[{"role":"user","content":"List all staff members showing their full name and position."},{"role":"assistant","content":"SELECT first_name || ' ' || last_name AS staff_full_name, position FROM hospitality_technology.staff;"},{"role":"user","content":"Now only include staff who are not currently active and were hired before 2020."},{"role":"assistant","content":"SELECT first_name || ' ' || last_name AS staff_full_name, position FROM hospitality_technology.staff WHERE is_active = false AND hire_date < '2020-01-01';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_metas ( block_timestamp.timestamp, block_number.bigint, transaction_hash.text, transaction_index.bigint, from_address.text, contract_address.text, symbol.text, total_supply.text, name.text, decimals.bigint, is_erc20.integer, is_erc721.integer, is_erc1155.integer, is_proxy.integer, extra_info.text, pk.integer )\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE nft_holder_historical (\n block_number bigint NOT NULL, -- Block number containing the transaction\n contract_address varchar NOT NULL, -- Event contract address\n wallet_address varchar NOT NULL, -- The wallet address for the contract(with bloom filter)\n token_id varchar NOT NULL, -- NFT token id\n contract_type varchar NOT NULL, -- NFT contract type\n amount varchar NOT NULL, -- The quantity held in the wallet\n pk integer NOT NULL -- Partition key for the table(floor(block_number \/ 7200))\n)\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE nft_metadata ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, token_id varchar NOT NULL, contract_name varchar NOT NULL, erc_type varchar NOT NULL, amount bigint NOT NULL, minter varchar NOT NULL, owner varchar NOT NULL, mint_block_number bigint NOT NULL, mint_time bigint NOT NULL, mint_transaction_hash varchar NOT NULL, mint_price varchar NOT NULL, token_uri varchar NOT NULL, metadata varchar NOT NULL, name varchar NOT NULL, image_uri varchar NOT NULL, traits varchar NOT NULL, updated_at bigint NOT NULL, status varchar NOT NULL, rarity_score real NOT NULL, rarity_rank integer NOT NULL, unique_attribute_count integer NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\n","conversations":[{"role":"user","content":"Which ERC1155 NFT contracts on Ethereum have more than 25 approval-for-all events? List their contract addresses and approval counts."},{"role":"assistant","content":"SELECT ea.contract_address, COUNT(*) AS approval_count\nFROM erc1155_approval_for_all ea\nGROUP BY ea.contract_address\nHAVING COUNT(*) > 25;"},{"role":"user","content":"Can you include the collection name for each contract by joining with nft_metadata? Only include collections on Ethereum."},{"role":"assistant","content":"SELECT ea.contract_address, nm.contract_name, COUNT(*) AS approval_count\nFROM erc1155_approval_for_all ea\nJOIN nft_metadata nm\n ON ea.contract_address = nm.contract_address\nWHERE nm.blockchain = 'Ethereum'\nGROUP BY ea.contract_address, nm.contract_name\nHAVING COUNT(*) > 25;"},{"role":"user","content":"I only want contracts with erc_type 'ERC1155' in the metadata and with at least 5 unique holders in nft_holders. Please include the unique holder count."},{"role":"assistant","content":"SELECT ea.contract_address, nm.contract_name, COUNT(*) AS approval_count, COUNT(DISTINCT nh.wallet_address) AS unique_holder_count\nFROM erc1155_approval_for_all ea\nJOIN nft_metadata nm\n ON ea.contract_address = nm.contract_address\nJOIN nft_holders nh\n ON nh.contract_address = ea.contract_address\nWHERE nm.blockchain = 'Ethereum' AND nm.erc_type = 'ERC1155'\nGROUP BY ea.contract_address, nm.contract_name\nHAVING approval_count > 25 AND COUNT(DISTINCT nh.wallet_address) >= 5;"},{"role":"user","content":"Sort the results by approval_count in descending order and only return the top 10 contracts."},{"role":"assistant","content":"SELECT ea.contract_address, nm.contract_name, COUNT(*) AS approval_count, COUNT(DISTINCT nh.wallet_address) AS unique_holder_count\nFROM erc1155_approval_for_all ea\nJOIN nft_metadata nm ON ea.contract_address = nm.contract_address\nJOIN nft_holders nh ON nh.contract_address = ea.contract_address\nWHERE nm.blockchain = 'Ethereum' AND nm.erc_type = 'ERC1155'\nGROUP BY ea.contract_address, nm.contract_name\nHAVING COUNT(*) > 25 AND COUNT(DISTINCT nh.wallet_address) >= 5\nORDER BY approval_count DESC\nLIMIT 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.properties (\n property_id character varying(64) NOT NULL, -- unique identifier for the property (hotel, resort, etc.)\n property_name character varying(255) NOT NULL, -- name of the property\n address_line1 character varying(255) NOT NULL, -- primary address line\n address_line2 character varying(255), -- secondary address line\n city character varying(100) NOT NULL, -- city\n state_province character varying(100), -- state or province\n postal_code character varying(20) NOT NULL, -- zip or postal code\n country_code character varying(3) NOT NULL, -- ISO country code (e.g., USA, CAN)\n phone_number character varying(30), -- main contact phone\n email_address character varying(255), -- main contact email\n property_type character varying(50) NOT NULL, -- e.g., Hotel, Resort, B&B, Motel\n star_rating numeric(2,1), -- star rating (e.g., 4.5)\n timezone character varying(64) NOT NULL, -- IANA timezone ID (e.g., America\/New_York)\n manager_staff_id character varying(64), -- FK to staff table for the general manager\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record creation time\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp, -- record last update time\n PRIMARY KEY (property_id)\n)\nCREATE TABLE hospitality_technology.room_types (\n room_type_id character varying(64) NOT NULL, -- unique identifier for the room type\n property_id character varying(64) NOT NULL, -- FK to properties table (type might be property-specific)\n type_name character varying(100) NOT NULL, -- e.g., Standard King, Deluxe Queen, Executive Suite\n description text, -- description of the room type\n base_rate numeric(10, 2) NOT NULL, -- standard price per night\n max_occupancy integer NOT NULL, -- maximum number of guests\n bed_type character varying(50), -- e.g., King, Queen, 2 Doubles, Twin\n area_sqft numeric(8,2), -- size of the room in square feet\n amenities text, -- comma-separated list or JSON of amenities\n PRIMARY KEY (room_type_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.guests (\n guest_id character varying(64) NOT NULL, -- unique identifier for the guest profile\n first_name character varying(100) NOT NULL, -- guest's first name\n last_name character varying(100) NOT NULL, -- guest's last name\n email character varying(255) UNIQUE, -- guest's email address (unique identifier?)\n phone_number character varying(30), -- guest's phone number\n date_of_birth date, -- guest's date of birth\n address_line1 character varying(255), -- guest's home address\n city character varying(100),\n state_province character varying(100),\n postal_code character varying(20),\n country_code character varying(3),\n preferences text, -- notes on guest preferences (e.g., allergies, room location)\n loyalty_member_id character varying(64) UNIQUE, -- FK to loyalty_members table\n communication_consent boolean DEFAULT true, -- consent for marketing communications\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n updated_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (guest_id)\n)\nCREATE TABLE hospitality_technology.staff (\n staff_id character varying(64) NOT NULL, -- unique identifier for the staff member\n property_id character varying(64) NOT NULL, -- FK to properties table (primary property)\n first_name character varying(100) NOT NULL,\n last_name character varying(100) NOT NULL,\n position character varying(100) NOT NULL, -- e.g., Front Desk Agent, Housekeeper, Manager, Concierge\n work_email character varying(255) UNIQUE, -- staff member's work email\n work_phone character varying(30),\n hire_date date NOT NULL,\n termination_date date, -- date employment ended (if applicable)\n is_active boolean NOT NULL DEFAULT true, -- currently employed flag\n access_level integer NOT NULL, -- permission level within systems (e.g., 1=basic, 5=admin)\n manager_id character varying(64), -- FK to staff table (self-referencing for supervisor)\n created_at timestamp with time zone NOT NULL DEFAULT current_timestamp,\n PRIMARY KEY (staff_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (manager_id) REFERENCES hospitality_technology.staff(staff_id)\n)\nCREATE TABLE hospitality_technology.services (\n service_id character varying(64) NOT NULL, -- unique identifier for a chargeable service\n property_id character varying(64) NOT NULL, -- FK to properties table\n service_name character varying(150) NOT NULL, -- e.g., Room Service - Burger, Spa - Massage 60min, Laundry - Shirt\n description text,\n category character varying(100), -- e.g., Food & Beverage, Wellness, Business Center, Activities\n price numeric(10, 2) NOT NULL, -- price per unit\/instance\n unit character varying(30), -- e.g., Per Item, Per Hour, Per Day\n is_available boolean NOT NULL DEFAULT true, -- is the service currently offered?\n department character varying(100), -- department responsible (e.g., F&B, Spa, Housekeeping)\n PRIMARY KEY (service_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id)\n)\nCREATE TABLE hospitality_technology.reviews (\n review_id character varying(64) NOT NULL, -- unique identifier for the review\n property_id character varying(64) NOT NULL, -- FK to properties table\n reservation_id character varying(64) UNIQUE, -- FK to reservations (link review to a specific stay, optional but good)\n guest_id character varying(64) NOT NULL, -- FK to guests table\n rating_overall integer, -- overall score (e.g., 1-5 or 1-10)\n rating_cleanliness integer,\n rating_service integer,\n rating_location integer,\n rating_value integer,\n comment text, -- guest's written feedback\n review_source character varying(100), -- e.g., DirectSurvey, TripAdvisor, Google, Booking.com\n review_date timestamp with time zone NOT NULL DEFAULT current_timestamp, -- when the review was submitted\n is_public boolean DEFAULT true, -- whether the review is publicly visible\n staff_response text, -- official response from the property\n response_staff_id character varying(64), -- FK to staff (who responded)\n response_date timestamp with time zone, -- when the response was posted\n PRIMARY KEY (review_id),\n FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id),\n FOREIGN KEY (reservation_id) REFERENCES hospitality_technology.reservations(reservation_id),\n FOREIGN KEY (guest_id) REFERENCES hospitality_technology.guests(guest_id),\n FOREIGN KEY (response_staff_id) REFERENCES hospitality_technology.staff(staff_id)\n)\n","conversations":[{"role":"user","content":"List all staff members, the property name they work for, and the number of services offered at their property."},{"role":"assistant","content":"SELECT s.staff_id, s.first_name, s.last_name, p.property_name, COUNT(sv.service_id) AS service_count\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nLEFT JOIN hospitality_technology.services sv ON p.property_id = sv.property_id\nGROUP BY s.staff_id, s.first_name, s.last_name, p.property_name;"},{"role":"user","content":"Actually, I also want to see the staff member's position in the result."},{"role":"assistant","content":"SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name, COUNT(sv.service_id) AS service_count\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nLEFT JOIN hospitality_technology.services sv ON p.property_id = sv.property_id\nGROUP BY s.staff_id, s.first_name, s.last_name, s.position, p.property_name;"},{"role":"user","content":"Can you filter the results to only show staff members whose properties have more than 3 services?"},{"role":"assistant","content":"SELECT s.staff_id, s.first_name, s.last_name, s.position, p.property_name, COUNT(sv.service_id) AS service_count\nFROM hospitality_technology.staff s\nJOIN hospitality_technology.properties p ON s.property_id = p.property_id\nLEFT JOIN hospitality_technology.services sv ON p.property_id = sv.property_id\nGROUP BY s.staff_id, s.first_name, s.last_name, s.position, p.property_name\nHAVING COUNT(sv.service_id) > 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE erc1155_approval_for_all (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Timestamp of the block containing the transaction\n transaction_index integer NOT NULL, -- Index of the transaction within the block\n transaction_hash varchar(66) NOT NULL, -- Transaction hash\n log_index integer NOT NULL, -- Log index\n contract_address varchar(42) NOT NULL -- Event contract address\n)\nCREATE TABLE erc20_balances ( block_number bigint, contract_address varchar, wallet_address varchar, amount varchar, pk varchar )\nCREATE TABLE erc20_balances_historical ( block_number bigint, contract_address text, wallet_address text, amount text, pk integer )\nCREATE TABLE nft_holders ( block_number.bigint, contract_address.text, wallet_address.text, token_id.text, contract_type.text, amount.text, pk.text )\nCREATE TABLE sui_coins ( object_id varchar NOT NULL, status varchar NOT NULL, coin_type varchar NOT NULL, balance varchar NOT NULL, owner varchar NOT NULL )\nCREATE TABLE sui_coins_metadata (\n object_id varchar NOT NULL, -- object id of the coin metadata object\n coin_type varchar NOT NULL, -- coin type, eg. 0x...66::reap_token::REAP_TOKEN\n status varchar NOT NULL, -- coin status, eg. exists, deleted\n decimals bigint NOT NULL, -- decimals of the coin\n description varchar NOT NULL, -- description of the coin\n icon_url varchar NOT NULL, -- icon url of the coin\n symbol varchar NOT NULL, -- symbol of the coin\n name varchar NOT NULL -- name of the coin\n)\nCREATE TABLE sui_nfts ( object_id.text, status.text, collection_type.text, package_id.text, previous_transaction.text, display.text, owner.text, name.text )\nCREATE TABLE nft_collections ( blockchain varchar NOT NULL, contract_address varchar NOT NULL, name varchar NOT NULL, symbol varchar NOT NULL, deploy_block_number bigint NOT NULL, deploy_block_time bigint NOT NULL, erc_type varchar NOT NULL, owner varchar NOT NULL, traits varchar NOT NULL, description varchar NOT NULL, slug varchar NOT NULL, media_info varchar NOT NULL, image_url varchar NOT NULL, banner_image_url varchar NOT NULL, updated_at bigint NOT NULL, banner varchar NOT NULL, token_count bigint NOT NULL, floor_price varchar NOT NULL, floor_price_symbol varchar NOT NULL, floor_price_contract varchar NOT NULL, pk integer NOT NULL )\nCREATE TABLE token_prices ( uuid.text, blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE token_prices_latest ( blockchain.text, address.text, decimals.bigint, symbol.text, price.real, timestamp.timestamp )\nCREATE TABLE erc20_approval ( block_number.bigint, block_timestamp.timestamp, transaction_index.integer, transaction_hash.text, log_index.integer, contract_address.text, pk.integer )\nCREATE TABLE token_balances (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar NOT NULL, -- Token tick\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info ( block_timestamp timestamp(3) NOT NULL, block_number bigint NOT NULL, tx_index integer NOT NULL, tx_hash varchar(66) NOT NULL, tick varchar NOT NULL, max_supply decimal(38,0) NOT NULL, lim decimal(38,0) NOT NULL, wlim decimal(38,0) NOT NULL, dec integer NOT NULL, creator varchar(42) NOT NULL )\nCREATE TABLE token_activities ( block_timestamp.timestamp, block_number.bigint, tx_index.integer, tx_hash.text, log_index.integer, type.text, tick.text, id.text, amt.decimal, from_address.text, to_address.text )\nCREATE TABLE mud_holesky_redstone ( address text, table_id text, key_bytes text, key0 text, key1 text, static_data text, encoded_lengths text, dynamic_data text, is_deleted boolean, block_number bigint, log_index bigint )\nCREATE TABLE token_balances_bitcoin (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(255) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply varchar NOT NULL, -- Max supply: Set max supply of the inscription\n amount varchar NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, tick text, max_supply decimal, lim decimal, wlim decimal, dec integer, creator text )\nCREATE TABLE token_activities_bitcoin ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash text, log_index integer, type text, tick text, id text, amt decimal, from_address text, to_address text )\nCREATE TABLE token_activities_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, log_index integer, type varchar, tick varchar, id varchar, amt decimal, from_address varchar, to_address varchar )\nCREATE TABLE token_balances_avalanche (\n block_number bigint NOT NULL, -- Block number containing the transaction\n block_timestamp timestamp(3) NOT NULL, -- Block timestamp containing the transaction\n tick varchar(20) NOT NULL, -- Ticker: Identifier of the inscription\n wallet_address varchar(42) NOT NULL, -- Address of owner\n total_supply decimal(38,0) NOT NULL, -- Max supply: Set max supply of the inscription\n amount decimal(38,0) NOT NULL -- The balance of wallet balance at the corresponding block height\n)\nCREATE TABLE token_info_avalanche ( block_timestamp timestamp, block_number bigint, tx_index integer, tx_hash varchar, tick varchar, max_supply decimal, lim decimal, wlim decimal, dec integer, creator varchar, minted decimal, holders decimal, txs decimal, updated_timestamp timestamp, completed_timestamp timestamp, id varchar )\n","conversations":[{"role":"user","content":"For each Bitcoin token tick, show me the creator address from the token_info_bitcoin table and the number of unique wallets currently holding that token."},{"role":"assistant","content":"SELECT ti.tick, ti.creator, COUNT(DISTINCT tb.wallet_address) AS unique_wallets FROM token_info_bitcoin ti JOIN token_balances_bitcoin tb ON ti.tick = tb.tick GROUP BY ti.tick, ti.creator;"},{"role":"user","content":"Now, only include ticks where there are more than 5 unique wallets, and order the result by the number of unique wallets descending."},{"role":"assistant","content":"SELECT ti.tick, ti.creator, COUNT(DISTINCT tb.wallet_address) AS unique_wallets FROM token_info_bitcoin ti JOIN token_balances_bitcoin tb ON ti.tick = tb.tick GROUP BY ti.tick, ti.creator HAVING COUNT(DISTINCT tb.wallet_address) > 5 ORDER BY unique_wallets DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.policies ( policy_id text, customer_id text, product_id text, agent_id text, policy_number text, start_date date, end_date date, premium_amount numeric, coverage_limit numeric, deductible numeric, status text, issued_at timestamp, cancellation_date date, cancellation_reason text )\n","conversations":[{"role":"user","content":"List all customers who have two policies with overlapping coverage periods and show both policy numbers along with the overlap start and end dates."},{"role":"assistant","content":"SELECT p1.customer_id, p1.policy_number AS policy_number1, p2.policy_number AS policy_number2, GREATEST(p1.start_date, p2.start_date) AS overlap_start, LEAST(p1.end_date, p2.end_date) AS overlap_end FROM insurance.policies p1 JOIN insurance.policies p2 ON p1.customer_id = p2.customer_id AND p1.policy_id < p2.policy_id WHERE p1.start_date <= p2.end_date AND p2.start_date <= p1.end_date;"},{"role":"user","content":"Actually, I only want overlapping policies where both policies are currently active."},{"role":"assistant","content":"SELECT p1.customer_id, p1.policy_number AS policy_number1, p2.policy_number AS policy_number2, GREATEST(p1.start_date, p2.start_date) AS overlap_start, LEAST(p1.end_date, p2.end_date) AS overlap_end FROM insurance.policies p1 JOIN insurance.policies p2 ON p1.customer_id = p2.customer_id AND p1.policy_id < p2.policy_id WHERE p1.status = 'active' AND p2.status = 'active' AND p1.start_date <= p2.end_date AND p2.start_date <= p1.end_date;"},{"role":"user","content":"Also include the number of days of overlap as overlap_days."},{"role":"assistant","content":"SELECT p1.customer_id, p1.policy_number AS policy_number1, p2.policy_number AS policy_number2, GREATEST(p1.start_date, p2.start_date) AS overlap_start, LEAST(p1.end_date, p2.end_date) AS overlap_end, (LEAST(p1.end_date, p2.end_date) - GREATEST(p1.start_date, p2.start_date)) AS overlap_days FROM insurance.policies p1 JOIN insurance.policies p2 ON p1.customer_id = p2.customer_id AND p1.policy_id < p2.policy_id WHERE p1.status = 'active' AND p2.status = 'active' AND p1.start_date <= p2.end_date AND p2.start_date <= p1.end_date;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.reservations ( reservation_id text PRIMARY KEY, property_id text, guest_id text, room_id text, room_type_id text, check_in_date date, check_out_date date, actual_check_in_ts timestamp, actual_check_out_ts timestamp, num_adults int, num_children int, status text, booking_source text, rate_plan_id text, total_amount numeric, amount_paid numeric, special_requests text, created_at timestamp, updated_at timestamp )\n","conversations":[{"role":"user","content":"List all reservations with their guest IDs and room IDs where the total amount is greater than $300, ordered by check-in date."},{"role":"assistant","content":"SELECT reservation_id, guest_id, room_id, check_in_date FROM hospitality_technology.reservations WHERE total_amount > 300 ORDER BY check_in_date;"},{"role":"user","content":"The query is missing the property ID. Can you include that as well?"},{"role":"assistant","content":"SELECT reservation_id, guest_id, room_id, property_id, check_in_date FROM hospitality_technology.reservations WHERE total_amount > 300 ORDER BY check_in_date;"},{"role":"user","content":"Actually, I need to see only reservations from properties with ID starting with 'PROP1'."},{"role":"assistant","content":"SELECT reservation_id, guest_id, room_id, property_id, check_in_date FROM hospitality_technology.reservations WHERE total_amount > 300 AND property_id LIKE 'PROP1%' ORDER BY check_in_date;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\n","conversations":[{"role":"user","content":"For each vehicle, find the vehicle in the same depot that was acquired immediately before it. Display the current vehicle_id, acquisition_date, previous vehicle_id, and its acquisition_date."},{"role":"assistant","content":"SELECT v.vehicle_id, v.acquisition_date, prev.vehicle_id AS previous_vehicle_id, prev.acquisition_date AS previous_acquisition_date FROM transportation.vehicles v JOIN transportation.vehicles prev ON v.depot_id = prev.depot_id AND prev.acquisition_date = (SELECT MAX(acquisition_date) FROM transportation.vehicles WHERE depot_id = v.depot_id AND acquisition_date < v.acquisition_date);"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts (\n contract_id character varying(64) NOT NULL, -- unique identifier for the contract\n address character varying(128) NOT NULL, -- address of the deployed contract\n abi text NOT NULL, -- application binary interface of the contract\n bytecode text NOT NULL, -- bytecode of the contract\n deployer_address character varying(128) NOT NULL, -- address of the deployer\n deployed_at timestamp NOT NULL, -- time when the contract was deployed\n network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed\n status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)\n PRIMARY KEY (contract_id)\n)\nCREATE TABLE web3.events (\n event_id character varying(64) NOT NULL, -- unique identifier for the event\n contract_id character varying(64) NOT NULL, -- identifier of the contract emitting the event\n event_name character varying(128) NOT NULL, -- name of the event\n data text NOT NULL, -- data payload of the event\n emitted_at timestamp NOT NULL, -- time when the event was emitted\n transaction_id character varying(64) NOT NULL, -- identifier of the transaction that triggered the event\n log_index integer NOT NULL, -- index of the event log in the transaction\n PRIMARY KEY (event_id)\n)\nCREATE TABLE web3.transactions ( transaction_id character varying(64) NOT NULL, from_address character varying(128) NOT NULL, to_address character varying(128), value numeric(38,14) NOT NULL, gas_used integer NOT NULL, gas_price numeric(38,14) NOT NULL, block_number integer NOT NULL, timestamp timestamp NOT NULL, input_data text, status character varying(32) NOT NULL, nonce integer NOT NULL, PRIMARY KEY (transaction_id) )\nCREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )\nCREATE TABLE web3.wallets ( wallet_id text PRIMARY KEY, user_id text, address text, private_key text, created_at timestamp )\nCREATE TABLE web3.users (\n user_id character varying(64) NOT NULL, -- unique identifier for the user\n username character varying(128) NOT NULL, -- username of the user\n email character varying(128) NOT NULL, -- email address of the user\n password_hash text NOT NULL, -- hashed password of the user\n created_at timestamp NOT NULL, -- time when the user account was created\n PRIMARY KEY (user_id)\n)\n","conversations":[{"role":"user","content":"List all users and the total value of all transactions they have initiated. Show user_id, username, and total_transaction_value."},{"role":"assistant","content":"SELECT u.user_id, u.username, COALESCE(SUM(t.value), 0) AS total_transaction_value\nFROM web3.users u\nLEFT JOIN web3.wallets w ON u.user_id = w.user_id\nLEFT JOIN web3.transactions t ON w.address = t.from_address\nGROUP BY u.user_id, u.username;"},{"role":"user","content":"Actually, only show users who have initiated at least one transaction, and sort them by total_transaction_value descending."},{"role":"assistant","content":"SELECT u.user_id, u.username, SUM(t.value) AS total_transaction_value\nFROM web3.users u\nJOIN web3.wallets w ON u.user_id = w.user_id\nJOIN web3.transactions t ON w.address = t.from_address\nGROUP BY u.user_id, u.username\nHAVING SUM(t.value) > 0\nORDER BY total_transaction_value DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\n","conversations":[{"role":"user","content":"I need to find all pairs of diagnoses for the same patient where one diagnosis is chronic and the other is non-chronic. Show patient_id, chronic diagnosis_id as chronic_id, non-chronic diagnosis_id as acute_id, chronic diagnosis_date, and acute diagnosis_date."},{"role":"assistant","content":"SELECT d1.patient_id,\n d1.diagnosis_id AS chronic_id,\n d2.diagnosis_id AS acute_id,\n d1.diagnosis_date AS chronic_date,\n d2.diagnosis_date AS acute_date\nFROM healthcare.diagnoses d1\nJOIN healthcare.diagnoses d2\n ON d1.patient_id = d2.patient_id\nWHERE d1.is_chronic = TRUE\n AND d2.is_chronic = FALSE;"},{"role":"user","content":"Actually, only include pairs where the chronic diagnosis date is after the acute diagnosis date."},{"role":"assistant","content":"SELECT d1.patient_id,\n d1.diagnosis_id AS chronic_id,\n d2.diagnosis_id AS acute_id,\n d1.diagnosis_date AS chronic_date,\n d2.diagnosis_date AS acute_date\nFROM healthcare.diagnoses d1\nJOIN healthcare.diagnoses d2\n ON d1.patient_id = d2.patient_id\nWHERE d1.is_chronic = TRUE\n AND d2.is_chronic = FALSE\n AND d1.diagnosis_date > d2.diagnosis_date;"},{"role":"user","content":"Also restrict the results to diagnoses made in 2023."},{"role":"assistant","content":"SELECT d1.patient_id,\n d1.diagnosis_id AS chronic_id,\n d2.diagnosis_id AS acute_id,\n d1.diagnosis_date AS chronic_date,\n d2.diagnosis_date AS acute_date\nFROM healthcare.diagnoses d1\nJOIN healthcare.diagnoses d2\n ON d1.patient_id = d2.patient_id\nWHERE d1.is_chronic = TRUE\n AND d2.is_chronic = FALSE\n AND d1.diagnosis_date > d2.diagnosis_date\n AND d1.diagnosis_date BETWEEN '2023-01-01' AND '2023-12-31'\n AND d2.diagnosis_date BETWEEN '2023-01-01' AND '2023-12-31';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.wallets ( wallet_id.text, user_id.text, address.text, private_key.text, created_at.timestamp )\n","conversations":[{"role":"user","content":"For each user, show their user ID and the count of unique wallet addresses they own."},{"role":"assistant","content":"SELECT user_id, COUNT(DISTINCT address) FROM wallets GROUP BY user_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, item_id uuid NOT NULL, quantity integer NOT NULL DEFAULT 1, acquired_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, instance_data jsonb, PRIMARY KEY (inventory_id) )\n","conversations":[{"role":"user","content":"Find players who own items with rarity 'Rare' or higher ('Epic', 'Legendary') and list their usernames."},{"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 WHERE T3.rarity IN ('Rare', 'Epic', 'Legendary');"},{"role":"user","content":"Filter this list further to only include players who acquired these items after '2024-01-01'."},{"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 WHERE T3.rarity IN ('Rare', 'Epic', 'Legendary') AND T2.acquired_at > '2024-01-01';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE trading_platform.orders ( order_id text PRIMARY KEY, user_id text, wallet_id text, asset_id text, order_type text, quantity numeric, price numeric, status text, created_at timestamp )\nCREATE TABLE trading_platform.trades ( trade_id text PRIMARY KEY, order_id text, buyer_id text, seller_id text, asset_id text, quantity numeric, price numeric, traded_at timestamp )\nCREATE TABLE trading_platform.utxos ( utxo_id text PRIMARY KEY, transaction_id text, output_index int, address text, amount numeric, spent boolean )\nCREATE TABLE trading_platform.dapps ( dapp_id text PRIMARY KEY, name text, description text, url text )\nCREATE TABLE trading_platform.peers ( peer_id text PRIMARY KEY, ip_address text, port int, last_seen timestamp )\nCREATE TABLE trading_platform.metadata ( metadata_id text PRIMARY KEY, asset_id text, key text, value text )\nCREATE TABLE trading_platform.kyc_audit ( kyc_audit_id text PRIMARY KEY, user_id text, status text, reviewed_at timestamp )\nCREATE TABLE trading_platform.logs ( log_id text PRIMARY KEY, user_id text, action text, details text, logged_at timestamp )\n","conversations":[{"role":"user","content":"Show a list of all DApps together with the total number of unique assets linked to each via the metadata table."},{"role":"assistant","content":"SELECT d.dapp_id, d.name, d.url, COUNT(DISTINCT m.asset_id) AS unique_asset_count\nFROM trading_platform.dapps d\nLEFT JOIN trading_platform.metadata m ON m.asset_id IS NOT NULL\nGROUP BY d.dapp_id, d.name, d.url;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.messages ( message_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, sender_user_id character varying(64) NOT NULL, content text, media_url text, media_type character varying(20), sent_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, read_at timestamp, PRIMARY KEY (message_id) )\nCREATE TABLE social_media.conversation_participants ( participant_id character varying(64) NOT NULL, conversation_id character varying(64) NOT NULL, user_id character varying(64) NOT NULL, joined_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, last_read_at timestamp, PRIMARY KEY (participant_id), CONSTRAINT unique_user_conversation UNIQUE (conversation_id, user_id) )\n","conversations":[{"role":"user","content":"List `user_id` and `conversation_id` for participants who are in conversations where there is at least one message sent by *another* user that they have not read."},{"role":"assistant","content":"SELECT DISTINCT T1.user_id, T1.conversation_id FROM social_media.conversation_participants AS T1 JOIN social_media.messages AS T2 ON T1.conversation_id = T2.conversation_id WHERE T2.sender_user_id != T1.user_id AND (T1.last_read_at IS NULL OR T2.sent_at > T1.last_read_at);"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.conversations ( conversation_id text PRIMARY KEY, created_at timestamp, last_message_at timestamp, is_group_chat bool, group_name text )\n","conversations":[{"role":"user","content":"List the group chat names and the creation dates for all group chats that have a last message sent in 2024."},{"role":"assistant","content":"SELECT group_name, created_at FROM social_media.conversations WHERE is_group_chat = TRUE AND last_message_at >= '2024-01-01';"},{"role":"user","content":"Can you include the conversation_id as well?"},{"role":"assistant","content":"SELECT conversation_id, group_name, created_at FROM social_media.conversations WHERE is_group_chat = TRUE AND last_message_at >= '2024-01-01';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.law_firms ( firm_id text PRIMARY KEY, firm_name text, address text, phone text, website text, founded_date date, managing_partner_id text )\nCREATE TABLE legal_services.cases ( case_id text PRIMARY KEY, case_number text UNIQUE, case_name text, client_id text, lead_lawyer_id text, case_type text, status text, date_opened timestamp, date_closed timestamp, description text, court_jurisdiction text )\nCREATE TABLE legal_services.appointments ( appointment_id text PRIMARY KEY, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n","conversations":[{"role":"user","content":"Show me a list of appointments, including their subject and start time, along with the case number for the related case."},{"role":"assistant","content":"SELECT T1.subject, T1.start_time, T2.case_number FROM appointments AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id;"},{"role":"user","content":"Please filter this list to only include appointments that start after '2024-01-01'."},{"role":"assistant","content":"SELECT T1.subject, T1.start_time, T2.case_number FROM appointments AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id WHERE T1.start_time > '2024-01-01';"},{"role":"user","content":"Additionally, restrict the results to only those cases where the description contains the word 'meeting'."},{"role":"assistant","content":"SELECT T1.subject, T1.start_time, T2.case_number FROM appointments AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id WHERE T1.start_time > '2024-01-01' AND T2.description LIKE '%meeting%';"},{"role":"user","content":"Just show the appointment subject and the case number, ordered by the appointment start time in ascending order."},{"role":"assistant","content":"SELECT T1.subject, T2.case_number FROM appointments AS T1 JOIN cases AS T2 ON T1.case_id = T2.case_id WHERE T1.start_time > '2024-01-01' AND T2.description LIKE '%meeting%' ORDER BY T1.start_time ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.appointments ( appointment_id text PRIMARY KEY, client_id text, lawyer_id text, case_id text, start_time timestamp, end_time timestamp, location text, subject text, notes text, status text, created_at timestamp )\n","conversations":[{"role":"user","content":"I want to find all appointment pairs where two appointments are scheduled for the same client at overlapping times. Provide the appointment_id from both overlapping appointments."},{"role":"assistant","content":"SELECT a1.appointment_id AS appointment_id_1, a2.appointment_id AS appointment_id_2\nFROM legal_services.appointments a1\nJOIN legal_services.appointments a2\n ON a1.client_id = a2.client_id\n AND a1.appointment_id < a2.appointment_id\n AND a1.start_time < a2.end_time\n AND a2.start_time < a1.end_time;"},{"role":"user","content":"Actually, only include pairs where both appointments have status 'scheduled'."},{"role":"assistant","content":"SELECT a1.appointment_id AS appointment_id_1, a2.appointment_id AS appointment_id_2\nFROM legal_services.appointments a1\nJOIN legal_services.appointments a2\n ON a1.client_id = a2.client_id\n AND a1.appointment_id < a2.appointment_id\n AND a1.start_time < a2.end_time\n AND a2.start_time < a1.end_time\nWHERE a1.status = 'scheduled'\n AND a2.status = 'scheduled';"},{"role":"user","content":"And ensure the overlapping appointments start within 1 hour of each other."},{"role":"assistant","content":"SELECT a1.appointment_id AS appointment_id_1, a2.appointment_id AS appointment_id_2\nFROM legal_services.appointments a1\nJOIN legal_services.appointments a2\n ON a1.client_id = a2.client_id\n AND a1.appointment_id < a2.appointment_id\n AND a1.start_time < a2.end_time\n AND a2.start_time < a1.end_time\n AND ABS(EXTRACT(EPOCH FROM (a1.start_time - a2.start_time))) <= 3600\nWHERE a1.status = 'scheduled'\n AND a2.status = 'scheduled';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_dexpool_info ( pair_address.text, token_name.text, token_symbol.text, chain.text, price.numeric, price_change_percentage_1h.numeric, price_change_percentage_6h.numeric, price_change_percentage_24h.numeric, makers_24h.numeric, volume_24h.numeric, liquidity.numeric, market_cap.numeric, trend_rank.numeric )\n","conversations":[{"role":"user","content":"For the Arbitrum chain, which three tokens have the greatest positive change in price over the last 1 hour? Please show their symbol, name, price, and 1-hour price change percentage."},{"role":"assistant","content":"SELECT token_symbol, token_name, price, price_change_percentage_1h FROM token_dexpool_info WHERE chain = 'Arbitrum' ORDER BY price_change_percentage_1h DESC LIMIT 3;"},{"role":"user","content":"Could you also add the 24-hour trading volume and liquidity for these tokens?"},{"role":"assistant","content":"SELECT token_symbol, token_name, price, price_change_percentage_1h, volume_24h, liquidity FROM token_dexpool_info WHERE chain = 'Arbitrum' ORDER BY price_change_percentage_1h DESC LIMIT 3;"},{"role":"user","content":"I only want to see tokens where the liquidity is greater than $500,000 and market cap exceeds $10,000,000."},{"role":"assistant","content":"SELECT token_symbol, token_name, price, price_change_percentage_1h, volume_24h, liquidity FROM token_dexpool_info WHERE chain = 'Arbitrum' AND liquidity > 500000 AND market_cap > 10000000 ORDER BY price_change_percentage_1h DESC LIMIT 3;"},{"role":"user","content":"Please also display the 24-hour price change and order the results by 24-hour trading volume descending."},{"role":"assistant","content":"SELECT token_symbol, token_name, price, price_change_percentage_1h, price_change_percentage_24h, volume_24h, liquidity FROM token_dexpool_info WHERE chain = 'Arbitrum' AND liquidity > 500000 AND market_cap > 10000000 ORDER BY volume_24h DESC LIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text PRIMARY KEY, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\n","conversations":[{"role":"user","content":"Show the count of patients residing in each unique address, excluding any entries with no address listed."},{"role":"assistant","content":"SELECT address, COUNT(patient_id) AS patient_count FROM healthcare.patients WHERE address IS NOT NULL AND address != '' GROUP BY address;"},{"role":"user","content":"Filter the previous result to only include addresses where there are more than 5 patients."},{"role":"assistant","content":"SELECT address, COUNT(patient_id) AS patient_count FROM healthcare.patients WHERE address IS NOT NULL AND address != '' GROUP BY address HAVING COUNT(patient_id) > 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE financial_services.trades ( trade_id character varying(64) NOT NULL, account_id character varying(64) NOT NULL, security_id character varying(64) NOT NULL, order_id character varying(64), trade_type character varying(10) NOT NULL, quantity numeric(19, 8) NOT NULL, price_per_unit numeric(19, 8) NOT NULL, total_amount numeric(19, 4) NOT NULL, commission numeric(10, 4), trade_timestamp timestamp NOT NULL, settlement_date date, status character varying(32) NOT NULL, execution_venue character varying(100), PRIMARY KEY (trade_id), FOREIGN KEY (account_id) REFERENCES financial_services.accounts(account_id), FOREIGN KEY (security_id) REFERENCES financial_services.securities(security_id) )\nCREATE TABLE financial_services.employees ( employee_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(100) NOT NULL, department character varying(100), branch_id character varying(64), email character varying(128) NOT NULL UNIQUE, phone_extension character varying(20), hire_date date NOT NULL, termination_date date, manager_id character varying(64), status character varying(32) NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (branch_id) REFERENCES financial_services.branches(branch_id), FOREIGN KEY (manager_id) REFERENCES financial_services.employees(employee_id) )\n","conversations":[{"role":"user","content":"Find pairs of BUY and SELL trades from the trades table for the same account that occurred on the same settlement_date and had matching quantities."},{"role":"assistant","content":"SELECT\n a.trade_id AS buy_trade_id,\n b.trade_id AS sell_trade_id,\n a.account_id,\n a.settlement_date,\n a.quantity\nFROM financial_services.trades a\nJOIN financial_services.trades b\n ON a.account_id = b.account_id\n AND a.settlement_date = b.settlement_date\n AND a.quantity = b.quantity\nWHERE a.trade_type = 'BUY'\n AND b.trade_type = 'SELL';"},{"role":"user","content":"Only include pairs where the execution_venue is different between the two trades."},{"role":"assistant","content":"SELECT\n a.trade_id AS buy_trade_id,\n b.trade_id AS sell_trade_id,\n a.account_id,\n a.settlement_date,\n a.quantity\nFROM financial_services.trades a\nJOIN financial_services.trades b\n ON a.account_id = b.account_id\n AND a.settlement_date = b.settlement_date\n AND a.quantity = b.quantity\nWHERE a.trade_type = 'BUY'\n AND b.trade_type = 'SELL'\n AND a.execution_venue <> b.execution_venue;"},{"role":"user","content":"Sort the results by account_id ascending and settlement_date descending."},{"role":"assistant","content":"SELECT\n a.trade_id AS buy_trade_id,\n b.trade_id AS sell_trade_id,\n a.account_id,\n a.settlement_date,\n a.quantity\nFROM financial_services.trades a\nJOIN financial_services.trades b\n ON a.account_id = b.account_id\n AND a.settlement_date = b.settlement_date\n AND a.quantity = b.quantity\nWHERE a.trade_type = 'BUY'\n AND b.trade_type = 'SELL'\n AND a.execution_venue <> b.execution_venue\nORDER BY a.account_id ASC, a.settlement_date DESC;"}]} +{"system":"You are an expert in writing database language. You can write a corresponding database language query to answer the user's question based on the table structure described by the table creation statement. \n##Table Structure\nCREATE TABLE smart_money_token_inflow ( token_address text, token_symbol text, token_amount numeric, usd_value numeric, avg_price numeric, type numeric, address_amount numeric, narrative text, chain text )\n","conversations":[{"role":"user","content":"What is the total USD value of smart money token inflows for each chain?"},{"role":"assistant","content":"SELECT chain, SUM(usd_value) AS total_usd_inflow FROM smart_money_token_inflow GROUP BY chain ORDER BY total_usd_inflow DESC;"},{"role":"user","content":"Now, show me the total USD inflow for each chain, but only for inflows associated with the 'AI' narrative."},{"role":"assistant","content":"SELECT chain, SUM(usd_value) AS total_usd_inflow FROM smart_money_token_inflow WHERE narrative = 'AI' GROUP BY chain ORDER BY total_usd_inflow DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.cases ( case_id character varying(64) NOT NULL, case_number character varying(100) UNIQUE, case_name text NOT NULL, client_id character varying(64) NOT NULL, lead_lawyer_id character varying(64) NOT NULL, case_type character varying(100) NOT NULL, status character varying(50) NOT NULL, date_opened timestamp NOT NULL, date_closed timestamp, description text, court_jurisdiction character varying(128), PRIMARY KEY (case_id) )\nCREATE TABLE legal_services.documents ( document_id character varying(64) NOT NULL, case_id character varying(64) NOT NULL, document_name character varying(255) NOT NULL, document_type character varying(100), storage_path text NOT NULL, uploaded_by_lawyer_id character varying(64), upload_timestamp timestamp NOT NULL, version integer DEFAULT 1, description text, PRIMARY KEY (document_id) )\nCREATE TABLE legal_services.time_entries ( entry_id 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) )\nCREATE TABLE legal_services.invoices ( invoice_id character varying(64) NOT NULL, invoice_number character varying(100) UNIQUE NOT NULL, client_id character varying(64) NOT NULL, case_id character varying(64), issue_date date NOT NULL, due_date date NOT NULL, total_amount numeric(12, 2) NOT NULL, amount_paid numeric(12, 2) DEFAULT 0.00, status character varying(50) NOT NULL, payment_date timestamp, notes text, created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (invoice_id) )\n","conversations":[{"role":"user","content":"Which cases have at least one document uploaded, and what are the names and case numbers of those cases along with the most recent document name for each?"},{"role":"assistant","content":"SELECT c.case_id, c.case_name, c.case_number, d.document_name AS latest_document_name\nFROM legal_services.cases c\nJOIN (\n SELECT case_id, MAX(upload_timestamp) AS latest_upload\n FROM legal_services.documents\n GROUP BY case_id\n) last_doc ON c.case_id = last_doc.case_id\nJOIN legal_services.documents d ON d.case_id = last_doc.case_id AND d.upload_timestamp = last_doc.latest_upload;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.patients ( patient_id text, first_name text, last_name text, date_of_birth date, gender text, address text, phone_number text, email text, emergency_contact_name text, emergency_contact_phone text, created_at timestamp, updated_at timestamp )\nCREATE TABLE healthcare.insurance_plans (\n plan_id character varying(64) NOT NULL, -- unique identifier for the insurance plan\n plan_name character varying(200) NOT NULL, -- name of the insurance plan\n insurance_provider character varying(100) NOT NULL, -- name of the insurance company\n plan_type character varying(50), -- e.g., PPO, HMO, EPO\n contact_phone character varying(20), -- provider contact number\n website character varying(255), -- provider website\n PRIMARY KEY (plan_id)\n)\n","conversations":[{"role":"user","content":"List all female patients born before 1990 who have a phone number listed, showing their full names and contact information."},{"role":"assistant","content":"SELECT first_name, last_name, phone_number, email, emergency_contact_name, emergency_contact_phone FROM healthcare.patients WHERE gender = 'female' AND date_of_birth < '1990-01-01' AND phone_number IS NOT NULL;"},{"role":"user","content":"Now, I also want to see their insurance provider names if they have any insurance plans."},{"role":"assistant","content":"SELECT p.first_name, p.last_name, p.phone_number, p.email, ip.insurance_provider FROM healthcare.patients p LEFT JOIN healthcare.insurance_plans ip ON p.patient_id = ip.plan_id WHERE p.gender = 'female' AND p.date_of_birth < '1990-01-01' AND p.phone_number IS NOT NULL;"},{"role":"user","content":"Actually, I only need patients whose insurance providers are 'Blue Cross'."},{"role":"assistant","content":"SELECT p.first_name, p.last_name, p.phone_number, p.email, ip.insurance_provider FROM healthcare.patients p LEFT JOIN healthcare.insurance_plans ip ON p.patient_id = ip.plan_id WHERE p.gender = 'female' AND p.date_of_birth < '1990-01-01' AND p.phone_number IS NOT NULL AND ip.insurance_provider = 'Blue Cross';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )\nCREATE TABLE blockchain.users ( user_id.text, username.text, email.text, password_hash.text )\n","conversations":[{"role":"user","content":"List all users whose password hash contains the substring 'abc'."},{"role":"assistant","content":"SELECT user_id, username, password_hash FROM blockchain.users WHERE password_hash LIKE '%abc%';"},{"role":"user","content":"Also include their email address."},{"role":"assistant","content":"SELECT user_id, username, password_hash, email FROM blockchain.users WHERE password_hash LIKE '%abc%';"},{"role":"user","content":"Filter to only show users whose username does *not* contain 'test'."},{"role":"assistant","content":"SELECT user_id, username, password_hash, email FROM blockchain.users WHERE password_hash LIKE '%abc%' AND username NOT LIKE '%test%';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.customers (\n customer_id character varying(64) NOT NULL, -- unique identifier for the customer\n first_name character varying(100) NOT NULL, -- customer's first name\n last_name character varying(100) NOT NULL, -- customer's last name\n date_of_birth date NOT NULL, -- customer's date of birth\n ssn_hash character varying(128), -- Hashed social security number (or national ID)\n address_line1 character varying(255) NOT NULL,\n address_line2 character varying(255),\n city character varying(100) NOT NULL,\n state character varying(50) NOT NULL,\n zip_code character varying(20) NOT NULL,\n country character varying(50) NOT NULL DEFAULT 'USA',\n phone_number character varying(30),\n email character varying(128) UNIQUE, -- unique email address\n created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -- when the customer record was created\n updated_at timestamp, -- when the customer record was last updated\n status character varying(20) NOT NULL DEFAULT 'Active', -- e.g., Active, Inactive, Prospect\n PRIMARY KEY (customer_id)\n)\n","conversations":[{"role":"user","content":"Show me all active customers from California who were born before 1980, along with their contact information."},{"role":"assistant","content":"SELECT first_name, last_name, phone_number, email, address_line1, city, zip_code FROM insurance.customers WHERE state = 'California' AND date_of_birth < '1980-01-01' AND status = 'Active';"},{"role":"user","content":"Now filter these results to only show customers who have provided both a phone number and an email address."},{"role":"assistant","content":"SELECT first_name, last_name, phone_number, email, address_line1, city, zip_code FROM insurance.customers WHERE state = 'California' AND date_of_birth < '1980-01-01' AND status = 'Active' AND phone_number IS NOT NULL AND email IS NOT NULL;"},{"role":"user","content":"I also want to see how long these customers have been in our system (difference between current date and created_at in years)."},{"role":"assistant","content":"SELECT first_name, last_name, phone_number, email, address_line1, city, zip_code, EXTRACT(YEAR FROM AGE(CURRENT_DATE, created_at)) AS years_in_system FROM insurance.customers WHERE state = 'California' AND date_of_birth < '1980-01-01' AND status = 'Active' AND phone_number IS NOT NULL AND email IS NOT NULL;"},{"role":"user","content":"Finally, order the results by the longest tenure in our system first, then by last name alphabetically."},{"role":"assistant","content":"SELECT first_name, last_name, phone_number, email, address_line1, city, zip_code, EXTRACT(YEAR FROM AGE(CURRENT_DATE, created_at)) AS years_in_system FROM insurance.customers WHERE state = 'California' AND date_of_birth < '1980-01-01' AND status = 'Active' AND phone_number IS NOT NULL AND email IS NOT NULL ORDER BY years_in_system DESC, last_name ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.employees ( employee_id text, agency_id text, first_name text, last_name text, job_title text, department text, work_email text, work_phone text, hire_date date, termination_date date, access_level text, manager_employee_id text )\n","conversations":[{"role":"user","content":"Show the full names and job titles of employees who work in the same department as at least one other employee."},{"role":"assistant","content":"SELECT first_name, last_name, job_title\nFROM government_services.employees\nWHERE department IN (\n SELECT department FROM government_services.employees GROUP BY department HAVING COUNT(*) > 1\n);"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE healthcare.diagnoses (\n diagnosis_id character varying(64) NOT NULL, -- unique identifier for the diagnosis entry\n record_id character varying(64) NOT NULL, -- FK linking to the specific medical record entry\n patient_id character varying(64) NOT NULL, -- FK to patients table\n doctor_id character varying(64) NOT NULL, -- FK to doctors table (diagnosing doctor)\n diagnosis_code character varying(20) NOT NULL, -- standard code (e.g., ICD-10)\n code_type character varying(10) NOT NULL DEFAULT 'ICD-10', -- type of code used\n description text, -- textual description of the diagnosis\n diagnosis_date date NOT NULL, -- date the diagnosis was made\n status character varying(32) NOT NULL, -- e.g., Active, Resolved, Ruled Out\n is_chronic boolean DEFAULT false, -- flag for chronic conditions\n PRIMARY KEY (diagnosis_id)\n)\nCREATE TABLE healthcare.patient_insurance ( patient_insurance_id.text, patient_id.text, plan_id.text, policy_number.text, group_number.text, subscriber_name.text, effective_date.date, expiration_date.date, is_primary.boolean )\n","conversations":[{"role":"user","content":"List the patient ID and subscriber name for all patients who have both at least one diagnosis recorded and at least one primary insurance policy."},{"role":"assistant","content":"SELECT DISTINCT pi.patient_id, pi.subscriber_name FROM healthcare.patient_insurance pi JOIN healthcare.diagnoses d ON pi.patient_id = d.patient_id WHERE pi.is_primary = true;"},{"role":"user","content":"Refine this list to only include patients whose most recent diagnosis is marked as chronic."},{"role":"assistant","content":"WITH LatestDiagnosis AS ( SELECT patient_id, diagnosis_id, diagnosis_date, is_chronic, ROW_NUMBER() OVER(PARTITION BY patient_id ORDER BY diagnosis_date DESC) as rn FROM healthcare.diagnoses ) SELECT DISTINCT pi.patient_id, pi.subscriber_name FROM healthcare.patient_insurance pi JOIN LatestDiagnosis ld ON pi.patient_id = ld.patient_id WHERE pi.is_primary = true AND ld.rn = 1 AND ld.is_chronic = true;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE project_fundraising_record ( id.text, project_id.text, project_name.text, rounds_name.text, investment_value.numeric, investment_date.text, introduction.text, valuation.numeric )\n","conversations":[{"role":"user","content":"What is the total investment_value per fundraising round for the year 2023? Order by total investment descending."},{"role":"assistant","content":"SELECT\n substr(investment_date,1,7) AS month,\n rounds_name,\n SUM(investment_value) AS total_investment\nFROM project_fundraising_record\nWHERE investment_date LIKE '2023-%'\nGROUP BY substr(investment_date,1,7), rounds_name\nORDER BY total_investment DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.agents ( agent_id text PRIMARY KEY, first_name text, last_name text, agency_name text, license_number text, license_state text, contact_email text, contact_phone text, hire_date date, termination_date date, status text, commission_rate numeric, manager_id text )\n","conversations":[{"role":"user","content":"List all terminated agents who worked for more than 5 years, showing their full names and termination dates."},{"role":"assistant","content":"SELECT first_name, last_name, termination_date FROM insurance.agents WHERE termination_date IS NOT NULL AND (termination_date - hire_date) > 1825 ORDER BY termination_date DESC;"},{"role":"user","content":"Now include their agency names and sort by termination date in ascending order."},{"role":"assistant","content":"SELECT first_name, last_name, agency_name, termination_date FROM insurance.agents WHERE termination_date IS NOT NULL AND (termination_date - hire_date) > 1825 ORDER BY termination_date ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id character varying(64) NOT NULL, license_plate character varying(32) NOT NULL UNIQUE, vin character varying(17) UNIQUE, make character varying(64) NOT NULL, model character varying(64) NOT NULL, year integer NOT NULL, type character varying(32) NOT NULL, capacity integer, fuel_type character varying(32) NOT NULL, status character varying(32) NOT NULL, depot_id character varying(64), acquisition_date date, PRIMARY KEY (vehicle_id) )\nCREATE TABLE transportation.trips (\n trip_id character varying(64) NOT NULL, -- unique identifier for a specific trip instance\n route_id character varying(64), -- identifier of the route being followed (can be null for ad-hoc trips)\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle used\n driver_id character varying(64) NOT NULL, -- identifier of the driver operating\n scheduled_departure timestamp with time zone NOT NULL, -- planned departure time\n actual_departure timestamp with time zone, -- actual departure time\n scheduled_arrival timestamp with time zone NOT NULL, -- planned arrival time\n actual_arrival timestamp with time zone, -- actual arrival time\n origin_location_id character varying(64) NOT NULL, -- actual starting location (could differ from route origin)\n destination_location_id character varying(64) NOT NULL, -- actual ending location (could differ from route destination)\n status character varying(32) NOT NULL, -- e.g., Scheduled, In Progress, Completed, Delayed, Cancelled\n passenger_count integer, -- number of passengers (if applicable)\n cargo_manifest_id character varying(64), -- link to cargo details (if applicable)\n PRIMARY KEY (trip_id)\n)\nCREATE TABLE transportation.locations (\n location_id character varying(64) NOT NULL, -- unique identifier for the location\n name character varying(255) NOT NULL, -- name of the location (e.g., Central Station, Depot Alpha, Pier 7)\n type character varying(64) NOT NULL, -- e.g., Station, Stop, Depot, Port, Airport, Customer Address\n address_line1 character varying(255), -- street address\n city character varying(128), -- city name\n state_province character varying(128), -- state or province\n postal_code character varying(32), -- postal code\n country character varying(64) NOT NULL, -- country name\n latitude numeric(9, 6), -- geographic latitude\n longitude numeric(9, 6), -- geographic longitude\n timezone character varying(64), -- IANA timezone name (e.g., America\/New_York)\n PRIMARY KEY (location_id)\n)\nCREATE TABLE transportation.maintenance_logs (\n log_id character varying(64) NOT NULL, -- unique identifier for the maintenance record\n vehicle_id character varying(64) NOT NULL, -- identifier of the vehicle serviced\n service_date date NOT NULL, -- date the service was performed\n odometer_reading integer, -- vehicle mileage at time of service\n service_type character varying(128) NOT NULL, -- type of service (e.g., Oil Change, Tire Rotation, Engine Repair)\n description text NOT NULL, -- detailed description of work done\n cost numeric(10, 2), -- cost of the service\n mechanic_name character varying(128), -- name or ID of the mechanic\/shop\n next_service_due_date date, -- recommended date for next service\n PRIMARY KEY (log_id)\n)\nCREATE TABLE transportation.fuel_logs ( fuel_log_id.text, vehicle_id.text, trip_id.text, log_timestamp.timestamp, fuel_type.text, quantity.numeric, unit.text, cost_per_unit.numeric, total_cost.numeric, odometer_reading.integer, location_id.text )\nCREATE TABLE transportation.passengers (\n passenger_id character varying(64) NOT NULL, -- unique identifier for the passenger\n first_name character varying(128) NOT NULL, -- passenger's first name\n last_name character varying(128) NOT NULL, -- passenger's last name\n email character varying(128) UNIQUE, -- email address\n phone_number character varying(32) UNIQUE, -- phone number\n date_of_birth date, -- passenger's date of birth\n loyalty_program_id character varying(64), -- identifier for loyalty program membership\n created_at timestamp with time zone NOT NULL, -- time when the passenger record was created\n PRIMARY KEY (passenger_id)\n)\n","conversations":[{"role":"user","content":"List all trips that originated from locations in California, showing the trip ID, vehicle make and model, and origin location details."},{"role":"assistant","content":"SELECT t.trip_id, v.make, v.model, l.name AS origin_name, l.city AS origin_city FROM transportation.trips t JOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id JOIN transportation.locations l ON t.origin_location_id = l.location_id WHERE l.state_province = 'California'"},{"role":"user","content":"Can you also include the destination location city and filter to only show completed trips?"},{"role":"assistant","content":"SELECT t.trip_id, v.make, v.model, l.name AS origin_name, l.city AS origin_city, ld.city AS destination_city FROM transportation.trips t JOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id JOIN transportation.locations l ON t.origin_location_id = l.location_id JOIN transportation.locations ld ON t.destination_location_id = ld.location_id WHERE l.state_province = 'California' AND t.status = 'Completed'"},{"role":"user","content":"Now order these results by the origin city in ascending order and limit to 50 records."},{"role":"assistant","content":"SELECT t.trip_id, v.make, v.model, l.name AS origin_name, l.city AS origin_city, ld.city AS destination_city FROM transportation.trips t JOIN transportation.vehicles v ON t.vehicle_id = v.vehicle_id JOIN transportation.locations l ON t.origin_location_id = l.location_id JOIN transportation.locations ld ON t.destination_location_id = ld.location_id WHERE l.state_province = 'California' AND t.status = 'Completed' ORDER BY l.city ASC LIMIT 50"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.lawyers (\n lawyer_id character varying(64) NOT NULL, -- unique identifier for the lawyer\n first_name character varying(100) NOT NULL, -- lawyer's first name\n last_name character varying(100) NOT NULL, -- lawyer's last name\n bar_number character varying(64) UNIQUE NOT NULL, -- lawyer's bar association number\n firm_id character varying(64), -- FK to law_firms table\n email character varying(128) UNIQUE NOT NULL, -- lawyer's professional email\n phone character varying(32), -- lawyer's contact phone number\n specialization text, -- areas of legal expertise\n hire_date timestamp NOT NULL, -- date the lawyer was hired or joined\n is_partner boolean DEFAULT false, -- flag indicating if the lawyer is a partner\n PRIMARY KEY (lawyer_id)\n)\n","conversations":[{"role":"user","content":"List the first name, last name, and firm name for all lawyers who are partners."},{"role":"assistant","content":"SELECT T1.first_name , T1.last_name , T2.firm_name FROM legal_services.lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.is_partner = TRUE"},{"role":"user","content":"Only show partners from law firms founded before 2010."},{"role":"assistant","content":"SELECT T1.first_name , T1.last_name , T2.firm_name FROM legal_services.lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.is_partner = TRUE AND T2.founded_date < '2010-01-01'"},{"role":"user","content":"Sort the results by firm name and then by the lawyer's last name."},{"role":"assistant","content":"SELECT T1.first_name , T1.last_name , T2.firm_name FROM legal_services.lawyers AS T1 JOIN law_firms AS T2 ON T1.firm_id = T2.firm_id WHERE T1.is_partner = TRUE AND T2.founded_date < '2010-01-01' ORDER BY T2.firm_name , T1.last_name"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid, player_id uuid, game_id uuid, server_id uuid, start_time timestamp with time zone, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb )\nCREATE TABLE gaming_technology.servers ( server_id uuid, game_id uuid, server_name text, region text, ip_address text, port integer, current_players integer, max_players integer, status text, last_heartbeat timestamp with time zone )\nCREATE TABLE gaming_technology.achievements ( achievement_id uuid PRIMARY KEY, game_id uuid, name text, description text, icon_url text, points int, hidden boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, achievement_id uuid NOT NULL, unlocked_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (player_achievement_id), UNIQUE (player_id, achievement_id) )\nCREATE TABLE gaming_technology.in_game_items (\n item_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the item definition\n game_id uuid NOT NULL, -- FK linking to the game this item belongs to\n item_name character varying(150) NOT NULL, -- name of the item\n item_type character varying(50) NOT NULL, -- type (e.g., Cosmetic, Consumable, Weapon, Armor)\n description text, -- description of the item\n rarity character varying(30), -- item rarity (e.g., Common, Rare, Epic, Legendary)\n cost_currency character varying(10), -- currency code if purchasable (e.g., USD, EUR, GOLD)\n cost_amount numeric(12, 2), -- price if purchasable\n attributes jsonb, -- flexible field for item stats or properties\n PRIMARY KEY (item_id)\n -- FOREIGN KEY (game_id) REFERENCES gaming_technology.games(game_id)\n)\nCREATE TABLE gaming_technology.player_inventory ( inventory_id.uuid, player_id.uuid, item_id.uuid, quantity.integer, acquired_at.timestamptz, instance_data.jsonb )\n","conversations":[{"role":"user","content":"Show me the top 3 servers by the number of game sessions they've hosted, including server_name, region, and session_count."},{"role":"assistant","content":"SELECT\n s.server_name,\n s.region,\n COUNT(gs.session_id) AS session_count\nFROM gaming_technology.servers s\nLEFT JOIN gaming_technology.game_sessions gs\n ON s.server_id = gs.server_id\nGROUP BY s.server_name, s.region\nORDER BY session_count DESC\nLIMIT 3;"},{"role":"user","content":"Exclude servers that are currently 'offline'."},{"role":"assistant","content":"SELECT\n s.server_name,\n s.region,\n COUNT(gs.session_id) AS session_count\nFROM gaming_technology.servers s\nLEFT JOIN gaming_technology.game_sessions gs\n ON s.server_id = gs.server_id\nWHERE s.status <> 'offline'\nGROUP BY s.server_name, s.region\nORDER BY session_count DESC\nLIMIT 3;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid PRIMARY KEY, username text, email text, password_hash text, registration_date timestamptz, last_login timestamptz, country_code text, status text, profile_data jsonb )\nCREATE TABLE gaming_technology.developers (\n developer_id uuid NOT NULL DEFAULT gen_random_uuid(), -- unique identifier for the developer studio\n name character varying(150) NOT NULL UNIQUE, -- name of the development studio\n country character varying(100), -- country where the studio is based\n founded_year integer, -- year the studio was founded\n website character varying(255), -- developer's official website\n created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (developer_id)\n)\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id.uuid, player_id.uuid, achievement_id.uuid, unlocked_at.timestamptz )\n","conversations":[{"role":"user","content":"Which developers have at least one player who unlocked an achievement on a game they developed?"},{"role":"assistant","content":"SELECT DISTINCT d.developer_id, d.name\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.achievements a ON g.game_id = a.game_id\nJOIN gaming_technology.player_achievements pa ON a.achievement_id = pa.achievement_id;"},{"role":"user","content":"Now, can you also provide the total number of players who unlocked achievements per developer?"},{"role":"assistant","content":"SELECT d.developer_id, d.name, COUNT(DISTINCT pa.player_id) AS players_with_achievements\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.achievements a ON g.game_id = a.game_id\nJOIN gaming_technology.player_achievements pa ON a.achievement_id = pa.achievement_id\nGROUP BY d.developer_id, d.name;"},{"role":"user","content":"Only show developers who have at least 10 such players."},{"role":"assistant","content":"SELECT d.developer_id, d.name, COUNT(DISTINCT pa.player_id) AS players_with_achievements\nFROM gaming_technology.developers d\nJOIN gaming_technology.games g ON d.developer_id = g.developer_id\nJOIN gaming_technology.achievements a ON g.game_id = a.game_id\nJOIN gaming_technology.player_achievements pa ON a.achievement_id = pa.achievement_id\nGROUP BY d.developer_id, d.name\nHAVING COUNT(DISTINCT pa.player_id) >= 10;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.premium_payments ( payment_id text PRIMARY KEY, policy_id text, customer_id text, payment_date timestamp, amount_paid numeric, payment_method text, transaction_reference text, due_date date, payment_period_start date, payment_period_end date, status text )\n","conversations":[{"role":"user","content":"Show me all premium payments made via credit card in the last 30 days, along with their policy IDs and payment amounts."},{"role":"assistant","content":"SELECT payment_id, policy_id, amount_paid FROM insurance.premium_payments WHERE payment_method = 'credit_card' AND payment_date >= NOW() - INTERVAL '30 days';"},{"role":"user","content":"Now filter these payments to only show those with amounts greater than $500 and include the payment dates."},{"role":"assistant","content":"SELECT payment_id, policy_id, amount_paid, payment_date FROM insurance.premium_payments WHERE payment_method = 'credit_card' AND payment_date >= NOW() - INTERVAL '30 days' AND amount_paid > 500;"},{"role":"user","content":"I also want to see the count of such payments per policy ID."},{"role":"assistant","content":"SELECT policy_id, COUNT(*) as payment_count FROM insurance.premium_payments WHERE payment_method = 'credit_card' AND payment_date >= NOW() - INTERVAL '30 days' AND amount_paid > 500 GROUP BY policy_id;"},{"role":"user","content":"Finally, show me the average payment amount for these filtered payments."},{"role":"assistant","content":"SELECT AVG(amount_paid) as average_payment FROM insurance.premium_payments WHERE payment_method = 'credit_card' AND payment_date >= NOW() - INTERVAL '30 days' AND amount_paid > 500;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients ( client_id text PRIMARY KEY, first_name text, last_name text, company_name text, email text UNIQUE, phone text, address text, date_registered timestamp, status text )\nCREATE TABLE legal_services.invoices ( invoice_id text, invoice_number text, client_id text, case_id text, issue_date date, due_date date, total_amount numeric, amount_paid numeric, status text, payment_date timestamp, notes text, created_at timestamp )\n","conversations":[{"role":"user","content":"Give me a list of all unpaid invoices along with the first and last names of the clients and the issue date of each invoice."},{"role":"assistant","content":"SELECT i.invoice_number, i.issue_date, c.first_name, c.last_name\nFROM legal_services.invoices i\nJOIN legal_services.clients c ON i.client_id = c.client_id\nWHERE i.amount_paid < i.total_amount;"},{"role":"user","content":"Can you refine it to only include those invoices issued after March 1st, 2024?"},{"role":"assistant","content":"SELECT i.invoice_number, i.issue_date, c.first_name, c.last_name\nFROM legal_services.invoices i\nJOIN legal_services.clients c ON i.client_id = c.client_id\nWHERE i.amount_paid < i.total_amount AND i.issue_date > '2024-03-01';"},{"role":"user","content":"Add the client's status to the result and only show invoices for clients marked as 'prospect'."},{"role":"assistant","content":"SELECT i.invoice_number, i.issue_date, c.first_name, c.last_name, c.status\nFROM legal_services.invoices i\nJOIN legal_services.clients c ON i.client_id = c.client_id\nWHERE i.amount_paid < i.total_amount AND i.issue_date > '2024-03-01' AND c.status = 'prospect';"},{"role":"user","content":"Now, order the results by issue date in ascending order."},{"role":"assistant","content":"SELECT i.invoice_number, i.issue_date, c.first_name, c.last_name, c.status\nFROM legal_services.invoices i\nJOIN legal_services.clients c ON i.client_id = c.client_id\nWHERE i.amount_paid < i.total_amount AND i.issue_date > '2024-03-01' AND c.status = 'prospect'\nORDER BY i.issue_date ASC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE insurance.claim_documents ( document_id text, claim_id text, document_type text, file_name text, file_path text, file_size_bytes integer, mime_type text, uploaded_by text, uploaded_at timestamp, description text )\n","conversations":[{"role":"user","content":"Show me all medical report documents with their claim IDs and descriptions, sorted by upload date."},{"role":"assistant","content":"SELECT document_id, claim_id, description, uploaded_at FROM insurance.claim_documents WHERE document_type = 'medical_report' ORDER BY uploaded_at;"},{"role":"user","content":"Now filter to only show medical reports that have descriptions containing 'hospital' or 'clinic'."},{"role":"assistant","content":"SELECT document_id, claim_id, description, uploaded_at FROM insurance.claim_documents WHERE document_type = 'medical_report' AND (description LIKE '%hospital%' OR description LIKE '%clinic%') ORDER BY uploaded_at;"},{"role":"user","content":"I also want to see the count of these medical reports per claim."},{"role":"assistant","content":"SELECT claim_id, COUNT(*) AS medical_report_count FROM insurance.claim_documents WHERE document_type = 'medical_report' AND (description LIKE '%hospital%' OR description LIKE '%clinic%') GROUP BY claim_id;"},{"role":"user","content":"Finally, show me the average file size of these medical reports by claim, but only for claims with more than 2 medical reports."},{"role":"assistant","content":"SELECT claim_id, AVG(file_size_bytes) AS avg_file_size FROM insurance.claim_documents WHERE document_type = 'medical_report' AND (description LIKE '%hospital%' OR description LIKE '%clinic%') GROUP BY claim_id HAVING COUNT(*) > 2;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE government_services.citizens ( citizen_id character varying(64) NOT NULL, national_id_number character varying(128) NOT NULL UNIQUE, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, date_of_birth date NOT NULL, gender character varying(20), primary_address text NOT NULL, contact_email character varying(128) UNIQUE, contact_phone character varying(32), registration_date timestamp NOT NULL, is_verified boolean DEFAULT false, PRIMARY KEY (citizen_id) )\nCREATE TABLE government_services.agencies ( agency_id character varying(64) NOT NULL, agency_name character varying(255) NOT NULL, jurisdiction_level character varying(50) NOT NULL, primary_contact_email character varying(128), main_phone_number character varying(32), website_url character varying(255), established_date date, parent_agency_id character varying(64), PRIMARY KEY (agency_id) )\nCREATE TABLE government_services.services ( service_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, service_name character varying(255) NOT NULL, description text, category character varying(100), eligibility_criteria text, standard_fee numeric(10, 2) DEFAULT 0.00, average_processing_time_days integer, is_active boolean DEFAULT true, online_application_url character varying(255), PRIMARY KEY (service_id) )\nCREATE TABLE government_services.applications ( application_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, service_id character varying(64) NOT NULL, submitted_at timestamp NOT NULL, status character varying(50) NOT NULL, last_updated_at timestamp NOT NULL, assigned_employee_id character varying(64), decision_date date, notes text, reference_number character varying(100) UNIQUE, PRIMARY KEY (application_id) )\nCREATE TABLE government_services.payments ( payment_id character varying(64) NOT NULL, application_id character varying(64), citizen_id character varying(64) NOT NULL, service_id character varying(64), amount numeric(12, 2) NOT NULL, currency character varying(3) NOT NULL DEFAULT 'USD', payment_method character varying(50), payment_provider_reference character varying(128), payment_timestamp timestamp NOT NULL, status character varying(30) NOT NULL, notes text, PRIMARY KEY (payment_id) )\nCREATE TABLE government_services.employees ( employee_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, first_name character varying(100) NOT NULL, last_name character varying(100) NOT NULL, job_title character varying(150) NOT NULL, department character varying(100), work_email character varying(128) NOT NULL UNIQUE, work_phone character varying(32), hire_date date NOT NULL, termination_date date, access_level character varying(50), manager_employee_id character varying(64), PRIMARY KEY (employee_id) )\nCREATE TABLE government_services.service_locations ( location_id character varying(64) NOT NULL, agency_id character varying(64) NOT NULL, location_name character varying(200), address text NOT NULL, city character varying(100), state character varying(50), postal_code character varying(20), latitude numeric(9, 6), longitude numeric(9, 6), operating_hours text, contact_phone character varying(32), is_accessible boolean, PRIMARY KEY (location_id) )\nCREATE TABLE government_services.appointments ( appointment_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, employee_id character varying(64), location_id character varying(64), service_id character varying(64), scheduled_start_time timestamp NOT NULL, scheduled_end_time timestamp, purpose text NOT NULL, status character varying(30) NOT NULL, booking_method character varying(50), created_at timestamp NOT NULL, notes text, PRIMARY KEY (appointment_id) )\nCREATE TABLE government_services.notifications ( notification_id character varying(64) NOT NULL, citizen_id character varying(64) NOT NULL, application_id character varying(64), message_subject character varying(255), message_body text NOT NULL, channel character varying(30) NOT NULL, sent_at timestamp NOT NULL, status character varying(30) NOT NULL, related_entity_type character varying(50), related_entity_id character varying(64), PRIMARY KEY (notification_id) )\n","conversations":[{"role":"user","content":"List each employee's first and last name along with the count of active services offered by their agency."},{"role":"assistant","content":"SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name;"},{"role":"user","content":"Actually, only include employees whose service count is greater than 5."},{"role":"assistant","content":"SELECT e.first_name, e.last_name, COUNT(s.service_id) AS active_service_count\nFROM government_services.employees e\nJOIN government_services.services s ON e.agency_id = s.agency_id AND s.is_active = TRUE\nGROUP BY e.employee_id, e.first_name, e.last_name\nHAVING COUNT(s.service_id) > 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.maintenance_logs ( log_id character varying(64) NOT NULL, vehicle_id character varying(64) NOT NULL, service_date date NOT NULL, odometer_reading integer, service_type character varying(128) NOT NULL, description text NOT NULL, cost numeric(10, 2), mechanic_name character varying(128), next_service_due_date date, PRIMARY KEY (log_id) )\nCREATE TABLE transportation.bookings ( booking_id text, passenger_id text, trip_id text, seat_number text, booking_time timestamp, status text, fare numeric, payment_transaction_id text, special_requests text )\n","conversations":[{"role":"user","content":"For each trip, list the trip ID, its scheduled departure time, and the total fare from all bookings associated with that trip."},{"role":"assistant","content":"SELECT T2.trip_id , T2.scheduled_departure , SUM(T1.fare) FROM transportation.bookings AS T1 JOIN transportation.trips AS T2 ON T1.trip_id = T2.trip_id GROUP BY T2.trip_id , T2.scheduled_departure"},{"role":"user","content":"Now, only include trips where the total fare exceeds 500."},{"role":"assistant","content":"SELECT T2.trip_id , T2.scheduled_departure , SUM(T1.fare) FROM transportation.bookings AS T1 JOIN transportation.trips AS T2 ON T1.trip_id = T2.trip_id GROUP BY T2.trip_id , T2.scheduled_departure HAVING SUM(T1.fare) > 500"},{"role":"user","content":"Also, include the vehicle's make and model for these trips and order by total fare descending."},{"role":"assistant","content":"SELECT T2.trip_id , T2.scheduled_departure , SUM(T1.fare) , T3.make , T3.model FROM transportation.bookings AS T1 JOIN transportation.trips AS T2 ON T1.trip_id = T2.trip_id JOIN transportation.vehicles AS T3 ON T2.vehicle_id = T3.vehicle_id GROUP BY T2.trip_id , T2.scheduled_departure , T3.make , T3.model HAVING SUM(T1.fare) > 500 ORDER BY SUM(T1.fare) DESC"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.contracts (\n contract_id character varying(64) NOT NULL, -- unique identifier for the contract\n address character varying(128) NOT NULL, -- address of the deployed contract\n abi text NOT NULL, -- application binary interface of the contract\n bytecode text NOT NULL, -- bytecode of the contract\n deployer_address character varying(128) NOT NULL, -- address of the deployer\n deployed_at timestamp NOT NULL, -- time when the contract was deployed\n network_id character varying(64) NOT NULL, -- identifier of the network where the contract is deployed\n status character varying(32) NOT NULL, -- status of the contract (e.g., active, deprecated)\n PRIMARY KEY (contract_id)\n)\nCREATE TABLE web3.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128), -- address of the receiver (can be null for contract deployment)\n value numeric(38,14) NOT NULL, -- value transferred\n gas_used integer NOT NULL, -- amount of gas used by the transaction\n gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction\n block_number integer NOT NULL, -- block number containing the transaction\n timestamp timestamp NOT NULL, -- time when the transaction was mined\n input_data text, -- input data of the transaction (can be null)\n status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)\n nonce integer NOT NULL, -- nonce of the sender at the time of the transaction\n PRIMARY KEY (transaction_id)\n)\nCREATE TABLE web3.wallets (\n wallet_id character varying(64) NOT NULL, -- unique identifier for the wallet\n user_id character varying(64) NOT NULL, -- identifier of the user owning the wallet\n address character varying(128) NOT NULL, -- address of the wallet\n private_key text NOT NULL, -- private key of the wallet\n created_at timestamp NOT NULL, -- time when the wallet was created\n PRIMARY KEY (wallet_id)\n)\n","conversations":[{"role":"user","content":"List all transactions along with the user_id of the sender when the sender\u2019s address matches a wallet. Return transaction_id, from_address, and user_id."},{"role":"assistant","content":"SELECT t.transaction_id, t.from_address, w.user_id FROM web3.transactions t JOIN web3.wallets w ON t.from_address = w.address;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\nCREATE TABLE gaming_technology.developers ( developer_id.uuid, name.text, country.text, founded_year.integer, website.text, created_at.timestamptz )\n","conversations":[{"role":"user","content":"List all games released in 2023 along with their titles, platforms, and the names of their developers."},{"role":"assistant","content":"SELECT g.game_id, g.title, g.platform, d.name AS developer_name\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d\n ON g.developer_id = d.developer_id\nWHERE g.release_date >= '2023-01-01' AND g.release_date <= '2023-12-31';"},{"role":"user","content":"Also include the country of each developer in the output."},{"role":"assistant","content":"SELECT g.game_id, g.title, g.platform, d.name AS developer_name, d.country AS developer_country\nFROM gaming_technology.games g\nJOIN gaming_technology.developers d\n ON g.developer_id = d.developer_id\nWHERE g.release_date >= '2023-01-01' AND g.release_date <= '2023-12-31';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.players ( player_id uuid NOT NULL DEFAULT gen_random_uuid(), username character varying(100) NOT NULL UNIQUE, email character varying(255) NOT NULL UNIQUE, password_hash text NOT NULL, registration_date timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, last_login timestamp with time zone, country_code character(2), status character varying(20) NOT NULL DEFAULT 'active', profile_data jsonb, PRIMARY KEY (player_id) )\nCREATE TABLE gaming_technology.games ( game_id uuid PRIMARY KEY, title text, developer_id uuid, publisher_id uuid, genre text, release_date date, description text, platform text, engine text, website text )\nCREATE TABLE gaming_technology.game_sessions ( session_id uuid NOT NULL DEFAULT gen_random_uuid(), player_id uuid NOT NULL, game_id uuid NOT NULL, server_id uuid, start_time timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, end_time timestamp with time zone, duration_seconds integer, score integer, session_data jsonb, PRIMARY KEY (session_id) )\nCREATE TABLE gaming_technology.servers ( server_id uuid PRIMARY KEY, game_id uuid, server_name text, region text, ip_address text, port int, current_players int, max_players int, status text, last_heartbeat timestamptz )\nCREATE TABLE gaming_technology.achievements ( achievement_id.uuid, game_id.uuid, name.text, description.text, icon_url.text, points.integer, hidden.boolean )\nCREATE TABLE gaming_technology.player_achievements ( player_achievement_id uuid PRIMARY KEY, player_id uuid, achievement_id uuid, unlocked_at timestamptz )\nCREATE TABLE gaming_technology.in_game_items ( item_id uuid PRIMARY KEY, game_id uuid, item_name text, item_type text, description text, rarity text, cost_currency text, cost_amount numeric, attributes jsonb )\nCREATE TABLE gaming_technology.player_inventory ( inventory_id uuid PRIMARY KEY, player_id uuid, item_id uuid, quantity int, acquired_at timestamptz, instance_data jsonb )\n","conversations":[{"role":"user","content":"For each player, list their username together with the titles of games they have any items from in their inventory."},{"role":"assistant","content":"SELECT DISTINCT p.username, g.title\nFROM gaming_technology.players p\nJOIN gaming_technology.player_inventory pi ON p.player_id = pi.player_id\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id;"},{"role":"user","content":"Now restrict the list to only include items of rarity 'Epic'."},{"role":"assistant","content":"SELECT DISTINCT p.username, g.title\nFROM gaming_technology.players p\nJOIN gaming_technology.player_inventory pi ON p.player_id = pi.player_id\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE i.rarity = 'Epic';"},{"role":"user","content":"Also include the quantity of each epic item and sort the output by quantity in descending order."},{"role":"assistant","content":"SELECT p.username, g.title, i.item_name, pi.quantity\nFROM gaming_technology.players p\nJOIN gaming_technology.player_inventory pi ON p.player_id = pi.player_id\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE i.rarity = 'Epic'\nORDER BY pi.quantity DESC;"},{"role":"user","content":"Finally, filter out entries where the quantity is less than 2."},{"role":"assistant","content":"SELECT p.username, g.title, i.item_name, pi.quantity\nFROM gaming_technology.players p\nJOIN gaming_technology.player_inventory pi ON p.player_id = pi.player_id\nJOIN gaming_technology.in_game_items i ON pi.item_id = i.item_id\nJOIN gaming_technology.games g ON i.game_id = g.game_id\nWHERE i.rarity = 'Epic'\n AND pi.quantity >= 2\nORDER BY pi.quantity DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE token_basic_info ( coin_id character varying(100) NOT NULL, -- the id of the token token_name character varying(100) NOT NULL, -- the token's name token_symbol character varying(100) NOT NULL, -- the token's symbol token_address character varying(100) NOT NULL, -- the token's address chain text, -- the chain that the token resides price double precision, -- the current price of the token price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days highest_price_24h double precision, -- the highest price of the token in 24 hours lowest_price_24h double precision, -- the lowest price of the token in 24 hours market_cap double precision, -- the market cap of the token market_cap_rank bigint, -- the rank of the token market cap in desc market_cap_change_percentage_24h text, -- the percentage of market cap changes in 24 hours total_volume text, -- the trade volum of the token both in decentralized exchange(DEX) and centralized exchange(CEX) narrative text, -- the category or narrative of the token trend_rank biging, -- the trending rank of the token, value 1 expresses the most popular token. ,PRIMARY KEY (coin_id, chain) )\nCREATE TABLE narrative_info ( narrative character varying(512) NOT NULL, -- the id of narrative top_3_coins text, -- the top 3 tokens in the narrative price_change_percentage_1h double precision, -- change in value divided by the absolute price value of the original token price in 1 hour in the narrative price_change_percentage_24h double precision, -- change in value divided by the absolute price value of the original token price in 24 hours in the narrative price_change_percentage_7d double precision, -- change in value divided by the absolute price value of the original token price in 7 days in the narrative market_cap double precision, -- the market cap of the narrative volume_24h double precision, -- the trade volume of the narrative trend_rank bigint, -- the trending rank of the narrative, value 1 expresses the most popular narrative token_num bigint, -- total token number in the narrative ,PRIMARY KEY (narrative) )\nCREATE TABLE smart_money_profit ( address character varying(100) NOT NULL, -- the user's address rank INT, -- the rank of the address in trade performance, value 1 expresses the best address. profit numeric(38,6), -- the profit user made in a month roi numeric(38,2), -- the roi of the user in a month realized_ratio numeric(38,2), -- the percentage of the user's realized profit most_profit_token character varying(100), -- the token symbol of the user's most profitable trade last_trade_time character varying(100), -- the last trade time of the user chain character varying(100), -- the chain that the address resides PRIMARY KEY (address, chain) )\nCREATE TABLE smart_money_token_performance ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol pnl numeric(38,2), -- the profit users made on this token net_flow numeric(38,2), -- the netflow of the token, means the money user spent minus the the money user sold of this token avg_cost numeric(38,16), -- the average cost price of user spent on this token price double precision, -- the current price of the token realized_ratio numeric(10,2), -- the ratio user sold of the token roi numeric(10,2), -- the roi users made of this token chain character varying(100), -- the chain that the token resides PRIMARY KEY (token_address, chain) )\nCREATE TABLE smart_money_token_inflow ( token_address character varying(100) NOT NULL, -- the token's address token_symbol character varying(100), -- the tokens's symbol token_amount numeric(38,2), -- the absolute value of the amount if user bought minus the amount user sold of this token usd_value numeric(38,2), -- the absolute usd value of the bought token minus sold token avg_price numeric(38,6), -- the average cost price of user spent on this token type int, -- the direction of the trade on this token. 1 means buying, 2 means selling address_amount integer, -- the amount of the user bought this token narrative character varying(100), -- the category or narrative of the token chain character varying(100), -- the chain that the token resides ,PRIMARY KEY (token_address, chain) )\n","conversations":[{"role":"user","content":"For each narrative in smart_money_token_inflow, calculate the total usd_value and avg_price from buy transactions (type=1) and include the narrative's token count from narrative_info. Show narrative, chain, total_usd_value, avg_price, and token_num, ordered by total_usd_value descending, limit to 5."},{"role":"assistant","content":"SELECT i.narrative, i.chain, SUM(i.usd_value) AS total_usd_value, AVG(i.avg_price) AS avg_price, ni.token_num\nFROM smart_money_token_inflow AS i\nJOIN narrative_info AS ni ON i.narrative = ni.narrative\nWHERE i.type = 1\nGROUP BY i.narrative, i.chain, ni.token_num\nORDER BY total_usd_value DESC\nLIMIT 5;"},{"role":"user","content":"Please filter results to only include narratives where the total token_amount exceeds 1000."},{"role":"assistant","content":"SELECT i.narrative, i.chain, SUM(i.usd_value) AS total_usd_value, AVG(i.avg_price) AS avg_price, ni.token_num\nFROM smart_money_token_inflow AS i\nJOIN narrative_info AS ni ON i.narrative = ni.narrative\nWHERE i.type = 1\nGROUP BY i.narrative, i.chain, ni.token_num\nHAVING SUM(i.token_amount) > 1000\nORDER BY total_usd_value DESC\nLIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE blockchain.blocks ( block_id.text, previous_block_id.text, timestamp.timestamp, nonce.integer, merkle_root.text, difficulty.integer )\nCREATE TABLE blockchain.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n block_id character varying(64) NOT NULL, -- identifier of the block containing the transaction\n sender_address character varying(128) NOT NULL, -- address of the sender\n receiver_address character varying(128) NOT NULL, -- address of the receiver\n amount numeric(38,14) NOT NULL, -- amount transferred\n timestamp timestamp NOT NULL, -- time when the transaction was created\n signature text NOT NULL, -- digital signature of the transaction\n PRIMARY KEY (transaction_id)\n)\nCREATE TABLE blockchain.addresses ( address_id character varying(128) NOT NULL, public_key text NOT NULL, balance numeric(38,14) NOT NULL, PRIMARY KEY (address_id) )\nCREATE TABLE blockchain.wallets ( wallet_id.text, user_id.text, address_id.text, private_key.text )\nCREATE TABLE blockchain.users ( user_id character varying(64) NOT NULL, username character varying(128) NOT NULL, email character varying(128) NOT NULL, password_hash text NOT NULL, PRIMARY KEY (user_id) )\nCREATE TABLE blockchain.smart_contracts ( contract_id character varying(64) NOT NULL, creator_address character varying(128) NOT NULL, code text NOT NULL, timestamp timestamp NOT NULL, PRIMARY KEY (contract_id) )\n","conversations":[{"role":"user","content":"Retrieve the username and email for every user, along with the wallet ID and associated address ID for any wallets they own."},{"role":"assistant","content":"SELECT\n u.username,\n u.email,\n w.wallet_id,\n w.address_id\nFROM\n blockchain.users AS u\nLEFT JOIN\n blockchain.wallets AS w ON u.user_id = w.user_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE gaming_technology.games ( game_id.uuid, title.text, developer_id.uuid, publisher_id.uuid, genre.text, release_date.date, description.text, platform.text, engine.text, website.text )\n","conversations":[{"role":"user","content":"How many games are there per platform, and what is the earliest release_date for each platform?"},{"role":"assistant","content":"SELECT platform,\n COUNT(*) AS game_count,\n MIN(release_date) AS earliest_release\nFROM gaming_technology.games\nGROUP BY platform;"},{"role":"user","content":"Only include platforms with at least 10 games."},{"role":"assistant","content":"SELECT platform,\n COUNT(*) AS game_count,\n MIN(release_date) AS earliest_release\nFROM gaming_technology.games\nGROUP BY platform\nHAVING COUNT(*) >= 10;"},{"role":"user","content":"Sort the results by game_count descending."},{"role":"assistant","content":"SELECT platform,\n COUNT(*) AS game_count,\n MIN(release_date) AS earliest_release\nFROM gaming_technology.games\nGROUP BY platform\nHAVING COUNT(*) >= 10\nORDER BY game_count DESC;"},{"role":"user","content":"Also include the number of unique genres available on each platform."},{"role":"assistant","content":"SELECT platform,\n COUNT(*) AS game_count,\n MIN(release_date) AS earliest_release,\n COUNT(DISTINCT genre) AS genre_count\nFROM gaming_technology.games\nGROUP BY platform\nHAVING COUNT(*) >= 10\nORDER BY game_count DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.vehicles ( vehicle_id text PRIMARY KEY, license_plate text, vin text, make text, model text, year int, type text, capacity int, fuel_type text, status text, depot_id text, acquisition_date date )\n","conversations":[{"role":"user","content":"Find vehicles whose capacity is greater than the average capacity for their type. Show the vehicle_id, type, and capacity."},{"role":"assistant","content":"SELECT v.vehicle_id, v.type, v.capacity FROM transportation.vehicles v JOIN (SELECT type, AVG(capacity) AS avg_capacity FROM transportation.vehicles GROUP BY type) a ON v.type = a.type WHERE v.capacity > a.avg_capacity;"},{"role":"user","content":"Now restrict this to vehicles acquired after January 1, 2020."},{"role":"assistant","content":"SELECT v.vehicle_id, v.type, v.capacity FROM transportation.vehicles v JOIN (SELECT type, AVG(capacity) AS avg_capacity FROM transportation.vehicles GROUP BY type) a ON v.type = a.type WHERE v.capacity > a.avg_capacity AND v.acquisition_date > '2020-01-01';"},{"role":"user","content":"Also include each vehicle's make and model in the result."},{"role":"assistant","content":"SELECT v.vehicle_id, v.make, v.model, v.type, v.capacity FROM transportation.vehicles v JOIN (SELECT type, AVG(capacity) AS avg_capacity FROM transportation.vehicles GROUP BY type) a ON v.type = a.type WHERE v.capacity > a.avg_capacity AND v.acquisition_date > '2020-01-01';"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.transactions (\n transaction_id character varying(64) NOT NULL, -- unique identifier for the transaction\n from_address character varying(128) NOT NULL, -- address of the sender\n to_address character varying(128), -- address of the receiver (can be null for contract deployment)\n value numeric(38,14) NOT NULL, -- value transferred\n gas_used integer NOT NULL, -- amount of gas used by the transaction\n gas_price numeric(38,14) NOT NULL, -- price of gas at the time of the transaction\n block_number integer NOT NULL, -- block number containing the transaction\n timestamp timestamp NOT NULL, -- time when the transaction was mined\n input_data text, -- input data of the transaction (can be null)\n status character varying(32) NOT NULL, -- status of the transaction (e.g., success, failed)\n nonce integer NOT NULL, -- nonce of the sender at the time of the transaction\n PRIMARY KEY (transaction_id)\n)\n","conversations":[{"role":"user","content":"Find the top 5 transactions with the highest gas prices, including the from_address, to_address, and block_number, sorted by gas_price in descending order."},{"role":"assistant","content":"SELECT transaction_id, from_address, to_address, block_number, gas_price FROM web3.transactions ORDER BY gas_price DESC LIMIT 5;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE web3.tokens ( token_id text PRIMARY KEY, contract_address text, token_name text, token_symbol text, decimals int, total_supply numeric )\n","conversations":[{"role":"user","content":"List all tokens along with the contract addresses for symbols that appear more than once."},{"role":"assistant","content":"SELECT t.token_id, t.token_symbol, t.contract_address\nFROM web3.tokens t\nJOIN (\n SELECT token_symbol\n FROM web3.tokens\n GROUP BY token_symbol\n HAVING COUNT(*) > 1\n) dup ON t.token_symbol = dup.token_symbol;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE social_media.post_hashtags ( post_hashtag_id character varying(64) NOT NULL, post_id character varying(64) NOT NULL, hashtag_id character varying(64) NOT NULL, PRIMARY KEY (post_hashtag_id), CONSTRAINT unique_post_hashtag UNIQUE (post_id, hashtag_id) )\n","conversations":[{"role":"user","content":"List all distinct pairs of hashtag_id that are applied to the same post_id."},{"role":"assistant","content":"SELECT ph1.post_id, ph1.hashtag_id AS hashtag1_id, ph2.hashtag_id AS hashtag2_id\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id;"},{"role":"user","content":"I also want to see the total number of posts where each hashtag pair co-occurs."},{"role":"assistant","content":"SELECT ph1.hashtag_id AS hashtag1_id, ph2.hashtag_id AS hashtag2_id, COUNT(DISTINCT ph1.post_id) AS co_occurrence_count\nFROM social_media.post_hashtags ph1\nJOIN social_media.post_hashtags ph2\n ON ph1.post_id = ph2.post_id\n AND ph1.hashtag_id < ph2.hashtag_id\nGROUP BY ph1.hashtag_id, ph2.hashtag_id;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE legal_services.clients (\n client_id character varying(64) NOT NULL, -- unique identifier for the client\n first_name character varying(100) NOT NULL, -- client's first name\n last_name character varying(100) NOT NULL, -- client's last name\n company_name character varying(200), -- company name if applicable\n email character varying(128) UNIQUE NOT NULL, -- client's primary email\n phone character varying(32), -- client's contact phone number\n address text, -- client's full address\n date_registered timestamp NOT NULL, -- when the client was first registered\n status character varying(32) NOT NULL, -- client status (e.g., active, inactive, prospect)\n PRIMARY KEY (client_id)\n)\n","conversations":[{"role":"user","content":"List all pairs of clients who registered in the same month and year. Show both clients\u2019 first and last names, plus the month and year they share."},{"role":"assistant","content":"SELECT c1.first_name AS first_name_1,\n c1.last_name AS last_name_1,\n c2.first_name AS first_name_2,\n c2.last_name AS last_name_2,\n EXTRACT(YEAR FROM c1.date_registered) AS year,\n EXTRACT(MONTH FROM c1.date_registered) AS month\nFROM legal_services.clients c1\nJOIN legal_services.clients c2\n ON EXTRACT(YEAR FROM c1.date_registered) = EXTRACT(YEAR FROM c2.date_registered)\n AND EXTRACT(MONTH FROM c1.date_registered) = EXTRACT(MONTH FROM c2.date_registered)\n AND c1.client_id < c2.client_id;"},{"role":"user","content":"Actually, limit this to registrations that occurred in 2023 only."},{"role":"assistant","content":"SELECT c1.first_name AS first_name_1,\n c1.last_name AS last_name_1,\n c2.first_name AS first_name_2,\n c2.last_name AS last_name_2,\n EXTRACT(YEAR FROM c1.date_registered) AS year,\n EXTRACT(MONTH FROM c1.date_registered) AS month\nFROM legal_services.clients c1\nJOIN legal_services.clients c2\n ON EXTRACT(YEAR FROM c1.date_registered) = EXTRACT(YEAR FROM c2.date_registered)\n AND EXTRACT(MONTH FROM c1.date_registered) = EXTRACT(MONTH FROM c2.date_registered)\n AND c1.client_id < c2.client_id\nWHERE EXTRACT(YEAR FROM c1.date_registered) = 2023;"},{"role":"user","content":"Also, sort the results by month and then by the first client\u2019s last name."},{"role":"assistant","content":"SELECT c1.first_name AS first_name_1,\n c1.last_name AS last_name_1,\n c2.first_name AS first_name_2,\n c2.last_name AS last_name_2,\n EXTRACT(YEAR FROM c1.date_registered) AS year,\n EXTRACT(MONTH FROM c1.date_registered) AS month\nFROM legal_services.clients c1\nJOIN legal_services.clients c2\n ON EXTRACT(YEAR FROM c1.date_registered) = EXTRACT(YEAR FROM c2.date_registered)\n AND EXTRACT(MONTH FROM c1.date_registered) = EXTRACT(MONTH FROM c2.date_registered)\n AND c1.client_id < c2.client_id\nWHERE EXTRACT(YEAR FROM c1.date_registered) = 2023\nORDER BY month,\n c1.last_name;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE transportation.trips ( trip_id text PRIMARY KEY, route_id text, vehicle_id text, driver_id text, scheduled_departure timestamp, actual_departure timestamp, scheduled_arrival timestamp, actual_arrival timestamp, origin_location_id text, destination_location_id text, status text, passenger_count int, cargo_manifest_id text )\n","conversations":[{"role":"user","content":"Show me all trips that were completed with a passenger count greater than 15, including their route and vehicle details."},{"role":"assistant","content":"SELECT t.trip_id, t.route_id, t.vehicle_id, t.driver_id, t.scheduled_departure, t.actual_departure, t.scheduled_arrival, t.actual_arrival, t.origin_location_id, t.destination_location_id, t.passenger_count FROM transportation.trips t WHERE t.status = 'completed' AND t.passenger_count > 15;"},{"role":"user","content":"Can you also include the difference between scheduled and actual departure time in minutes for these trips, and order them by this difference in descending order?"},{"role":"assistant","content":"SELECT t.trip_id, t.route_id, t.vehicle_id, t.driver_id, t.scheduled_departure, t.actual_departure, EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 AS departure_delay_minutes, t.scheduled_arrival, t.actual_arrival, t.origin_location_id, t.destination_location_id, t.passenger_count FROM transportation.trips t WHERE t.status = 'completed' AND t.passenger_count > 15 ORDER BY departure_delay_minutes DESC;"},{"role":"user","content":"Now filter these results to only show trips where the departure delay was more than 30 minutes."},{"role":"assistant","content":"SELECT t.trip_id, t.route_id, t.vehicle_id, t.driver_id, t.scheduled_departure, t.actual_departure, EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 AS departure_delay_minutes, t.scheduled_arrival, t.actual_arrival, t.origin_location_id, t.destination_location_id, t.passenger_count FROM transportation.trips t WHERE t.status = 'completed' AND t.passenger_count > 15 AND EXTRACT(EPOCH FROM (t.actual_departure - t.scheduled_departure))\/60 > 30 ORDER BY departure_delay_minutes DESC;"}]} +{"system":"You are an SQL statement expert. Given the table structure described by the CREATE TABLE statement, write an SQL query that provides the solution to the user's question.\n##Table Structure\nCREATE TABLE hospitality_technology.services ( service_id character varying(64) NOT NULL, property_id character varying(64) NOT NULL, service_name character varying(150) NOT NULL, description text, category character varying(100), price numeric(10, 2) NOT NULL, unit character varying(30), is_available boolean NOT NULL DEFAULT true, department character varying(100), PRIMARY KEY (service_id), FOREIGN KEY (property_id) REFERENCES hospitality_technology.properties(property_id) )\n","conversations":[{"role":"user","content":"Show me each department in each property, along with the total number of available services and their combined price."},{"role":"assistant","content":"SELECT property_id, department, COUNT(*) AS service_count, SUM(price) AS total_price FROM hospitality_technology.services WHERE is_available = true GROUP BY property_id, department;"}]}